Struct Script
pub struct Script(/* private fields */);
Expand description
Bitcoin script.
A list of instructions in a simple, Forth-like, stack-based programming language that Bitcoin uses.
See Bitcoin Wiki: Script for more information.
§Bitcoin Core References
Implementations§
§impl Script
impl Script
pub fn new_p2pkh(pubkey_hash: &PubkeyHash) -> Script
pub fn new_p2pkh(pubkey_hash: &PubkeyHash) -> Script
Generates P2PKH-type of scriptPubkey.
pub 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.
pub 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.
pub fn new_v0_p2wpkh(pubkey_hash: &WPubkeyHash) -> Script
pub fn new_v0_p2wpkh(pubkey_hash: &WPubkeyHash) -> Script
Generates P2WPKH-type of scriptPubkey.
pub 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.
pub 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.
pub 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.
pub 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
.
pub 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.
pub 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.
pub fn script_hash(&self) -> ScriptHash
pub fn script_hash(&self) -> ScriptHash
Returns 160-bit hash of the script.
pub fn wscript_hash(&self) -> WScriptHash
pub fn wscript_hash(&self) -> WScriptHash
Returns 256-bit hash of the script for P2WSH outputs.
pub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Converts the script into a byte vector.
pub fn p2wpkh_script_code(&self) -> Option<Script>
pub fn p2wpkh_script_code(&self) -> Option<Script>
Returns the script code used for spending a P2WPKH output if this script is a script pubkey
for a P2WPKH output. The scriptCode
is described in BIP143.
pub 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”).
pub 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.
pub 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
.
pub fn is_witness_program(&self) -> bool
pub fn is_witness_program(&self) -> bool
Checks whether a script pubkey is a Segregated Witness (segwit) program.
pub fn is_v0_p2wsh(&self) -> bool
pub fn is_v0_p2wsh(&self) -> bool
Checks whether a script pubkey is a P2WSH output.
pub fn is_v0_p2wpkh(&self) -> bool
pub fn is_v0_p2wpkh(&self) -> bool
Checks whether a script pubkey is a P2WPKH output.
pub fn is_v1_p2tr(&self) -> bool
pub fn is_v1_p2tr(&self) -> bool
Checks whether a script pubkey is a P2TR output.
pub fn is_op_return(&self) -> bool
pub fn is_op_return(&self) -> bool
Check if this is an OP_RETURN output.
pub 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.
pub 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.
pub 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
.
pub 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.
pub 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.
pub 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.
pub 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§
§impl Deserialize for Script
impl Deserialize for Script
§impl Into<Script> for ShutdownScript
impl Into<Script> for ShutdownScript
§impl Ord for Script
impl Ord for Script
§impl PartialOrd for Script
impl PartialOrd for Script
§impl TryFrom<Script> for ShutdownScript
impl TryFrom<Script> for ShutdownScript
§type Error = InvalidShutdownScript
type Error = InvalidShutdownScript
§fn try_from(
script: Script,
) -> Result<ShutdownScript, <ShutdownScript as TryFrom<Script>>::Error>
fn try_from( script: Script, ) -> Result<ShutdownScript, <ShutdownScript as TryFrom<Script>>::Error>
§impl Writeable for Script
impl Writeable 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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<T> Base32Len for T
impl<T> Base32Len for T
§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
§impl<T> CheckBase32<Vec<u5>> for T
impl<T> CheckBase32<Vec<u5>> for T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
§impl<T> MaybeReadable for Twhere
T: Readable,
impl<T> MaybeReadable for Twhere
T: Readable,
§impl<T> ToBase32 for T
impl<T> ToBase32 for T
§fn write_base32<W>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err>where
W: WriteBase32,
fn write_base32<W>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err>where
W: WriteBase32,
source§impl<T> ToHex for T
impl<T> ToHex for T
source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)