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
👎Deprecated since 0.28.0: use Script::new_v0_p2wpkh method instead
pub fn new_v0_wpkh(pubkey_hash: &WPubkeyHash) -> Script
Generates P2WPKH-type of scriptPubkey.
Sourcepub fn new_v0_p2wpkh(pubkey_hash: &WPubkeyHash) -> Script
pub fn new_v0_p2wpkh(pubkey_hash: &WPubkeyHash) -> Script
Generates P2WPKH-type of scriptPubkey.
Sourcepub fn new_v0_wsh(script_hash: &WScriptHash) -> Script
👎Deprecated since 0.28.0: use Script::new_v0_p2wsh method instead
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_v0_p2wsh(script_hash: &WScriptHash) -> Script
pub fn new_v0_p2wsh(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<TapBranchHash>,
) -> Script
pub fn new_v1_p2tr<C: Verification>( secp: &Secp256k1<C>, internal_key: UntweakedPublicKey, merkle_root: Option<TapBranchHash>, ) -> 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(version: WitnessVersion, program: &[u8]) -> Script
pub fn new_witness_program(version: WitnessVersion, 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 the 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> ⓘ
Converts the script into a byte vector.
Sourcepub fn to_v0_p2wsh(&self) -> Script
pub fn to_v0_p2wsh(&self) -> Script
Computes the P2WSH output corresponding to this witnessScript (aka the “witness redeem script”).
Sourcepub fn to_v1_p2tr<C: Verification>(
&self,
secp: &Secp256k1<C>,
internal_key: UntweakedPublicKey,
) -> Script
pub fn to_v1_p2tr<C: Verification>( &self, secp: &Secp256k1<C>, internal_key: UntweakedPublicKey, ) -> Script
Computes P2TR output with a given internal key and a single script spending path equal to the current script, assuming that the script is a Tapscript.
Sourcepub fn witness_version(&self) -> Option<WitnessVersion>
pub fn witness_version(&self) -> Option<WitnessVersion>
Returns witness version of the script, if any, assuming the script is a scriptPubkey
.
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_v1_p2tr(&self) -> bool
pub fn is_v1_p2tr(&self) -> bool
Checks whether a script pubkey is a P2TR 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
Checks whether a script can be proven to have no satisfying input.
Sourcepub fn dust_value(&self) -> Amount
pub fn dust_value(&self) -> Amount
Returns the minimum value an output with this script should have in order to be broadcastable on today’s Bitcoin network.
Sourcepub fn instructions(&self) -> Instructions<'_> ⓘ
pub fn instructions(&self) -> Instructions<'_> ⓘ
Iterates 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 Self::instructions_minimal
.
Sourcepub fn instructions_minimal(&self) -> Instructions<'_> ⓘ
pub fn instructions_minimal(&self) -> Instructions<'_> ⓘ
Iterates over the script in the form of Instruction
s while enforcing minimal pushes.
Sourcepub fn verify(
&self,
index: usize,
amount: Amount,
spending: &[u8],
) -> Result<(), Error>
Available on crate feature bitcoinconsensus
only.
pub fn verify( &self, index: usize, amount: Amount, spending: &[u8], ) -> Result<(), Error>
bitcoinconsensus
only.Shorthand for Self::verify_with_flags
with flag bitcoinconsensus::VERIFY_ALL.
Sourcepub fn verify_with_flags<F: Into<u32>>(
&self,
index: usize,
amount: Amount,
spending: &[u8],
flags: F,
) -> Result<(), Error>
Available on crate feature bitcoinconsensus
only.
pub fn verify_with_flags<F: Into<u32>>( &self, index: usize, amount: Amount, spending: &[u8], flags: F, ) -> Result<(), Error>
bitcoinconsensus
only.Verifies spend of an input script.
§Parameters
index
- The input index in spending which is spending this transaction.amount
- The amount this script guards.spending
- The transaction that attempts to spend the output holding this script.flags
- Verification flags, seebitcoinconsensus::VERIFY_ALL
and similar.
Sourcepub fn bytes_to_asm_fmt(script: &[u8], f: &mut dyn Write) -> Result
pub fn bytes_to_asm_fmt(script: &[u8], f: &mut dyn Write) -> Result
Writes the assembly decoding of the script bytes to the formatter.
Sourcepub fn fmt_asm(&self, f: &mut dyn Write) -> Result
pub fn fmt_asm(&self, f: &mut dyn Write) -> Result
Writes the assembly decoding of the script to the formatter.
Sourcepub fn bytes_to_asm(script: &[u8]) -> String
pub fn bytes_to_asm(script: &[u8]) -> String
Creates an assembly decoding of the script in the given byte slice.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Script
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for Script
serde
only.