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
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(usize, Vec<Policy<Pk>>)
A set of descriptors, satisfactions must be provided for k
of them
Implementations
sourceimpl<Pk: MiniscriptKey> Policy<Pk>
impl<Pk: MiniscriptKey> Policy<Pk>
sourcepub 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);
sourcepub fn entails(self, other: Policy<Pk>) -> Result<bool, PolicyError>
pub fn entails(self, other: Policy<Pk>) -> Result<bool, PolicyError>
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.
sourceimpl<Pk: MiniscriptKey> Policy<Pk>
impl<Pk: MiniscriptKey> Policy<Pk>
sourcepub fn normalized(self) -> Policy<Pk>
pub fn normalized(self) -> Policy<Pk>
Flatten out trees of And
s and Or
s; eliminate Trivial
and
Unsatisfiable
s. Does not reorder any branches; use .sort
.
sourcepub fn is_trivial(&self) -> bool
pub fn is_trivial(&self) -> bool
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.
sourcepub fn is_unsatisfiable(&self) -> bool
pub fn is_unsatisfiable(&self) -> bool
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.
sourcepub fn relative_timelocks(&self) -> Vec<u32>
pub fn relative_timelocks(&self) -> Vec<u32>
Returns a list of all relative timelocks, not including 0, which appear in the policy
sourcepub fn at_age(self, time: u32) -> Policy<Pk>
pub fn at_age(self, time: u32) -> Policy<Pk>
Filter a policy by eliminating relative timelock constraints that are not satisfied at the given age.
sourcepub fn n_keys(&self) -> usize
pub fn n_keys(&self) -> usize
Count the number of public keys and keyhashes referenced in a policy. Duplicate keys will be double-counted.
sourcepub fn minimum_n_keys(&self) -> usize
pub fn minimum_n_keys(&self) -> usize
Count the minimum number of public keys for which signatures could be used to satisfy the policy.
sourceimpl<Pk: MiniscriptKey> Policy<Pk>
impl<Pk: MiniscriptKey> Policy<Pk>
Trait Implementations
sourceimpl<Pk: MiniscriptKey> Debug for Policy<Pk>
impl<Pk: MiniscriptKey> Debug for Policy<Pk>
sourceimpl<Pk: MiniscriptKey> Display for Policy<Pk>
impl<Pk: MiniscriptKey> Display for Policy<Pk>
sourceimpl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk>
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk>
sourceimpl<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,
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,
sourceimpl<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,
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,
sourceimpl<Pk: MiniscriptKey> Liftable<Pk> for Semantic<Pk>
impl<Pk: MiniscriptKey> Liftable<Pk> for Semantic<Pk>
sourceimpl<Pk: Ord + MiniscriptKey> Ord for Policy<Pk> where
Pk::Hash: Ord,
impl<Pk: Ord + MiniscriptKey> Ord for Policy<Pk> where
Pk::Hash: Ord,
sourceimpl<Pk: PartialEq + MiniscriptKey> PartialEq<Policy<Pk>> for Policy<Pk> where
Pk::Hash: PartialEq,
impl<Pk: PartialEq + MiniscriptKey> PartialEq<Policy<Pk>> for Policy<Pk> where
Pk::Hash: PartialEq,
sourceimpl<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,
sourcefn partial_cmp(&self, other: &Policy<Pk>) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
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 · sourcefn le(&self, other: &Rhs) -> bool
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
impl<Pk: Eq + MiniscriptKey> Eq for Policy<Pk> where
Pk::Hash: Eq,
impl<Pk: MiniscriptKey> StructuralEq for Policy<Pk>
impl<Pk: MiniscriptKey> StructuralPartialEq for Policy<Pk>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more