Enum miniscript::policy::concrete::Policy
source · pub enum Policy<Pk: MiniscriptKey> {
Unsatisfiable,
Trivial,
Key(Pk),
After(PackedLockTime),
Older(Sequence),
Sha256(Pk::Sha256),
Hash256(Pk::Hash256),
Ripemd160(Pk::Ripemd160),
Hash160(Pk::Hash160),
And(Vec<Policy<Pk>>),
Or(Vec<(usize, Policy<Pk>)>),
Threshold(usize, Vec<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(PackedLockTime)
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<Policy<Pk>>)
A list of sub-policies, all of which must be satisfied
Or(Vec<(usize, Policy<Pk>)>)
A list of sub-policies, one of which must be satisfied, along with relative probabilities for each one
Threshold(usize, Vec<Policy<Pk>>)
A set of descriptors, satisfactions must be provided for k
of them
Implementations
sourceimpl<Pk> Policy<Pk>where
Pk: MiniscriptKey,
impl<Pk> Policy<Pk>where
Pk: MiniscriptKey,
sourceimpl<Pk: MiniscriptKey> Policy<Pk>
impl<Pk: MiniscriptKey> Policy<Pk>
sourcepub fn translate_pk<Q, E, T>(&self, t: &mut T) -> Result<Policy<Q>, E>where
T: Translator<Pk, Q, E>,
Q: MiniscriptKey,
pub fn translate_pk<Q, E, T>(&self, t: &mut T) -> Result<Policy<Q>, E>where
T: Translator<Pk, Q, E>,
Q: MiniscriptKey,
Convert a policy using one kind of public key to another type of public key
Example
use miniscript::{bitcoin::PublicKey, policy::concrete::Policy, Translator, hash256};
use std::str::FromStr;
use miniscript::translate_hash_fail;
use std::collections::HashMap;
use miniscript::bitcoin::hashes::{sha256, hash160, ripemd160};
let alice_key = "0270cf3c71f65a3d93d285d9149fddeeb638f87a2d4d8cf16c525f71c417439777";
let bob_key = "02f43b15c50a436f5335dbea8a64dd3b4e63e34c3b50c42598acb5f4f336b5d2fb";
let placeholder_policy = Policy::<String>::from_str("and(pk(alice_key),pk(bob_key))").unwrap();
// Information to translator abstract String type keys to concrete bitcoin::PublicKey.
// In practice, wallets would map from String key names to BIP32 keys
struct StrPkTranslator {
pk_map: HashMap<String, bitcoin::PublicKey>
}
// If we also wanted to provide mapping of other associated types(sha256, older etc),
// we would use the general Translator Trait.
impl Translator<String, bitcoin::PublicKey, ()> for StrPkTranslator {
// Provides the translation public keys P -> Q
fn pk(&mut self, pk: &String) -> Result<bitcoin::PublicKey, ()> {
self.pk_map.get(pk).copied().ok_or(()) // Dummy Err
}
// Fail for hash types
translate_hash_fail!(String, bitcoin::PublicKey, ());
}
let mut pk_map = HashMap::new();
pk_map.insert(String::from("alice_key"), bitcoin::PublicKey::from_str(alice_key).unwrap());
pk_map.insert(String::from("bob_key"), bitcoin::PublicKey::from_str(bob_key).unwrap());
let mut t = StrPkTranslator { pk_map: pk_map };
let real_policy = placeholder_policy.translate_pk(&mut t).unwrap();
let expected_policy = Policy::from_str(&format!("and(pk({}),pk({}))", alice_key, bob_key)).unwrap();
assert_eq!(real_policy, expected_policy);
sourcepub fn translate_unsatisfiable_pk(self, key: &Pk) -> Policy<Pk>
pub fn translate_unsatisfiable_pk(self, key: &Pk) -> Policy<Pk>
Translate Concrete::Key(key)
to Concrete::Unsatisfiable
when extracting TapKey
sourcepub fn check_duplicate_keys(&self) -> Result<(), PolicyError>
pub fn check_duplicate_keys(&self) -> Result<(), PolicyError>
Check whether the policy contains duplicate public keys
sourcepub fn check_timelocks(&self) -> Result<(), PolicyError>
pub fn check_timelocks(&self) -> Result<(), PolicyError>
Checks whether the given concrete policy contains a combination of timelocks and heightlocks. Returns an error if there is at least one satisfaction that contains a combination of hieghtlock and timelock.
sourcepub fn is_valid(&self) -> Result<(), PolicyError>
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
sourcepub fn is_safe_nonmalleable(&self) -> (bool, bool)
pub fn is_safe_nonmalleable(&self) -> (bool, bool)
This returns whether any possible compilation of the policy could be compiled as non-malleable and safe. Note that this returns a tuple (safe, non-malleable) to avoid because the non-malleability depends on safety and we would like to cache results.
Trait Implementations
sourceimpl<Pk: Clone + MiniscriptKey> Clone for Policy<Pk>where
Pk::Sha256: Clone,
Pk::Hash256: Clone,
Pk::Ripemd160: Clone,
Pk::Hash160: Clone,
impl<Pk: Clone + MiniscriptKey> Clone for Policy<Pk>where
Pk::Sha256: Clone,
Pk::Hash256: Clone,
Pk::Ripemd160: Clone,
Pk::Hash160: Clone,
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::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,
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,
sourceimpl<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,
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,
sourceimpl<Pk: Hash + MiniscriptKey> Hash for Policy<Pk>where
Pk::Sha256: Hash,
Pk::Hash256: Hash,
Pk::Ripemd160: Hash,
Pk::Hash160: Hash,
impl<Pk: Hash + MiniscriptKey> Hash for Policy<Pk>where
Pk::Sha256: Hash,
Pk::Hash256: Hash,
Pk::Ripemd160: Hash,
Pk::Hash160: Hash,
sourceimpl<Pk: MiniscriptKey> Liftable<Pk> for Concrete<Pk>
impl<Pk: MiniscriptKey> Liftable<Pk> for Concrete<Pk>
sourceimpl<Pk: Ord + MiniscriptKey> Ord for Policy<Pk>where
Pk::Sha256: Ord,
Pk::Hash256: Ord,
Pk::Ripemd160: Ord,
Pk::Hash160: Ord,
impl<Pk: Ord + MiniscriptKey> Ord for Policy<Pk>where
Pk::Sha256: Ord,
Pk::Hash256: Ord,
Pk::Ripemd160: Ord,
Pk::Hash160: Ord,
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl<Pk: PartialEq + MiniscriptKey> PartialEq<Policy<Pk>> for Policy<Pk>where
Pk::Sha256: PartialEq,
Pk::Hash256: PartialEq,
Pk::Ripemd160: PartialEq,
Pk::Hash160: PartialEq,
impl<Pk: PartialEq + MiniscriptKey> PartialEq<Policy<Pk>> for Policy<Pk>where
Pk::Sha256: PartialEq,
Pk::Hash256: PartialEq,
Pk::Ripemd160: PartialEq,
Pk::Hash160: PartialEq,
sourceimpl<Pk: PartialOrd + MiniscriptKey> PartialOrd<Policy<Pk>> for Policy<Pk>where
Pk::Sha256: PartialOrd,
Pk::Hash256: PartialOrd,
Pk::Ripemd160: PartialOrd,
Pk::Hash160: PartialOrd,
impl<Pk: PartialOrd + MiniscriptKey> PartialOrd<Policy<Pk>> for Policy<Pk>where
Pk::Sha256: PartialOrd,
Pk::Hash256: PartialOrd,
Pk::Ripemd160: PartialOrd,
Pk::Hash160: PartialOrd,
sourcefn partial_cmp(&self, other: &Policy<Pk>) -> Option<Ordering>
fn partial_cmp(&self, other: &Policy<Pk>) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more