Policy

Enum Policy 

Source
pub enum Policy<Pk: MiniscriptKey> {
Show 13 variants Unsatisfiable, Trivial, Key(Pk), After(u32), Older(u32), Sha256(Hash), Hash256(Hash), Ripemd160(Hash), Hash160(Hash), And(Vec<Policy<Pk>>), Or(Vec<(usize, Policy<Pk>)>), Threshold(usize, Vec<Policy<Pk>>), TxTemplate(Hash),
}
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(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

§

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

§

TxTemplate(Hash)

A SHA256 whose must match the tx template

Implementations§

Source§

impl<Pk: MiniscriptKey> Policy<Pk>

Source

pub fn translate_pk<Fpk, Q, E>(&self, translatefpk: Fpk) -> Result<Policy<Q>, E>
where Fpk: FnMut(&Pk) -> Result<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};
use std::str::FromStr;
let alice_key = "0270cf3c71f65a3d93d285d9149fddeeb638f87a2d4d8cf16c525f71c417439777";
let bob_key = "02f43b15c50a436f5335dbea8a64dd3b4e63e34c3b50c42598acb5f4f336b5d2fb";
let placeholder_policy = Policy::<String>::from_str("and(pk(alice_key),pk(bob_key))").unwrap();

let real_policy = placeholder_policy.translate_pk(|placeholder: &String| match placeholder.as_str() {
    "alice_key" => PublicKey::from_str(alice_key),
    "bob_key"   => PublicKey::from_str(bob_key),
    _ => panic!("unknown key!")
}).unwrap();

let expected_policy = Policy::from_str(&format!("and(pk({}),pk({}))", alice_key, bob_key)).unwrap();
assert_eq!(real_policy, expected_policy);
Source

pub fn keys(&self) -> Vec<&Pk>

Get all keys in the policy

Source

pub fn check_duplicate_keys(&self) -> Result<(), PolicyError>

Check whether the policy contains duplicate public keys

Source

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.

Source

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

Source

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§

Source§

impl<Pk: Clone + MiniscriptKey> Clone for Policy<Pk>

Source§

fn clone(&self) -> Policy<Pk>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Pk: MiniscriptKey> Debug for Policy<Pk>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Pk: MiniscriptKey> Display for Policy<Pk>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Pk: MiniscriptKey> ForEachKey<Pk> for Policy<Pk>

Source§

fn for_each_key<'a, F: FnMut(ForEach<'a, Pk>) -> bool>( &'a self, pred: F, ) -> bool
where Pk: 'a, Pk::Hash: 'a,

Run a predicate on every key in the descriptor, returning whether the predicate returned true for every key
Source§

fn for_any_key<'a, F: FnMut(ForEach<'a, Pk>) -> bool>(&'a self, pred: F) -> bool
where Pk: 'a, Pk::Hash: 'a,

Run a predicate on every key in the descriptor, returning whether the predicate returned true for any key
Source§

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,

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Policy<Pk>, Error>

Parses a string s to return a value of this type. Read more
Source§

impl<Pk> FromTree for Policy<Pk>
where Pk: MiniscriptKey + FromStr, Pk::Hash: FromStr, <Pk as FromStr>::Err: ToString,

Source§

fn from_tree(top: &Tree<'_>) -> Result<Policy<Pk>, Error>

Extract a structure from Tree representation
Source§

impl<Pk: Hash + MiniscriptKey> Hash for Policy<Pk>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<Pk: MiniscriptKey> Liftable<Pk> for Concrete<Pk>

Source§

fn lift(&self) -> Result<Semantic<Pk>, Error>

Convert the object into an abstract policy
Source§

impl<Pk: Ord + MiniscriptKey> Ord for Policy<Pk>

Source§

fn cmp(&self, other: &Policy<Pk>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<Pk: PartialEq + MiniscriptKey> PartialEq for Policy<Pk>

Source§

fn eq(&self, other: &Policy<Pk>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Pk: PartialOrd + MiniscriptKey> PartialOrd for Policy<Pk>

Source§

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 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<Pk: Eq + MiniscriptKey> Eq for Policy<Pk>

Source§

impl<Pk: MiniscriptKey> StructuralPartialEq for Policy<Pk>

Auto Trait Implementations§

§

impl<Pk> Freeze for Policy<Pk>
where Pk: Freeze,

§

impl<Pk> RefUnwindSafe for Policy<Pk>
where Pk: RefUnwindSafe,

§

impl<Pk> Send for Policy<Pk>
where Pk: Send,

§

impl<Pk> Sync for Policy<Pk>
where Pk: Sync,

§

impl<Pk> Unpin for Policy<Pk>
where Pk: Unpin,

§

impl<Pk> UnwindSafe for Policy<Pk>
where Pk: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.