Skip to content

Commit 699f5b9

Browse files
committed
Merge rust-bitcoin#3655: Manually backport 3640
8d2267c backport: address: Add `Address::into_unchecked` (Tobin C. Harding) 499dd80 backport: address: Simplify `Address::assume_checked` impl (Tobin C. Harding) Pull request description: Manually backport the 2 patches from rust-bitcoin#3640. I did not investigate why the patches didn't apply cleanly I just grabed the changes from each patch. I did keep the patches separate and retained the commit logs. Holla if there is a better way to do this since we are backporting often these days. ACKs for top commit: MaxFangX: ACK [`8d2267c`](rust-bitcoin@8d2267c), confirmed use of `Address::into_unchecked` compiles and passes tests downstream with patch apoelstra: ACK 8d2267c; successfully ran local tests Tree-SHA512: 92ae39092d9ced3d1597305328589dbeecd7659b445302b442a715c9af82d5d664c7d75ddd95ab4b39b0908df5c1ea54455f9675d72f33f884bbd8208aa32dbb
2 parents 1a3cb16 + 8d2267c commit 699f5b9

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

bitcoin/src/address/mod.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ impl<V: NetworkValidation> Address<V> {
382382
pub fn as_unchecked(&self) -> &Address<NetworkUnchecked> {
383383
unsafe { &*(self as *const Address<V> as *const Address<NetworkUnchecked>) }
384384
}
385+
386+
/// Marks the network of this address as unchecked.
387+
pub fn into_unchecked(self) -> Address<NetworkUnchecked> { Address(self.0, PhantomData) }
385388
}
386389

387390
/// Methods and functions that can be called only on `Address<NetworkChecked>`.
@@ -773,16 +776,7 @@ impl Address<NetworkUnchecked> {
773776
/// For details about this mechanism, see section [*Parsing addresses*](Address#parsing-addresses)
774777
/// on [`Address`].
775778
#[inline]
776-
pub fn assume_checked(self) -> Address {
777-
use AddressInner::*;
778-
779-
let inner = match self.0 {
780-
P2pkh { hash, network } => P2pkh { hash, network },
781-
P2sh { hash, network } => P2sh { hash, network },
782-
Segwit { program, hrp } => Segwit { program, hrp },
783-
};
784-
Address(inner, PhantomData)
785-
}
779+
pub fn assume_checked(self) -> Address { Address(self.0, PhantomData) }
786780
}
787781

788782
impl From<Address> for script::ScriptBuf {

0 commit comments

Comments
 (0)