pub struct ScriptHash(/* private fields */);Expand description
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.
Implementations§
Source§impl ScriptHash
impl ScriptHash
Sourcepub fn from_script<T>(
redeem_script: &Script<T>,
) -> Result<Self, RedeemScriptSizeError>where
T: ScriptHashableTag,
pub fn from_script<T>(
redeem_script: &Script<T>,
) -> Result<Self, RedeemScriptSizeError>where
T: ScriptHashableTag,
Constructs a new ScriptHash after first checking the script size.
§520-byte limitation on serialized script size
As a consequence of the requirement for backwards compatibility the serialized script is itself subject to the same rules as any other PUSHDATA operation, including the rule that no data greater than 520 bytes may be pushed to the stack. Thus it is not possible to spend a P2SH output if the redemption script it refers to is >520 bytes in length.
ref: BIP-0016
§Errors
Returns an error if the script exceeds 520 bytes.
Sourcepub fn from_script_unchecked<T>(script: &Script<T>) -> Self
pub fn from_script_unchecked<T>(script: &Script<T>) -> Self
Constructs a new ScriptHash from any script irrespective of script size.
If you hash a script that exceeds 520 bytes in size and use it to create a P2SH output then the output will be unspendable (see BIP-0016).
§impl ScriptHash
impl ScriptHash
pub const fn from_byte_array(bytes: [u8; 20]) -> Self
pub const fn from_byte_array(bytes: [u8; 20]) -> Self
Constructs a new type from the underlying byte array.
pub const fn to_byte_array(self) -> [u8; 20]
pub const fn to_byte_array(self) -> [u8; 20]
Returns the underlying byte array.
pub const fn as_byte_array(&self) -> &[u8; 20]
pub const fn as_byte_array(&self) -> &[u8; 20]
Returns a reference to the underlying byte array.
Trait Implementations§
§impl<'a> Arbitrary<'a> for ScriptHash
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for ScriptHash
arbitrary only.§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl AsRef<PushBytes> for ScriptHash
impl AsRef<PushBytes> for ScriptHash
§impl AsRef<[u8; 20]> for ScriptHash
impl AsRef<[u8; 20]> for ScriptHash
§impl AsRef<[u8]> for ScriptHash
impl AsRef<[u8]> for ScriptHash
§impl Borrow<[u8; 20]> for ScriptHash
impl Borrow<[u8; 20]> for ScriptHash
§impl Borrow<[u8]> for ScriptHash
impl Borrow<[u8]> for ScriptHash
Source§impl Clone for ScriptHash
impl Clone for ScriptHash
Source§fn clone(&self) -> ScriptHash
fn clone(&self) -> ScriptHash
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ScriptHash
Source§impl Debug for ScriptHash
impl Debug for ScriptHash
§impl<'de> Deserialize<'de> for ScriptHash
impl<'de> Deserialize<'de> for ScriptHash
§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<ScriptHash, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<ScriptHash, D::Error>
§impl Display for ScriptHash
Available on crate feature hex only.
impl Display for ScriptHash
hex only.impl Eq for ScriptHash
Source§impl From<ScriptHash> for PushBytesBuf
impl From<ScriptHash> for PushBytesBuf
Source§fn from(hash: ScriptHash) -> Self
fn from(hash: ScriptHash) -> Self
§impl FromStr for ScriptHash
Available on crate feature hex only.
impl FromStr for ScriptHash
hex only.Source§impl Hash for ScriptHash
impl Hash for ScriptHash
§impl LowerHex for ScriptHash
Available on crate feature hex only.
impl LowerHex for ScriptHash
hex only.