Struct bdk::descriptor::Miniscript[]

pub struct Miniscript<Pk, Ctx> where
    Ctx: ScriptContext,
    Pk: MiniscriptKey, 
{ pub node: Terminal<Pk, Ctx>, pub ty: Type, pub ext: ExtData, // some fields omitted }
Expand description

Top-level script AST type

Fields

node: Terminal<Pk, Ctx>

A node in the Abstract Syntax Tree(

ty: Type

The correctness and malleability type information for the AST node

ext: ExtData

Additional information helpful for extra analysis.

Implementations

Whether all spend paths of miniscript require a signature

Whether the miniscript is malleable

Whether the miniscript can exceed the resource limits(Opcodes, Stack limit etc)

Whether the miniscript contains a combination of timelocks

Whether the miniscript has repeated Pk or Pkh

Check whether the underlying Miniscript is safe under the current context Lifting these polices would create a semantic representation that does not represent the underlying semantics when miniscript is spent. Signing logic may not find satisfaction even if one exists.

For most cases, users should be dealing with safe scripts. Use this function to check whether the guarantees of library hold. Most functions of the library like would still work, but results cannot be relied upon

Iterator-related extensions for Miniscript

Creates a new [Iter] iterator that will iterate over all Miniscript items within AST by traversing its branches. For the specific algorithm please see [Iter::next] function.

Creates a new [PkIter] iterator that will iterate over all plain public keys (and not key hash values) present in Miniscript items within AST by traversing all its branches. For the specific algorithm please see [PkIter::next] function.

Creates a new [PkhIter] iterator that will iterate over all public keys hashes (and not plain public keys) present in Miniscript items within AST by traversing all its branches. For the specific algorithm please see [PkhIter::next] function.

Creates a new [PkPkhIter] iterator that will iterate over all plain public keys and key hash values present in Miniscript items within AST by traversing all its branches. For the specific algorithm please see [PkPkhIter::next] function.

Enumerates all child nodes of the current AST node (self) and returns a Vec referencing them.

Returns child node with given index, if any

Returns Vec with cloned version of all public keys from the current miniscript item, if any. Otherwise returns an empty Vec.

NB: The function analyzes only single miniscript item and not any of its descendants in AST. To obtain a list of all public keys within AST use Miniscript::iter_pk() function, for example miniscript.iter_pubkeys().collect().

Returns Vec with hashes of all public keys from the current miniscript item, if any. Otherwise returns an empty Vec.

For each public key the function computes hash; for each hash of the public key the function returns its cloned copy.

NB: The function analyzes only single miniscript item and not any of its descendants in AST. To obtain a list of all public key hashes within AST use Miniscript::iter_pkh() function, for example miniscript.iter_pubkey_hashes().collect().

Returns Vec of [PkPkh] entries, representing either public keys or public key hashes, depending on the data from the current miniscript item. If there is no public keys or hashes, the function returns an empty Vec.

NB: The function analyzes only single miniscript item and not any of its descendants in AST. To obtain a list of all public keys or hashes within AST use Miniscript::iter_pk_pkh() function, for example miniscript.iter_pubkeys_and_hashes().collect().

Returns Option::Some with cloned n’th public key from the current miniscript item, if any. Otherwise returns Option::None.

NB: The function analyzes only single miniscript item and not any of its descendants in AST.

Returns Option::Some with hash of n’th public key from the current miniscript item, if any. Otherwise returns Option::None.

For each public key the function computes hash; for each hash of the public key the function returns it cloned copy.

NB: The function analyzes only single miniscript item and not any of its descendants in AST.

Returns Option::Some with hash of n’th public key or hash from the current miniscript item, if any. Otherwise returns Option::None.

NB: The function analyzes only single miniscript item and not any of its descendants in AST.

Add type information(Type and Extdata) to Miniscript based on AstElem fragment. Dependent on display and clone because of Error Display code of type_check.

Extracts the AstElem representing the root of the miniscript

Get a reference to the inner AstElem representing the root of miniscript

Attempt to parse an insane(scripts don’t clear sanity checks) script into a Miniscript representation. Use this to parse scripts with repeated pubkeys, timelock mixing, malleable scripts without sig or scripts that can exceed resource limits. Some of the analysis guarantees of miniscript are lost when dealing with insane scripts. In general, in a multi-party setting users should only accept sane scripts.

Attempt to parse a Script into Miniscript representation. This function will fail parsing for scripts that do not clear the Miniscript::sanity_check checks. Use Miniscript::parse_insane to parse such scripts.

Encode as a Bitcoin script

Size, in bytes of the script-pubkey. If this Miniscript is used outside of segwit (e.g. in a bare or P2SH descriptor), this quantity should be multiplied by 4 to compute the weight.

In general, it is not recommended to use this function directly, but to instead call the corresponding function on a Descriptor, which will handle the segwit/non-segwit technicalities for you.

Maximum number of witness elements used to satisfy the Miniscript fragment, including the witness script itself. Used to estimate the weight of the VarInt that specifies this number in a serialized transaction.

This function may returns Error when the Miniscript is impossible to satisfy

Maximum size, in bytes, of a satisfying witness. For Segwit outputs one_cost should be set to 2, since the number 1 requires two bytes to encode. For non-segwit outputs one_cost should be set to 1, since OP_1 is available in scriptSigs.

In general, it is not recommended to use this function directly, but to instead call the corresponding function on a Descriptor, which will handle the segwit/non-segwit technicalities for you.

All signatures are assumed to be 73 bytes in size, including the length prefix (segwit) or push opcode (pre-segwit) and sighash postfix.

Attempt to parse an insane(scripts don’t clear sanity checks) from string into a Miniscript representation. Use this to parse scripts with repeated pubkeys, timelock mixing, malleable scripts without sig or scripts that can exceed resource limits. Some of the analysis guarantees of miniscript are lost when dealing with insane scripts. In general, in a multi-party setting users should only accept sane scripts.

Attempt to produce non-malleable satisfying witness for the witness script represented by the parse tree

Attempt to produce a malleable satisfying witness for the witness script represented by the parse tree

Lifting corresponds conversion of miniscript into Policy [policy.semantic.Policy] for human readable or machine analysis. However, naively lifting miniscripts can result in incorrect interpretations that don’t correspond underlying semantics when we try to spend them on bitcoin network. This can occur if the miniscript contains a

  1. Timelock combination
  2. Contains a spend that exceeds resource limits

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Extract the spending policy

Run a predicate on every key in the descriptor, returning whether the predicate returned true for every key Read more

Run a predicate on every key in the descriptor, returning whether the predicate returned true for any key Read more

Parse a Miniscript from string and perform sanity checks See Miniscript::from_str_insane to parse scripts from string that do not clear the Miniscript::sanity_check checks.

The associated error which can be returned from parsing.

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

Parse an expression tree into a Miniscript. As a general rule, this should not be called directly; rather go through the descriptor API.

Feeds this value into the given Hasher. Read more

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

Convert the object into an abstract policy

Ord of Miniscript must depend only on node and not the type information. The type information and extra_properties can be deterministically determined by the ast.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

PartialEq of Miniscript must depend only on node and not the type information. The type information and extra_properties can be deterministically determined by the ast.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

PartialOrd of Miniscript must depend only on node and not the type information. The type information and extra_properties can be deterministically determined by the ast.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

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

This will panic if translatefpk returns an uncompressed key when converting to a Segwit descriptor. To prevent this panic, ensure translatefpk returns an error in this case instead.

The associated output type. This must be Self

Calls translate_pk with conversion functions that cannot fail

Eq of Miniscript must depend only on node and not the type information. The type information and extra_properties can be deterministically determined by the ast.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Converts the given value to a String. Read more

Translate a struct from one generic to another where the translation for Pk is provided by translatefpk Read more

Translate a struct from one generic to another where the translation for Pk is provided by translatefpk Read more

Translate a struct from one generic to another where the translation for Pk is provided by translatefpk Read more

Translate a struct from one generic to another where the translation for Pk is provided by translatefpk Read more

Translate a struct from one generic to another where the translation for Pk is provided by translatefpk Read more

Translate a struct from one generic to another where the translation for Pk is provided by translatefpk Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.