Enum Policy

Source
pub enum Policy<Pk: SimplicityKey> {
    Unsatisfiable(FailEntropy),
    Trivial,
    Key(Pk),
    After(u32),
    Older(u16),
    Sha256(Pk::Sha256),
    And {
        left: Arc<Policy<Pk>>,
        right: Arc<Policy<Pk>>,
    },
    Or {
        left: Arc<Policy<Pk>>,
        right: Arc<Policy<Pk>>,
    },
    Threshold(usize, Vec<Policy<Pk>>),
    Assembly(Cmr),
}
Expand description

Policy that expresses spending conditions for Simplicity.

The policy can be compiled into a Simplicity program and executed on the Bit Machine, given a witness.

Furthermore, the policy can be normalized and is amenable to semantic analysis.

Variants§

§

Unsatisfiable(FailEntropy)

Unsatisfiable

§

Trivial

Trivially satisfiable

§

Key(Pk)

Provide a signature that matches the given public key and some given message hash

§

After(u32)

Absolute timelock

§

Older(u16)

Relative timelock

§

Sha256(Pk::Sha256)

Provide the preimage of the given SHA256 hash image

§

And

Satisfy both of the given sub-policies

Fields

§left: Arc<Policy<Pk>>
§right: Arc<Policy<Pk>>
§

Or

Satisfy exactly one of the given sub-policies

Fields

§left: Arc<Policy<Pk>>
§right: Arc<Policy<Pk>>
§

Threshold(usize, Vec<Policy<Pk>>)

Satisfy exactly k of the given sub-policies

§

Assembly(Cmr)

Satisfy the program with the given CMR

Implementations§

Source§

impl<Pk: ToXOnlyPubkey> Policy<Pk>

Source

pub fn commit(&self) -> Option<Arc<CommitNode<Elements>>>

Return the program commitment of the policy.

Source

pub fn cmr(&self) -> Cmr

Return the CMR of the policy.

Source§

impl<Pk: SimplicityKey> Policy<Pk>

Source

pub fn translate<T, Q, E>(&self, translator: &mut T) -> Result<Policy<Q>, E>
where T: Translator<Pk, Q, E>, Q: SimplicityKey,

Convert a policy using one kind of public key to another type of public key

Source

pub fn normalized(self) -> Policy<Pk>

Flatten out trees of Ands and Ors; eliminate Trivial and Unsatisfiables. Does not reorder any branches; use .sort.

Source

pub fn sorted(self) -> Policy<Pk>

“Sort” a policy to bring it into a canonical form to allow comparisons. Does not allow policies to be compared for functional equivalence; in general this appears to require Gröbner basis techniques that are not implemented.

Source

pub fn iter(&self) -> PolicyIter<'_, Pk>

Return an iterator over the fragments of the policy.

Source

pub fn iter_pk(&self) -> impl Iterator<Item = Pk> + '_

Return an iterator over the public keys of the policy.

Source§

impl<Pk: ToXOnlyPubkey> Policy<Pk>

Source

pub fn satisfy<S: Satisfier<Pk>>( &self, satisfier: &S, env: &ElementsEnv<Arc<Transaction>>, ) -> Result<Arc<RedeemNode<Elements>>, SatisfierError>

Return the policy program with satisfying witness data.

The program is run on the Bit Machine for pruning, so the transaction environment needs to be provided.

Trait Implementations§

Source§

impl<Pk: Clone + SimplicityKey> Clone for Policy<Pk>
where Pk::Sha256: Clone,

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: SimplicityKey> Debug for Policy<Pk>

Source§

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

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

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

Source§

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

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

impl<Pk: Hash + SimplicityKey> Hash for Policy<Pk>
where Pk::Sha256: Hash,

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: Ord + SimplicityKey> Ord for Policy<Pk>
where Pk::Sha256: Ord,

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 + SimplicityKey> PartialEq for Policy<Pk>
where Pk::Sha256: PartialEq,

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 + SimplicityKey> PartialOrd for Policy<Pk>
where Pk::Sha256: PartialOrd,

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 + SimplicityKey> Eq for Policy<Pk>
where Pk::Sha256: Eq,

Source§

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

Auto Trait Implementations§

§

impl<Pk> Freeze for Policy<Pk>
where Pk: Freeze, <Pk as SimplicityKey>::Sha256: Freeze,

§

impl<Pk> RefUnwindSafe for Policy<Pk>

§

impl<Pk> Send for Policy<Pk>
where Pk: Send + Sync, <Pk as SimplicityKey>::Sha256: Send + Sync,

§

impl<Pk> Sync for Policy<Pk>
where Pk: Sync + Send, <Pk as SimplicityKey>::Sha256: Sync + Send,

§

impl<Pk> Unpin for Policy<Pk>
where Pk: Unpin, <Pk as SimplicityKey>::Sha256: Unpin,

§

impl<Pk> UnwindSafe for Policy<Pk>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V