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_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 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<'_>
pub fn instructions(&self) -> Instructions<'_>
Iterate over the script in the form of Instructions, 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<'_>
Iterate over the script in the form of Instructions while enforcing
minimal pushes.
Sourcepub fn bytes_to_asm_fmt(script: &[u8], f: &mut dyn Write) -> Result<(), Error>
pub fn bytes_to_asm_fmt(script: &[u8], f: &mut dyn Write) -> Result<(), Error>
Write the assembly decoding of the script bytes to the formatter.
Sourcepub fn fmt_asm(&self, f: &mut dyn Write) -> Result<(), Error>
pub fn fmt_asm(&self, f: &mut dyn Write) -> Result<(), Error>
Write 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
Create an assembly decoding of the script in the given byte slice.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Script
impl<'de> Deserialize<'de> for Script
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Script, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Script, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Deserialize for Script
impl Deserialize for Script
Source§impl Ord for Script
impl Ord for Script
Source§impl PartialOrd for Script
impl PartialOrd for Script
Source§impl Serialize for Script
impl Serialize for Script
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
User-facing serialization for Script.
impl Eq for Script
impl StructuralPartialEq for Script
Auto Trait Implementations§
impl Freeze for Script
impl RefUnwindSafe for Script
impl Send for Script
impl Sync for Script
impl Unpin for Script
impl UnwindSafe for Script
Blanket Implementations§
Source§impl<T> Base32Len for T
impl<T> Base32Len for T
Source§fn base32_len(&self) -> usize
fn base32_len(&self) -> usize
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<'f, T> CheckBase32<Vec<u5>> for T
impl<'f, T> CheckBase32<Vec<u5>> for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more