pub struct Script(/* private fields */);
Expand description
A Bitcoin script
Implementations§
source§impl Script
impl Script
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_v1_p2tr<C: Verification>(
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey,
merkle_root: Option<TapNodeHash>
) -> Script
pub fn new_v1_p2tr<C: Verification>( secp: &Secp256k1<C>, internal_key: UntweakedPublicKey, merkle_root: Option<TapNodeHash> ) -> Script
Generates P2TR for script spending path using an internal public key and some optional script tree merkle root.
sourcepub fn new_v1_p2tr_tweaked(output_key: TweakedPublicKey) -> Script
pub fn new_v1_p2tr_tweaked(output_key: TweakedPublicKey) -> Script
Generates P2TR for key spending path for a known TweakedPublicKey
.
sourcepub fn new_witness_program(ver: Fe32, program: &[u8]) -> Script
pub fn new_witness_program(ver: Fe32, 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_v1_p2tr(&self) -> bool
pub fn is_v1_p2tr(&self) -> bool
Checks whether a script pubkey is a P2TR output.
sourcepub fn is_v1plus_p2witprog(&self) -> bool
pub fn is_v1plus_p2witprog(&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 In elements, is_provably_unspendable is consensus critical matches the implementation of CScript::IsUnspendable()
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 Script::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.
Trait Implementations§
source§impl Deserialize for Script
impl Deserialize for Script
source§impl Ord for Script
impl Ord for Script
source§impl PartialEq for Script
impl PartialEq for Script
source§impl PartialOrd for Script
impl PartialOrd for Script
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more