Add a note about Electrum's script hashes

The Electrum protocol uses hashes of `script_pubkey` that might look
similar to the ones we have in the crate and could be confused. This
change notes that to hopefully avoid the confusion.

Resolves https://github.com/rust-bitcoin/rust-bitcoin/discussions/3997
This commit is contained in:
Martin Habovstiak 2025-02-20 17:59:12 +01:00
parent 82f553aada
commit 9ec9adc71d
1 changed files with 11 additions and 2 deletions

View File

@ -33,9 +33,18 @@ pub const MAX_REDEEM_SCRIPT_SIZE: usize = 520;
pub const MAX_WITNESS_SCRIPT_SIZE: usize = 10_000;
hashes::hash_newtype! {
/// A hash of Bitcoin Script bytecode.
/// A 160-bit hash of Bitcoin Script bytecode.
///
/// Note: there is another "script hash" object in bitcoin ecosystem (Electrum protocol) that
/// uses 256-bit hash and hashes a semantically different script. Thus, this type cannot
/// represent it.
pub struct ScriptHash(hash160::Hash);
/// SegWit version of a Bitcoin Script bytecode hash.
/// SegWit (256-bit) version of a Bitcoin Script bytecode hash.
///
/// Note: there is another "script hash" object in bitcoin ecosystem (Electrum protocol) that
/// looks similar to this one also being SHA256, however, they hash semantically different
/// scripts and have reversed representations, so this type cannot be used for both.
pub struct WScriptHash(sha256::Hash);
}