Enum 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(usize, Vec<Policy<Pk>>), }
Expand description
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
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
A SHA256 whose preimage must be provided to satisfy the descriptor
A SHA256d whose preimage must be provided to satisfy the descriptor
A RIPEMD160 whose preimage must be provided to satisfy the descriptor
A HASH160 whose preimage must be provided to satisfy the descriptor
A set of descriptors, satisfactions must be provided for k
of them
Implementations
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,
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,
Convert a policy using one kind of public key to another type of public key
Example
use miniscript::{bitcoin::{hashes::hash160, PublicKey}, policy::semantic::Policy}; use std::str::FromStr; let alice_pkh = "236ada020df3208d2517f4b0db03e16f92cd8cf1"; let bob_pkh = "3e89b972416ae33870b4634d03b8cdc773200cac"; let placeholder_policy = Policy::<String>::from_str("and(pkh(alice_pkh),pkh(bob_pkh))").unwrap(); let real_policy = placeholder_policy.translate_pkh(|placeholder| match placeholder.as_str() { "alice_pkh" => hash160::Hash::from_str(alice_pkh), "bob_pkh" => hash160::Hash::from_str(bob_pkh), _ => panic!("unknown key hash!") }).unwrap(); let expected_policy = Policy::<PublicKey>::from_str(&format!("and(pkh({}),pkh({}))", alice_pkh, bob_pkh)).unwrap(); assert_eq!(real_policy, expected_policy);
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.
Flatten out trees of And
s and Or
s; eliminate Trivial
and
Unsatisfiable
s. Does not reorder any branches; use .sort
.
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.
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.
Returns a list of all relative timelocks, not including 0, which appear in the policy
Filter a policy by eliminating relative timelock constraints that are not satisfied at the given age.
Count the number of public keys and keyhashes referenced in a policy. Duplicate keys will be double-counted.
Count the minimum number of public keys for which signatures could be used to satisfy the policy.
Trait Implementations
Run a predicate on every key in the descriptor, returning whether the predicate returned true for every key Read more
impl<Pk: PartialOrd + MiniscriptKey> PartialOrd<Policy<Pk>> for Policy<Pk> where
Pk::Hash: PartialOrd,
impl<Pk: PartialOrd + MiniscriptKey> PartialOrd<Policy<Pk>> for Policy<Pk> where
Pk::Hash: PartialOrd,
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
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
Mutably borrows from an owned value. Read more