#[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
impl Descriptor
Sourcepub fn to_address(&self, network: Network) -> Result<Address, DescriptorError>
pub fn to_address(&self, network: Network) -> Result<Address, DescriptorError>
Converts the Descriptor
to a Bitcoin Address
given a Network
.
Sourcepub fn to_script(&self) -> ScriptBuf
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
impl Descriptor
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, DescriptorError>
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.
Sourcepub fn from_vec(bytes: Vec<u8>) -> Result<Self, DescriptorError>
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.
Sourcepub fn new_op_return(payload: &[u8]) -> Result<Self, DescriptorError>
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");
Sourcepub fn new_p2pkh(payload: &[u8; 20]) -> Self
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);
Sourcepub fn new_p2sh(payload: &[u8; 20]) -> Self
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);
Sourcepub fn new_p2wpkh(payload: &[u8; 20]) -> Self
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);
Sourcepub fn new_p2wsh(payload: &[u8; 32]) -> Self
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);
Sourcepub fn new_p2tr_unchecked(payload: &[u8; 32]) -> Self
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);
Sourcepub fn new_p2tr(payload: &[u8; 32]) -> Result<Self, DescriptorError>
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");
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Returns the bytes representation of the descriptor.
That is:
- 1-byte type tag.
- arbitrary-sized payload.
Sourcepub fn type_tag(&self) -> DescriptorType
pub fn type_tag(&self) -> DescriptorType
Returns the type tag of the descriptor.
Sourcepub fn payload(&self) -> &[u8] ⓘ
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
impl Clone for Descriptor
Source§fn clone(&self) -> Descriptor
fn clone(&self) -> Descriptor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more