From a3d2d1a184586eeb5a85efd2eace15ca9f388c7e Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 23 May 2024 09:41:18 +1000 Subject: [PATCH] Make Address:p2sh_from_hash public We previously made this function Private and added a comment that doing so was somehow better to remove the footgun of hashing the wrong length script. However in hindsight this was a bad idea and users want the functionality. Make the `Address:p2sh_from_hash` public and document it as we do for `Address::p2sh`. --- bitcoin/src/address/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bitcoin/src/address/mod.rs b/bitcoin/src/address/mod.rs index 89658144b..3883378fb 100644 --- a/bitcoin/src/address/mod.rs +++ b/bitcoin/src/address/mod.rs @@ -384,8 +384,13 @@ impl Address { Ok(Address::p2sh_from_hash(hash, network)) } - // This is intentionally not public so we enforce script length checks. - fn p2sh_from_hash(hash: ScriptHash, network: impl Into) -> Address { + /// Creates a pay to script hash P2SH address from a script hash. + /// + /// # Warning + /// + /// The `hash` pre-image (redeem script) must not exceed 520 bytes in length + /// otherwise outputs created from the returned address will be un-spendable. + pub fn p2sh_from_hash(hash: ScriptHash, network: impl Into) -> Address { Self(AddressInner::P2sh { hash, network: network.into() }, PhantomData) }