pub enum Policy<Pk: MiniscriptKey> {
    Unsatisfiable,
    Trivial,
    Key(Pk),
    After(AbsLockTime),
    Older(Sequence),
    Sha256(Pk::Sha256),
    Hash256(Pk::Hash256),
    Ripemd160(Pk::Ripemd160),
    Hash160(Pk::Hash160),
    And(Vec<Arc<Policy<Pk>>>),
    Or(Vec<(usize, Arc<Policy<Pk>>)>),
    Threshold(usize, Vec<Arc<Policy<Pk>>>),
}
Expand description

Concrete policy which corresponds directly to a miniscript structure, and whose disjunctions are annotated with satisfaction probabilities to assist the compiler.

Variants§

§

Unsatisfiable

Unsatisfiable.

§

Trivial

Trivially satisfiable.

§

Key(Pk)

A public key which must sign to satisfy the descriptor.

§

After(AbsLockTime)

An absolute locktime restriction.

§

Older(Sequence)

A relative locktime restriction.

§

Sha256(Pk::Sha256)

A SHA256 whose preimage must be provided to satisfy the descriptor.

§

Hash256(Pk::Hash256)

A SHA256d whose preimage must be provided to satisfy the descriptor.

§

Ripemd160(Pk::Ripemd160)

A RIPEMD160 whose preimage must be provided to satisfy the descriptor.

§

Hash160(Pk::Hash160)

A HASH160 whose preimage must be provided to satisfy the descriptor.

§

And(Vec<Arc<Policy<Pk>>>)

A list of sub-policies, all of which must be satisfied.

§

Or(Vec<(usize, Arc<Policy<Pk>>)>)

A list of sub-policies, one of which must be satisfied, along with relative probabilities for each one.

§

Threshold(usize, Vec<Arc<Policy<Pk>>>)

A set of descriptors, satisfactions must be provided for k of them.

Implementations§

source§

impl<Pk> Policy<Pk>where Pk: MiniscriptKey,

source

pub fn after(n: u32) -> Policy<Pk>

Construct a Policy::After from n. Helper function equivalent to Policy::After(absolute::LockTime::from_consensus(n)).

source

pub fn older(n: u32) -> Policy<Pk>

Construct a Policy::Older from n. Helper function equivalent to Policy::Older(Sequence::from_consensus(n)).

source§

impl<Pk: MiniscriptKey> Policy<Pk>

source

pub fn translate_pk<Q, E, T>(&self, t: &mut T) -> Result<Policy<Q>, E>where T: Translator<Pk, Q, E>, Q: MiniscriptKey,

Converts a policy using one kind of public key to another type of public key.

For example usage please see crate::policy::semantic::Policy::translate_pk.

source

pub fn translate_unsatisfiable_pk(self, key: &Pk) -> Policy<Pk>

Translates Concrete::Key(key) to Concrete::Unsatisfiable when extracting TapKey.

source

pub fn keys(&self) -> Vec<&Pk>

Gets all keys in the policy.

source

pub fn check_duplicate_keys(&self) -> Result<(), PolicyError>

Checks whether the policy contains duplicate public keys.

source

pub fn check_timelocks(&self) -> Result<(), PolicyError>

Checks whether the given concrete policy contains a combination of timelocks and heightlocks.

Returns

Returns an error if there is at least one satisfaction that contains a combination of heightlock and timelock.

source

pub fn is_valid(&self) -> Result<(), PolicyError>

This returns whether the given policy is valid or not. It maybe possible that the policy contains Non-two argument and, or or a 0 arg thresh. Validity condition also checks whether there is a possible satisfaction combination of timelocks and heightlocks

source

pub fn is_safe_nonmalleable(&self) -> (bool, bool)

Checks if any possible compilation of the policy could be compiled as non-malleable and safe.

Returns

Returns a tuple (safe, non-malleable) to avoid the fact that non-malleability depends on safety and we would like to cache results.

Trait Implementations§

source§

impl<Pk: Clone + MiniscriptKey> Clone for Policy<Pk>where Pk::Sha256: Clone, Pk::Hash256: Clone, Pk::Ripemd160: Clone, Pk::Hash160: Clone,

source§

