Enum sapio_miniscript::policy::semantic::Policy[][src]

pub enum Policy<Pk: MiniscriptKey> {
    Unsatisfiable,
    Trivial,
    KeyHash(Pk::Hash),
    After(u32),
    Older(u32),
    Sha256(Hash),
    Hash256(Hash),
    Ripemd160(Hash),
    Hash160(Hash),
    Threshold(usizeVec<Policy<Pk>>),
    TxTemplate(Hash),
}

Abstract policy which corresponds to the semantics of a Miniscript and which allows complex forms of analysis, e.g. filtering and normalization. Semantic policies store only hashes of keys to ensure that objects representing the same policy are lifted to the same Semantic, regardless of their choice of pk or pk_h nodes.

Variants

Unsatisfiable

Unsatisfiable

Trivial

Trivially satisfiable

KeyHash(Pk::Hash)

Signature and public key matching a given hash is required

After(u32)

An absolute locktime restriction

Older(u32)

A relative locktime restriction

Sha256(Hash)

A SHA256 whose preimage must be provided to satisfy the descriptor

Hash256(Hash)

A SHA256d whose preimage must be provided to satisfy the descriptor

Ripemd160(Hash)

A RIPEMD160 whose preimage must be provided to satisfy the descriptor

Hash160(Hash)

A HASH160 whose preimage must be provided to satisfy the descriptor

Threshold(usizeVec<Policy<Pk>>)

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

TxTemplate(Hash)

A SHA256 whose must match the tx template

Implementations

impl<Pk: MiniscriptKey> Policy<Pk>[src]

pub fn translate_pkh<Fpkh, Q, E>(
    &self,
    translatefpkh: Fpkh
) -> Result<Policy<Q>, E> where
    Fpkh: FnMut(&Pk::Hash) -> Result<Q::Hash, E>,
    Q: MiniscriptKey
[src]

Convert a policy using one kind of public key to another type of public key

pub fn entails(self, other: Policy<Pk>) -> Result<bool, PolicyError>[src]

This function computes whether the current policy entails the second one. A |- B means every satisfaction of A is also a satisfaction of B. This implementation will run slow for larger policies but should be sufficient for most practical policies.

impl<Pk: MiniscriptKey> Policy<Pk>[src]

pub fn normalized(self) -> Policy<Pk>[src]

Flatten out trees of Ands and Ors; eliminate Trivial and Unsatisfiables. Does not reorder any branches; use .sort.

pub fn is_trivial(&self) -> bool[src]

Helper function to detect a true/trivial policy This function only checks whether the policy is Policy::Trivial For checking if the normalized form is trivial, the caller is expected to normalize the policy first.

pub fn is_unsatisfiable(&self) -> bool[src]

Helper function to detect a false/unsatisfiable policy This function only checks whether the policy is Policy::Unsatisfiable For checking if the normalized form is unsatisfiable, the caller is expected to normalize the policy first.

pub fn relative_timelocks(&self) -> Vec<u32>[src]

Returns a list of all relative timelocks, not including 0, which appear in the policy

pub fn at_age(self, time: u32) -> Policy<Pk>[src]

Filter a policy by eliminating relative timelock constraints that are not satisfied at the given age.

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

Count the number of public keys and keyhashes referenced in a policy. Duplicate keys will be double-counted.

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

Count the minimum number of public keys for which signatures could be used to satisfy the policy.

impl<Pk: MiniscriptKey> Policy<Pk>[src]

pub fn sorted(self) -> Policy<Pk>[src]

“Sort” a policy to bring it into a canonical form to allow comparisons. Does not allow policies to be compared for functional equivalence; in general this appears to require Gröbner basis techniques that are not implemented.

Trait Implementations

impl<Pk: Clone + MiniscriptKey> Clone for Policy<Pk> where
    Pk::Hash: Clone
[src]

impl<Pk: MiniscriptKey> Debug for Policy<Pk>[src]

impl<Pk: MiniscriptKey> Display for Policy<Pk>[src]

impl<Pk: Eq + MiniscriptKey> Eq for Policy<Pk> where
    Pk::Hash: Eq
[src]

impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk>[src]

impl<Pk> FromStr for Policy<Pk> where
    Pk: MiniscriptKey + FromStr,
    Pk::Hash: FromStr,
    <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> FromTree for Policy<Pk> where
    Pk: MiniscriptKey + FromStr,
    Pk::Hash: FromStr,
    <Pk as FromStr>::Err: ToString,
    <<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString
[src]

impl<Pk: MiniscriptKey> Liftable<Pk> for Semantic<Pk>[src]

impl<Pk: Ord + MiniscriptKey> Ord for Policy<Pk> where
    Pk::Hash: Ord
[src]

impl<Pk: PartialEq + MiniscriptKey> PartialEq<Policy<Pk>> for Policy<Pk> where
    Pk::Hash: PartialEq
[src]

impl<Pk: PartialOrd + MiniscriptKey> PartialOrd<Policy<Pk>> for Policy<Pk> where
    Pk::Hash: PartialOrd
[src]

impl<Pk: MiniscriptKey> StructuralEq for Policy<Pk>[src]

impl<Pk: MiniscriptKey> StructuralPartialEq for Policy<Pk>[src]

Auto Trait Implementations

impl<Pk> RefUnwindSafe for Policy<Pk> where
    <Pk as MiniscriptKey>::Hash: RefUnwindSafe

impl<Pk> Send for Policy<Pk> where
    <Pk as MiniscriptKey>::Hash: Send

impl<Pk> Sync for Policy<Pk> where
    <Pk as MiniscriptKey>::Hash: Sync

impl<Pk> Unpin for Policy<Pk> where
    <Pk as MiniscriptKey>::Hash: Unpin

impl<Pk> UnwindSafe for Policy<Pk> where
    <Pk as MiniscriptKey>::Hash: 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.