[][src]Struct miniscript::miniscript::Miniscript

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

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

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx>[src]

Iterator-related extensions for Miniscript

pub fn iter(&self) -> Iter<'_, Pk, Ctx>

Notable traits for Iter<'a, Pk, Ctx>

impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> Iterator for Iter<'a, Pk, Ctx> type Item = &'a Miniscript<Pk, Ctx>;
[src]

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.

pub fn iter_pk(&self) -> PkIter<'_, Pk, Ctx>

Notable traits for PkIter<'a, Pk, Ctx>

impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> Iterator for PkIter<'a, Pk, Ctx> type Item = Pk;
[src]

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.

pub fn iter_pkh(&self) -> PkhIter<'_, Pk, Ctx>

Notable traits for PkhIter<'a, Pk, Ctx>

impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> Iterator for PkhIter<'a, Pk, Ctx> type Item = Pk::Hash;
[src]

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.

pub fn iter_pk_pkh(&self) -> PkPkhIter<'_, Pk, Ctx>

Notable traits for PkPkhIter<'a, Pk, Ctx>

impl<'a, Pk: MiniscriptKey, Ctx: ScriptContext> Iterator for PkPkhIter<'a, Pk, Ctx> type Item = PkPkh<Pk>;
[src]

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.

pub fn branches(&self) -> Vec<&Miniscript<Pk, Ctx>>[src]

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

pub fn get_nth_child(&self, n: usize) -> Option<&Miniscript<Pk, Ctx>>[src]

Returns child node with given index, if any

pub fn get_leaf_pk(&self) -> Vec<Pk>[src]

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 [iter_pk()] function, for example miniscript.iter_pubkeys().collect().

pub fn get_leaf_pkh(&self) -> Vec<Pk::Hash>[src]

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 [iter_pkh()] function, for example miniscript.iter_pubkey_hashes().collect().

pub fn get_leaf_pk_pkh(&self) -> Vec<PkPkh<Pk>>[src]

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 [iter_pk_pkh()] function, for example miniscript.iter_pubkeys_and_hashes().collect().

pub fn get_nth_pk(&self, n: usize) -> Option<Pk>[src]

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.

pub fn get_nth_pkh(&self, n: usize) -> Option<Pk::Hash>[src]

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.

pub fn get_nth_pk_pkh(&self, n: usize) -> Option<PkPkh<Pk>>[src]

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.

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx>[src]

pub fn from_ast(t: Terminal<Pk, Ctx>) -> Result<Miniscript<Pk, Ctx>, Error>[src]

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.

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx>[src]

pub fn into_inner(self) -> Terminal<Pk, Ctx>[src]

Extracts the AstElem representing the root of the miniscript

pub fn as_inner(&self) -> &Terminal<Pk, Ctx>[src]

impl<Ctx: ScriptContext> Miniscript<PublicKey, Ctx>[src]

pub fn parse(script: &Script) -> Result<Miniscript<PublicKey, Ctx>, Error>[src]

Attempt to parse a script into a Miniscript representation

impl<Pk: MiniscriptKey + ToPublicKey, Ctx: ScriptContext> Miniscript<Pk, Ctx>[src]

pub fn encode(&self) -> Script[src]

Encode as a Bitcoin script

pub fn script_size(&self) -> usize[src]

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.

pub fn max_satisfaction_witness_elements(&self) -> usize[src]

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 panic on misformed Miniscript objects which do not correspond to semantically sane Scripts. (Such scripts should be rejected at parse time. Any exceptions are bugs.)

pub fn max_satisfaction_size(&self, one_cost: usize) -> usize[src]

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.

This function may panic on misformed Miniscript objects which do not correspond to semantically sane Scripts. (Such scripts should be rejected at parse time. Any exceptions are bugs.)

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Miniscript<Pk, Ctx>[src]

pub fn translate_pk<FPk, FPkh, Q, FuncError>(
    &self,
    translatefpk: &mut FPk,
    translatefpkh: &mut FPkh
) -> Result<Miniscript<Q, Ctx>, FuncError> where
    FPk: FnMut(&Pk) -> Result<Q, FuncError>,
    FPkh: FnMut(&Pk::Hash) -> Result<Q::Hash, FuncError>,
    Q: MiniscriptKey
[src]

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.

impl<Pk: MiniscriptKey + ToPublicKey, Ctx: ScriptContext> Miniscript<Pk, Ctx>[src]

pub fn satisfy<S: Satisfier<Pk>>(&self, satisfier: S) -> Option<Vec<Vec<u8>>>[src]

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

Trait Implementations

impl<Pk: Clone + MiniscriptKey, Ctx: Clone + ScriptContext> Clone for Miniscript<Pk, Ctx>[src]

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Debug for Miniscript<Pk, Ctx>[src]

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Display for Miniscript<Pk, Ctx>[src]

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Eq for Miniscript<Pk, Ctx>[src]

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.

impl<Pk, Ctx> FromStr for Miniscript<Pk, Ctx> where
    Pk: MiniscriptKey,
    Ctx: ScriptContext,
    <Pk as FromStr>::Err: ToString,
    <<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString
[src]

type Err = Error

The associated error which can be returned from parsing.

impl<Pk, Ctx> FromTree for Miniscript<Pk, Ctx> where
    Pk: MiniscriptKey,
    Ctx: ScriptContext,
    <Pk as FromStr>::Err: ToString,
    <<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString
[src]

fn from_tree(top: &Tree<'_>) -> Result<Miniscript<Pk, Ctx>, Error>[src]

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

impl<Pk: Hash + MiniscriptKey, Ctx: Hash + ScriptContext> Hash for Miniscript<Pk, Ctx>[src]

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Liftable<Pk> for Miniscript<Pk, Ctx>[src]

impl<Pk: MiniscriptKey, Ctx: ScriptContext> Ord for Miniscript<Pk, Ctx>[src]

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.

impl<Pk: MiniscriptKey, Ctx: ScriptContext> PartialEq<Miniscript<Pk, Ctx>> for Miniscript<Pk, Ctx>[src]

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.

impl<Pk: MiniscriptKey, Ctx: ScriptContext> PartialOrd<Miniscript<Pk, Ctx>> for Miniscript<Pk, Ctx>[src]

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.

Auto Trait Implementations

impl<Pk, Ctx> RefUnwindSafe for Miniscript<Pk, Ctx> where
    Ctx: RefUnwindSafe,
    Pk: RefUnwindSafe,
    <Pk as MiniscriptKey>::Hash: RefUnwindSafe

impl<Pk, Ctx> Send for Miniscript<Pk, Ctx> where
    Ctx: Send + Sync,
    Pk: Send + Sync,
    <Pk as MiniscriptKey>::Hash: Send + Sync

impl<Pk, Ctx> Sync for Miniscript<Pk, Ctx> where
    Ctx: Send + Sync,
    Pk: Send + Sync,
    <Pk as MiniscriptKey>::Hash: Send + Sync

impl<Pk, Ctx> Unpin for Miniscript<Pk, Ctx> where
    Ctx: Unpin,
    Pk: Unpin,
    <Pk as MiniscriptKey>::Hash: Unpin

impl<Pk, Ctx> UnwindSafe for Miniscript<Pk, Ctx> where
    Ctx: RefUnwindSafe + UnwindSafe,
    Pk: RefUnwindSafe + UnwindSafe,
    <Pk as MiniscriptKey>::Hash: RefUnwindSafe + UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.