pub struct Script(/* private fields */);
Expand description
A Bitcoin script
Implementations§
Source§impl Script
impl Script
Sourcepub fn new_p2pk(secp: &Secp256k1, pubkey: &PublicKey) -> Script
pub fn new_p2pk(secp: &Secp256k1, pubkey: &PublicKey) -> Script
Generates P2PK-type of scriptPubkey
Sourcepub fn new_p2pkh(pubkey_hash: &PubkeyHash) -> Script
pub fn new_p2pkh(pubkey_hash: &PubkeyHash) -> Script
Generates P2PKH-type of scriptPubkey
Sourcepub fn new_p2sh(script_hash: &ScriptHash) -> Script
pub fn new_p2sh(script_hash: &ScriptHash) -> Script
Generates P2SH-type of scriptPubkey with a given hash of the redeem script
Sourcepub fn new_v0_wpkh(pubkey_hash: &WPubkeyHash) -> Script
pub fn new_v0_wpkh(pubkey_hash: &WPubkeyHash) -> Script
Generates P2WPKH-type of scriptPubkey
Sourcepub fn new_v0_wsh(script_hash: &WScriptHash) -> Script
pub fn new_v0_wsh(script_hash: &WScriptHash) -> Script
Generates P2WSH-type of scriptPubkey with a given hash of the redeem script
Sourcepub fn new_witness_program(ver: u5, program: &[u8]) -> Script
pub fn new_witness_program(ver: u5, program: &[u8]) -> Script
Generates P2WSH-type of scriptPubkey with a given hash of the redeem script
Sourcepub fn new_op_return(data: &[u8]) -> Script
pub fn new_op_return(data: &[u8]) -> Script
Generates OP_RETURN-type of scriptPubkey for a given data
Sourcepub fn script_hash(&self) -> ScriptHash
pub fn script_hash(&self) -> ScriptHash
Returns 160-bit hash of the script
Sourcepub fn wscript_hash(&self) -> WScriptHash
pub fn wscript_hash(&self) -> WScriptHash
Returns 256-bit hash of the script for P2WSH outputs
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Convert the script into a byte vector
Sourcepub fn to_v0_p2wsh(&self) -> Script
pub fn to_v0_p2wsh(&self) -> Script
Compute the P2WSH output corresponding to this witnessScript (aka the “witness redeem script”)
Sourcepub fn is_witness_program(&self) -> bool
pub fn is_witness_program(&self) -> bool
Checks whether a script pubkey is a Segregated Witness (segwit) program.
Sourcepub fn is_v0_p2wsh(&self) -> bool
pub fn is_v0_p2wsh(&self) -> bool
Checks whether a script pubkey is a p2wsh output
Sourcepub fn is_v0_p2wpkh(&self) -> bool
pub fn is_v0_p2wpkh(&self) -> bool
Checks whether a script pubkey is a p2wpkh output
Sourcepub fn is_op_return(&self) -> bool
pub fn is_op_return(&self) -> bool
Check if this is an OP_RETURN output
Sourcepub fn is_provably_unspendable(&self) -> bool
pub fn is_provably_unspendable(&self) -> bool
Whether a script can be proven to have no satisfying input
Sourcepub fn instructions(&self) -> Instructions<'_> ⓘ
pub fn instructions(&self) -> Instructions<'_> ⓘ
Iterate over the script in the form of Instruction
s, which are an enum covering
opcodes, datapushes and errors. At most one error will be returned and then the
iterator will end. To instead iterate over the script as sequence of bytes, treat
it as a slice using script[..]
or convert it to a vector using into_bytes()
.
To force minimal pushes, use [instructions_minimal].
Sourcepub fn instructions_minimal(&self) -> Instructions<'_> ⓘ
pub fn instructions_minimal(&self) -> Instructions<'_> ⓘ
Iterate over the script in the form of Instruction
s while enforcing
minimal pushes.