breez_sdk_liquid::bitcoin::blockdata::script

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

pub fn new() -> Script

Creates a new empty script.

pub fn new_p2pk(pubkey: &PublicKey) -> Script

Generates P2PK-type of scriptPubkey.

pub fn new_p2pkh(pubkey_hash: &PubkeyHash) -> Script

Generates P2PKH-type of scriptPubkey.

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

Generates P2WPKH-type of scriptPubkey.

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

Generates P2WSH-type of scriptPubkey with a given hash of the redeem 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>, ) -> Script
where 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

Generates P2TR for key spending path for a known TweakedPublicKey.

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

Generates OP_RETURN-type of scriptPubkey for the given data.

pub fn script_hash(&self) -> ScriptHash

Returns 160-bit hash of the script.

pub fn wscript_hash(&self) -> WScriptHash

Returns 256-bit hash of the script for P2WSH outputs.

pub fn len(&self) -> usize

Returns the length in bytes of the script.

pub fn is_empty(&self) -> bool

Returns whether the script is the empty script.

pub fn as_bytes(&self) -> &[u8]

Returns the script data as a byte slice.

pub fn to_bytes(&self) -> Vec<u8>

Returns a copy of the script data.

pub fn into_bytes(self) -> Vec<u8>

Converts the script into a byte vector.

pub fn to_p2sh(&self) -> Script

Computes the P2SH output corresponding to this redeem 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

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, ) -> Script
where 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>

Returns witness version of the script, if any, assuming the script is a scriptPubkey.

pub fn is_p2sh(&self) -> bool

Checks whether a script pubkey is a P2SH output.

pub fn is_p2pkh(&self) -> bool

Checks whether a script pubkey is a P2PKH output.

pub fn is_p2pk(&self) -> bool

Checks whether a script pubkey is a P2PK output.

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

Checks whether a script pubkey is a P2WSH output.

pub fn is_v0_p2wpkh(&self) -> bool

Checks whether a script pubkey is a P2WPKH output.

pub fn is_v1_p2tr(&self) -> bool

Checks whether a script pubkey is a P2TR output.

pub fn is_op_return(&self) -> bool

Check if this is an OP_RETURN output.

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

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<'_>

Iterates 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.

pub fn instructions_minimal(&self) -> Instructions<'_>

Iterates over the script in the form of Instructions while enforcing minimal pushes.

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>

Writes the assembly decoding of the script to the formatter.

pub fn bytes_to_asm(script: &[u8]) -> String

Creates an assembly decoding of the script in the given byte slice.

pub fn asm(&self) -> String

Returns the assembly decoding of the script.

Trait Implementations§

§

impl AsRef<[u8]> for Script

§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
§

impl Clone for Script

§

fn clone(&self) -> Script

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Script

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Decodable for Script

§

fn consensus_decode_from_finite_reader<R>(r: &mut R) -> Result<Script, Error>
where R: Read + ?Sized,

Decode Self from a size-limited reader. Read more
§

fn consensus_decode<R>(reader: &mut R) -> Result<Self, Error>
where R: Read + ?Sized,

Decode an object with a well-defined format. Read more
§

impl Default for Script

§

fn default() -> Script

Returns the “default value” for a type. Read more
§

impl Deserialize for Script

§

fn deserialize(bytes: &[u8]) -> Result<Script, Error>

Deserialize a value from raw data.
§

impl Display for Script

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Encodable for Script

§

fn consensus_encode<W>(&self, w: &mut W) -> Result<usize, Error>
where W: Write + ?Sized,

Encode an object with a well-defined format. Returns the number of bytes written on success. Read more
§

impl From<Vec<u8>> for Script

Creates a new script from an existing vector.

§

fn from(v: Vec<u8>) -> Script

Converts to this type from the input type.
§

impl FromHex for Script

§

fn from_byte_iter<I>(iter: I) -> Result<Script, Error>

Produces an object from a byte iterator.
§

fn from_hex(s: &str) -> Result<Self, Error>

Produces an object from a hex string.
§

impl FromStr for Script

§

type Err = Error

The associated error which can be returned from parsing.
§

fn from_str(s: &str) -> Result<Script, Error>

Parses a string s to return a value of this type. Read more
§

impl Hash for Script

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl<I> Index<I> for Script
where [u8]: Index<I>,

§

type Output = <[u8] as Index<I>>::Output

The returned type after indexing.
§

fn index(&self, index: I) -> &<Script as Index<I>>::Output

Performs the indexing (container[index]) operation. Read more
§

impl Into<Script> for ShutdownScript

§

fn into(self) -> Script

Converts this type into the (usually inferred) input type.
§

impl LowerHex for Script

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Ord for Script

§

fn cmp(&self, other: &Script) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
§

impl PartialEq for Script

§

fn eq(&self, other: &Script) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialOrd for Script

§

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 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl Readable for Script

§

fn read<R>(r: &mut R) -> Result<Script, DecodeError>
where R: Read,

Reads a Self in from the given Read.
§

impl Serialize for Script

§

fn serialize(&self) -> Vec<u8>

Serialize a value as raw data.
§

impl TryFrom<Script> for ShutdownScript

§

type Error = InvalidShutdownScript

The type returned in the event of a conversion error.
§

fn try_from( script: Script, ) -> Result<ShutdownScript, <ShutdownScript as TryFrom<Script>>::Error>

Performs the conversion.
§

impl UpperHex for Script

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Writeable for Script

§

fn write<W>(&self, w: &mut W) -> Result<(), Error>
where W: Writer,

Writes self out to the given Writer.
§

fn encode(&self) -> Vec<u8>

Writes self out to a Vec<u8>.
§

fn serialized_length(&self) -> usize

Gets the length of this object after it has been serialized. This can be overridden to optimize cases where we prepend an object with its length.
§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

§

impl<T> Base32Len for T
where T: AsRef<[u8]>,

§

fn base32_len(&self) -> usize

Calculate the base32 serialized length
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CheckBase32<Vec<u5>> for T
where T: AsRef<[u8]>,

§

type Err = Error

Error type if conversion fails
§

fn check_base32(self) -> Result<Vec<u5>, <T as CheckBase32<Vec<u5>>>::Err>

Check if all values are in range and return array-like struct of u5 values
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<T> MaybeReadable for T
where T: Readable,

§

fn read<R>(reader: &mut R) -> Result<Option<T>, DecodeError>
where R: Read,

Reads a Self in from the given Read.
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
§

impl<T> ToBase32 for T
where T: AsRef<[u8]>,

§

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.
§

fn to_base32(&self) -> Vec<u5>

Convert Self to base32 vector
§

impl<T> ToHex for T
where T: LowerHex,

§

fn to_hex(&self) -> String

Outputs the hash in hexadecimal form.

source§

impl<T> ToHex for T
where T: AsRef<[u8]>,

source§

fn encode_hex<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
source§

fn encode_hex_upper<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
§

impl<T> ToHex for T
where T: LowerHex,

§

fn to_hex(&self) -> String

Outputs the hash in hexadecimal form.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> DartSafe for T

§

impl<T> TaskRetFutTrait for T
where T: Send,