diff --git a/bitcoin/src/address/mod.rs b/bitcoin/src/address/mod.rs index c7053f667..1169e631a 100644 --- a/bitcoin/src/address/mod.rs +++ b/bitcoin/src/address/mod.rs @@ -383,6 +383,9 @@ impl Address { pub fn as_unchecked(&self) -> &Address { unsafe { &*(self as *const Address as *const Address) } } + + /// Marks the network of this address as unchecked. + pub fn into_unchecked(self) -> Address { Address(self.0, PhantomData) } } /// Methods and functions that can be called only on `Address`. @@ -792,16 +795,7 @@ impl Address { /// For details about this mechanism, see section [*Parsing addresses*](Address#parsing-addresses) /// on [`Address`]. #[inline] - pub fn assume_checked(self) -> Address { - use AddressInner::*; - - let inner = match self.0 { - P2pkh { hash, network } => P2pkh { hash, network }, - P2sh { hash, network } => P2sh { hash, network }, - Segwit { program, hrp } => Segwit { program, hrp }, - }; - Address(inner, PhantomData) - } + pub fn assume_checked(self) -> Address { Address(self.0, PhantomData) } /// Parse a bech32 Address string pub fn from_bech32_str(s: &str) -> Result, Bech32Error> {