pub struct Script(/* private fields */);Expand description
A Bitcoin script, represented as a byte vector newtype.
Implementations§
Source§impl Script
impl Script
Sourcepub fn from_hex(hex_str: &str) -> Result<Self, ScriptError>
pub fn from_hex(hex_str: &str) -> Result<Self, ScriptError>
Sourcepub fn from_bytes(bytes: &[u8]) -> Self
pub fn from_bytes(bytes: &[u8]) -> Self
Sourcepub fn from_asm(asm: &str) -> Result<Self, ScriptError>
pub fn from_asm(asm: &str) -> Result<Self, ScriptError>
Sourcepub fn to_asm(&self) -> String
pub fn to_asm(&self) -> String
Convert the script to its ASM (human-readable assembly) representation.
Each opcode or data push is represented as a space-separated token. Data pushes appear as their hex encoding; opcodes appear by name.
§Returns
A space-separated ASM string. Returns empty string for empty/invalid scripts.
Sourcepub fn is_p2pkh(&self) -> bool
pub fn is_p2pkh(&self) -> bool
Check if this is a Pay-to-Public-Key-Hash (P2PKH) output script.
Pattern: OP_DUP OP_HASH160 <20 bytes> OP_EQUALVERIFY OP_CHECKSIG
§Returns
true if the script matches the P2PKH pattern.
Sourcepub fn is_p2pk(&self) -> bool
pub fn is_p2pk(&self) -> bool
Check if this is a Pay-to-Public-Key (P2PK) output script.
Pattern: <pubkey> OP_CHECKSIG (pubkey is 33 or 65 bytes with valid prefix).
§Returns
true if the script matches the P2PK pattern.
Sourcepub fn is_p2sh(&self) -> bool
pub fn is_p2sh(&self) -> bool
Check if this is a Pay-to-Script-Hash (P2SH) output script.
Pattern: OP_HASH160 <20 bytes> OP_EQUAL
§Returns
true if the script matches the P2SH pattern.
Sourcepub fn is_data(&self) -> bool
pub fn is_data(&self) -> bool
Check if this is a data output script (OP_RETURN or OP_FALSE OP_RETURN).
§Returns
true if the script begins with OP_RETURN or OP_FALSE OP_RETURN.
Sourcepub fn is_multisig_out(&self) -> bool
pub fn is_multisig_out(&self) -> bool
Check if this is a multisig output script.
Pattern: OP_N <pubkey1> <pubkey2> ... OP_M OP_CHECKMULTISIG
§Returns
true if the script matches the multisig output pattern.
Sourcepub fn public_key_hash(&self) -> Result<Vec<u8>, ScriptError>
pub fn public_key_hash(&self) -> Result<Vec<u8>, ScriptError>
Extract the public key hash from a P2PKH script.
Returns the 20-byte hash160 if the script starts with OP_DUP OP_HASH160.
§Returns
The 20-byte public key hash, or an error if the script is not P2PKH.
Sourcepub fn chunks(&self) -> Result<Vec<ScriptChunk>, ScriptError>
pub fn chunks(&self) -> Result<Vec<ScriptChunk>, ScriptError>
Parse the script into a vector of decoded chunks.
§Returns
A vector of ScriptChunk values, or an error if the script is malformed.