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`.
This commit is contained in:
Tobin C. Harding 2024-05-23 09:41:18 +10:00
parent d0c1eb138c
commit a3d2d1a184
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 7 additions and 2 deletions

View File

@ -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<NetworkKind>) -> 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<NetworkKind>) -> Address {
Self(AddressInner::P2sh { hash, network: network.into() }, PhantomData)
}