Skip to content

Commit 7466382

Browse files
committed
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`.
1 parent 6e6fc14 commit 7466382

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)