pub struct Script(/* private fields */);
Expand description

A Bitcoin script

Implementations§

source§

impl Script

source

pub fn new() -> Script

Creates a new empty script

source

pub fn len(&self) -> usize

The length in bytes of the script

source

pub fn is_empty(&self) -> bool

Whether the script is the empty script

source

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

Returns the script data

source

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

Returns a copy of the script data

source

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

Convert the script into a byte vector

source

pub fn to_p2sh(&self) -> Script

Compute the P2SH output corresponding to this redeem script

source

pub fn to_v0_p2wsh(&self) -> Script

Compute the P2WSH output corresponding to this witnessScript (aka the “witness redeem script”)

source

pub fn is_p2sh(&self) -> bool

Checks whether a script pubkey is a p2sh output

source

pub fn is_p2pkh(&self) -> bool

Checks whether a script pubkey is a p2pkh output

source

pub fn is_p2pk(&self) -> bool

Checks whether a script pubkey is a p2pk output

source

pub fn is_witness_program(&self) -> bool

Checks whether a script pubkey is a Segregated Witness (segwit) program.

source

pub fn is_v0_p2wsh(&self) -> bool

Checks whether a script pubkey is a p2wsh output

source

pub fn is_v0_p2wpkh(&self) -> bool

Checks whether a script pubkey is a p2wpkh output

source

pub fn is_op_return(&self) -> bool

Check if this is an OP_RETURN output

source

pub fn is_provably_unspendable(&self) -> bool

Whether a script can be proven to have no satisfying input

source

pub fn is_cp2pkh(&self) -> bool

Check if a script pubkey is a cp2pkh output

source

pub fn is_cp2sh(&self) -> bool

Check if a script pubkey is a cp2sh output

source

pub fn is_colored(&self) -> bool

Check if a script pubkey is a colored coin script

source

pub fn is_multisig(&self) -> bool

Check if a script pubkey is multisig script

source

pub fn get_multisig_pubkeys( &self ) -> Result<(i32, Vec<PublicKey>), MultisigError>

Return public keys for multisig script, and the number of signatures required

source

pub fn add_color( &self, color_id: ColorIdentifier ) -> Result<Script, ColoredCoinError>

Create new script with color identifier

source

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 [instructions_minimal].

source

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

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

source

pub fn fmt_asm(&self, f: &mut dyn Write) -> Result

Write the assembly decoding of the script to the formatter.

source

pub fn asm(&self) -> String

Get the assembly decoding of the script.

source

pub fn split_color(&self) -> Option<(ColorIdentifier, Script)>

Extract a color_id and a remaining script Return None if script is not colored coin

source

pub fn script_type(&self) -> ScriptType

Return script type.

Trait Implementations§

source§

impl Clone for Script

source§

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

impl Debug for Script

source§

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

Formats the value using the given formatter. Read more
source§

impl Decodable for Script

source§

fn consensus_decode<D: Read>(d: D) -> Result<Self, Error>

Decode an object with a well-defined format
source§

impl Default for Script

source§

fn default() -> Script

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

impl Deserialize for Script

source§

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

Deserialize a value from raw data.
source§

impl Display for Script

source§

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

Formats the value using the given formatter. Read more
source§

impl Encodable for Script

source§

fn consensus_encode<S: Write>(&self, s: S) -> Result<usize, Error>

Encode an object with a well-defined format, should only ever error if the underlying Write errors. Returns the number of bytes written on success
source§

impl From<Vec<u8>> for Script

Creates a new script from an existing vector

source§

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

Converts to this type from the input type.
source§

impl Hash for Script

source§

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

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

impl Index<Range<usize>> for Script

§

type Output = [u8]

The returned type after indexing.
source§

fn index(&self, index: Range<usize>) -> &[u8]

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

impl Index<RangeFrom<usize>> for Script

§

type Output = [u8]

The returned type after indexing.
source§

fn index(&self, index: RangeFrom<usize>) -> &[u8]

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

impl Index<RangeFull> for Script

§

type Output = [u8]

The returned type after indexing.
source§

fn index(&self, _: RangeFull) -> &[u8]

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

impl Index<RangeTo<usize>> for Script

§

type Output = [u8]

The returned type after indexing.
source§

fn index(&self, index: RangeTo<usize>) -> &[u8]

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

impl LowerHex for Script

source§

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

Formats the value using the given formatter.
source§

impl Ord for Script

source§

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) -> Selfwhere Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Script

source§

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

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

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

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

impl PartialOrd for Script

source§

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

This method 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

This method 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

This method 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

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

impl Serialize for Script

source§

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

Serialize a value as raw data.
source§

impl UpperHex for Script

source§

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

Formats the value using the given formatter.
source§

impl Eq for Script

source§

impl StructuralEq for Script

source§

impl StructuralPartialEq for Script

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dstwhere T: Cast<Dst>,

Casts the value.
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,

Casts the value.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,

Casts the value.
source§

impl<T> ToHex for Twhere T: LowerHex,

source§

fn to_hex(&self) -> String

Outputs the hash in hexadecimal form

source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,

Casts the value.