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>(
secp: &Secp256k1<C>,
internal_key: XOnlyPublicKey,
merkle_root: Option<TapBranchHash>,
) -> Scriptwhere
C: Verification,
pub fn new_v1_p2tr<C>(
secp: &Secp256k1<C>,
internal_key: XOnlyPublicKey,
merkle_root: Option<TapBranchHash>,
) -> Scriptwhere
C: Verification,
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>(
&self,
secp: &Secp256k1<C>,
internal_key: XOnlyPublicKey,
) -> Scriptwhere
C: Verification,
pub fn to_v1_p2tr<C>(
&self,
secp: &Secp256k1<C>,
internal_key: XOnlyPublicKey,
) -> Scriptwhere
C: Verification,
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 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>
Writes 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>
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
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