Descriptor

Struct Descriptor 

Source
#[repr(C)]
pub struct Descriptor { /* private fields */ }
Expand description

A Bitcoin Output Script Descriptor (BOSD).

This is a compact binary format consisting of a type_tag that represents a ScriptPubKey that can be relayed by any node in the Bitcoin network, due to standardness requirements.

See the Bitcoin developer guide on Transactions for more information on standardness.

Implementations§

Source§

impl Descriptor

Source

pub fn to_address(&self, network: Network) -> Result<Address, DescriptorError>

Converts the Descriptor to a Bitcoin Address given a Network.

Source

pub fn to_script(&self) -> ScriptBuf

Converts the Descriptor to a Bitcoin ScriptBuf.

This is a standard relay-safe ScriptPubKey for a Bitcoin output.

Source§

impl Descriptor

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, DescriptorError>

Constructs a new Descriptor from a byte slice.

Users are advised to use the new_* methods whenever possible.

Source

pub fn from_vec(bytes: Vec<u8>) -> Result<Self, DescriptorError>

Constructs a new Descriptor from a byte Vec.

Users are advised to use the new_* methods whenever possible.

Source

pub fn new_op_return(payload: &[u8]) -> Result<Self, DescriptorError>

Constructs a new Descriptor from an OP_RETURN payload.

The payload is expected to be at most 80 bytes.

§Example
let payload = b"hello world";
let desc = Descriptor::new_op_return(payload).expect("valid payload that is at most 80 bytes");
Source

pub fn new_p2pkh(payload: &[u8; 20]) -> Self

Constructs a new Descriptor from a P2PKH payload.

The payload is expected to be a valid 20-byte hash.

§Example
let payload = [0u8; P2PKH_LEN]; // all zeros, don't use in production
let desc = Descriptor::new_p2pkh(&payload);
Source

pub fn new_p2sh(payload: &[u8; 20]) -> Self

Constructs a new Descriptor from a P2SH payload.

The payload is expected to be a valid 20-byte hash.

§Example
let payload = [0u8; P2SH_LEN]; // all zeros, don't use in production
let desc = Descriptor::new_p2sh(&payload);
Source

pub fn new_p2wpkh(payload: &[u8; 20]) -> Self

Constructs a new Descriptor from a P2WPKH payload.

The payload is expected to be a valid 20-byte hash.

§Example
let payload = [0u8; P2WPKH_LEN]; // all zeros, don't use in production
let desc = Descriptor::new_p2wpkh(&payload);
Source

pub fn new_p2wsh(payload: &[u8; 32]) -> Self

Constructs a new Descriptor from a P2WSH payload.

The payload is expected to be a valid 32-byte hash.

§Example
let payload = [0u8; P2WSH_LEN]; // all zeros, don't use in production
let desc = Descriptor::new_p2wsh(&payload);
Source

pub fn new_p2tr_unchecked(payload: &[u8; 32]) -> Self

Constructs a new Descriptor from an unchecked P2TR payload.

The payload is expected to be a valid 32-byte X-only public key. You must validate this key on your own; this function will not do it for you.

§Example
let payload = [2u8; P2TR_LEN]; // valid X-only public key, but don't use in production
let desc = Descriptor::new_p2tr_unchecked(&payload);
Source

pub fn new_p2tr(payload: &[u8; 32]) -> Result<Self, DescriptorError>

Constructs a new Descriptor from a P2TR payload.

The payload is expected to be a valid 32-byte X-only public key.A This function will validate this key for you, and return an error if validation fails.

§Example
let payload = [2u8; P2TR_LEN]; // valid X-only public key, but don't use in production
let desc = Descriptor::new_p2tr(&payload).expect("valid X-only public key");
Source

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

Returns the bytes representation of the descriptor.

That is:

  • 1-byte type tag.
  • arbitrary-sized payload.
Source

pub fn type_tag(&self) -> DescriptorType

Returns the type tag of the descriptor.

Source

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

Returns the payload of the descriptor.

§Warning

It is not advisable to use this method. Instead, try to parse it either as a Bitcoin address by using Descriptor::to_address in the case of an address, or as a Bitcoin script by using Descriptor::to_script in the case of an OP_RETURN payload.

Trait Implementations§

Source§

impl Clone for Descriptor

Source§

fn clone(&self) -> Descriptor

Returns a duplicate 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 Descriptor

Source§

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

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

impl<'de> Deserialize<'de> for Descriptor

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Descriptor

Source§

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

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

impl From<Address> for Descriptor

Source§

fn from(value: Address) -> Self

Converts to this type from the input type.
Source§

impl From<PubkeyHash> for Descriptor

Source§

fn from(pubkey_hash: PubkeyHash) -> Self

Converts to this type from the input type.
Source§

impl From<ScriptHash> for Descriptor

Source§

fn from(script_hash: ScriptHash) -> Self

Converts to this type from the input type.
Source§

impl From<TweakedPublicKey> for Descriptor

Source§

fn from(tweaked_pubkey: TweakedPublicKey) -> Self

Converts to this type from the input type.
Source§

impl From<WitnessProgram> for Descriptor

Source§

fn from(witness_program: WitnessProgram) -> Self

Converts to this type from the input type.
Source§

impl From<XOnlyPublicKey> for Descriptor

Source§

fn from(x_only_pubkey: XOnlyPublicKey) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Descriptor

Source§

type Err = DescriptorError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

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

impl PartialEq for Descriptor

Source§

fn eq(&self, other: &Descriptor) -> 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.
Source§

impl Serialize for Descriptor

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Descriptor

Source§

impl StructuralPartialEq for Descriptor

Auto Trait Implementations§

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

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,