fn clone(&self) -> Policy<Pk>

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<Pk: MiniscriptKey> Debug for Policy<Pk>

source§

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

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

impl<Pk: MiniscriptKey> Display for Policy<Pk>

source§

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

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

impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk>

source§

fn for_each_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> bool

Run a predicate on every key in the descriptor, returning whether the predicate returned true for every key
source§

fn for_any_key<'a, F: FnMut(&'a Pk) -> bool>(&'a self, pred: F) -> boolwhere Pk: 'a,

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

impl<Pk> FromStr for Policy<Pk>where Pk: MiniscriptKey + FromStr, Pk::Sha256: FromStr, Pk::Hash256: FromStr, Pk::Ripemd160: FromStr, Pk::Hash160: FromStr, <Pk as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Sha256 as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Hash256 as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Ripemd160 as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Hash160 as FromStr>::Err: ToString,

§

type Err = Error

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

fn from_str(s: &str) -> Result<Policy<Pk>, Error>

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

impl<Pk> FromTree for Policy<Pk>where Pk: MiniscriptKey + FromStr, Pk::Sha256: FromStr, Pk::Hash256: FromStr, Pk::Ripemd160: FromStr, Pk::Hash160: FromStr, <Pk as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Sha256 as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Hash256 as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Ripemd160 as FromStr>::Err: ToString, <<Pk as MiniscriptKey>::Hash160 as FromStr>::Err: ToString,

source§

fn from_tree(top: &Tree<'_>) -> Result<Policy<Pk>, Error>

Extract a structure from Tree representation
source§

impl<Pk: Hash + MiniscriptKey> Hash for Policy<Pk>where Pk::Sha256: Hash, Pk::Hash256: Hash, Pk::Ripemd160: Hash, Pk::Hash160: Hash,

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<Pk: MiniscriptKey> Liftable<Pk> for Concrete<Pk>

source§

fn lift(&self) -> Result<Semantic<Pk>, Error>

Converts this object into an abstract policy.
source§

impl<Pk: Ord + MiniscriptKey> Ord for Policy<Pk>where Pk::Sha256: Ord, Pk::Hash256: Ord, Pk::Ripemd160: Ord, Pk::Hash160: Ord,

source§

fn cmp(&self, other: &Policy<Pk>) -> 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<Self>,

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

impl<Pk: PartialEq + MiniscriptKey> PartialEq<Policy<Pk>> for Policy<Pk>where Pk::Sha256: PartialEq, Pk::Hash256: PartialEq, Pk::Ripemd160: PartialEq, Pk::Hash160: PartialEq,

source§

fn eq(&self, other: &Policy<Pk>) -> 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<Pk: PartialOrd + MiniscriptKey> PartialOrd<Policy<Pk>> for Policy<Pk>where Pk::Sha256: PartialOrd, Pk::Hash256: PartialOrd, Pk::Ripemd160: PartialOrd, Pk::Hash160: PartialOrd,

source§

fn partial_cmp(&self, other: &Policy<Pk>) -> 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<'a, Pk: MiniscriptKey> TreeLike for &'a Concrete<Pk>

source§

fn as_node(&self) -> Tree<Self>

Interpret the node as an abstract node.
source§

fn n_children(&self) -> usize

Accessor for the number of children this node has.
source§

fn nth_child(&self, n: usize) -> Option<Self>

Accessor for the nth child of the node, if a child with that index exists.
source§

fn pre_order_iter(self) -> PreOrderIter<Self>

Obtains an iterator of all the nodes rooted at the node, in pre-order.
source§

fn verbose_pre_order_iter(self) -> VerbosePreOrderIter<Self>

Obtains a verbose iterator of all the nodes rooted at the DAG, in pre-order. Read more
source§

fn post_order_iter(self) -> PostOrderIter<Self>

Obtains an iterator of all the nodes rooted at the DAG, in post order. Read more
source§

impl<Pk: Eq + MiniscriptKey> Eq for Policy<Pk>where Pk::Sha256: Eq, Pk::Hash256: Eq, Pk::Ripemd160: Eq, Pk::Hash160: Eq,

source§

impl<Pk: MiniscriptKey> StructuralEq for Policy<Pk>

source§

impl<Pk: MiniscriptKey> StructuralPartialEq for Policy<Pk>

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