Skip to content

Commit 0b59160

Browse files
committed
Merge rust-bitcoin#2806: Make Address:p2sh_from_hash public
7466382 Make Address:p2sh_from_hash public (Tobin C. Harding) Pull request description: 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`. This is a backport of patch 1 from rust-bitcoin#2795, patch 2 is an update to api files which don't exist on the `\0.32.x` release branch. ACKs for top commit: apoelstra: ACK 7466382 Tree-SHA512: 880ae255c332920b320cd51a633f6260ee5e3121671e49c8ae9c0f10f7d53dfff472a3cb4aca76ae96d00b5ef409362c1233926264370a89816c48a83395fab0
2 parents 6e6fc14 + 7466382 commit 0b59160

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

bitcoin/src/address/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,13 @@ impl Address {
384384
Ok(Address::p2sh_from_hash(hash, network))
385385
}
386386

387-
// This is intentionally not public so we enforce script length checks.
388-
fn p2sh_from_hash(hash: ScriptHash, network: impl Into<NetworkKind>) -> Address {
387+
/// Creates a pay to script hash P2SH address from a script hash.
388+
///
389+
/// # Warning
390+
///
391+
/// The `hash` pre-image (redeem script) must not exceed 520 bytes in length
392+
/// otherwise outputs created from the returned address will be un-spendable.
393+
pub fn p2sh_from_hash(hash: ScriptHash, network: impl Into<NetworkKind>) -> Address {
389394
Self(AddressInner::P2sh { hash, network: network.into() }, PhantomData)
390395
}
391396

0 commit comments

Comments
 (0)