pub struct Script(_);
Expand description
A Bitcoin script.
Implementations
sourceimpl 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
use Script::new_v0_p2wpkh method instead
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
use Script::new_v0_p2wsh method instead
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 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 as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Returns the script data
sourcepub fn to_bytes(&self) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn to_bytes(&self) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Returns a copy of the script data
sourcepub fn into_bytes(self) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn into_bytes(self) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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 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
Compute 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 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
Whether a script can be proven to have no satisfying input
sourcepub fn dust_value(&self) -> Amount
pub fn dust_value(&self) -> Amount
Gets 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<'_>ⓘNotable traits for Instructions<'a>impl<'a> Iterator for Instructions<'a> type Item = Result<Instruction<'a>, Error>;
pub fn instructions(&self) -> Instructions<'_>ⓘNotable traits for Instructions<'a>impl<'a> Iterator for Instructions<'a> type Item = Result<Instruction<'a>, Error>;
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 Self::instructions_minimal.
sourcepub fn instructions_minimal(&self) -> Instructions<'_>ⓘNotable traits for Instructions<'a>impl<'a> Iterator for Instructions<'a> type Item = Result<Instruction<'a>, Error>;
pub fn instructions_minimal(&self) -> Instructions<'_>ⓘNotable traits for Instructions<'a>impl<'a> Iterator for Instructions<'a> type Item = Result<Instruction<'a>, Error>;
Iterate 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>
This is supported 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>
This is supported 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.Verify spend of an input script
Parameters
index
- the input index in spending which is spending this transactionamount
- the amount this script guardsspending
- the transaction that attempts to spend the output holding this scriptflags
- verification flags, see bitcoinconsensus::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
Write 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
Write the assembly decoding of the script to the formatter.
Trait Implementations
sourceimpl Decodable for Script
impl Decodable for Script
sourcefn consensus_decode<D: Read>(d: D) -> Result<Self, Error>
fn consensus_decode<D: Read>(d: D) -> Result<Self, Error>
Decode an object with a well-defined format
sourceimpl Deserialize for Script
impl Deserialize for Script
sourceimpl<'de> Deserialize<'de> for Script
This is supported on crate feature serde
only.
impl<'de> Deserialize<'de> for Script
serde
only.sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl FromHex for Script
impl FromHex for Script
sourcefn from_byte_iter<I>(iter: I) -> Result<Self, Error> where
I: Iterator<Item = Result<u8, Error>> + ExactSizeIterator + DoubleEndedIterator,
fn from_byte_iter<I>(iter: I) -> Result<Self, Error> where
I: Iterator<Item = Result<u8, Error>> + ExactSizeIterator + DoubleEndedIterator,
Produce an object from a byte iterator
sourceimpl Ord for Script
impl Ord for Script
sourceimpl PartialOrd<Script> for Script
impl PartialOrd<Script> for Script
sourcefn partial_cmp(&self, other: &Script) -> Option<Ordering>
fn partial_cmp(&self, other: &Script) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for Script
impl StructuralEq for Script
impl StructuralPartialEq for Script
Auto Trait Implementations
impl RefUnwindSafe for Script
impl Send for Script
impl Sync for Script
impl Unpin for Script
impl UnwindSafe for Script
Blanket Implementations
sourceimpl<T> Base32Len for T where
T: AsRef<[u8]>,
impl<T> Base32Len for T where
T: AsRef<[u8]>,
sourcepub fn base32_len(&self) -> usize
pub fn base32_len(&self) -> usize
Calculate the base32 serialized length
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToBase32 for T where
T: AsRef<[u8]>,
impl<T> ToBase32 for T where
T: AsRef<[u8]>,
sourcepub fn write_base32<W>(
&self,
writer: &mut W
) -> Result<(), <W as WriteBase32>::Err> where
W: WriteBase32,
pub fn write_base32<W>(
&self,
writer: &mut W
) -> Result<(), <W as WriteBase32>::Err> where
W: WriteBase32,
Encode as base32 and write it to the supplied writer Implementations shouldn’t allocate. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more