pub enum Policy<Pk: MiniscriptKey> {
Unsatisfiable,
Trivial,
KeyHash(Pk::Hash),
After(u32),
Older(u32),
Sha256(Hash),
Hash256(Hash),
Ripemd160(Hash),
Hash160(Hash),
And(Vec<Policy<Pk>>),
Or(Vec<Policy<Pk>>),
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)
A relative locktime restriction
Older(u32)
An absolute 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
And(Vec<Policy<Pk>>)
A list of sub-policies, all of which must be satisfied
Or(Vec<Policy<Pk>>)
A list of sub-policies, one of which must be satisfied
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
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
sourcepub fn is_unsatisfiable(&self) -> bool
pub fn is_unsatisfiable(&self) -> bool
Helper function to detect a false/unsatisfiable policy
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> FromStr for Policy<Pk> where
Pk: MiniscriptKey,
<Pk as FromStr>::Err: ToString,
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
impl<Pk> FromStr for Policy<Pk> where
Pk: MiniscriptKey,
<Pk as FromStr>::Err: ToString,
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
sourceimpl<Pk> FromTree for Policy<Pk> where
Pk: MiniscriptKey,
<Pk as FromStr>::Err: ToString,
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
impl<Pk> FromTree for Policy<Pk> where
Pk: MiniscriptKey,
<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