Skip to main content

Program

Struct Program 

Source
pub struct Program { /* private fields */ }
Expand description

Represents a program structure containing its source, a public key, arguments, and associated storage.

Abstraction giving the power to execute Simplicity contracts without specifying any additional parameters.

Implementations§

Source§

impl Program

Source

pub fn new(source: &'static str, arguments: Box<dyn ArgumentsTrait>) -> Program

Creates a new instance of the struct with the provided source string and arguments.

Source

pub fn with_taproot_pubkey(self, pub_key: XOnlyPublicKey) -> Program

Sets the pub_key field of the struct to the provided XOnlyPublicKey value and returns the updated builder instance. This is used to set the taproot public key for the program.

Source

pub fn with_storage_capacity(self, capacity: usize) -> Program

Sets storage capacity for further usage.

Source

pub fn set_storage_at(&mut self, index: usize, new_value: [u8; 32])

Sets a 32-byte value at the specified index in the storage.

§Panics

Panics if the index is out of bounds for the initiasized storage.

Source

pub fn get_storage_len(&self) -> usize

Returns the number of storage chunks for a program.

Source

pub fn get_storage(&self) -> &[[u8; 32]]

Returns storage as a whole array of 32-byte chunks.

Source

pub fn get_storage_at(&self, index: usize) -> [u8; 32]

Returns storage value at a certain index.

§Panics

Panics if the index is out of bounds for the initiated storage.

Source

pub fn get_tr_address(&self, network: &SimplicityNetwork) -> Address

Returns a taproot address for a defined SimplicityNetwork.

§Panics

Panics if generating the taproot spending information fails.

Source

pub fn get_script_pubkey(&self, network: &SimplicityNetwork) -> Script

Retrieves the ScriptPubKey associated with the Simplicity address for the specified network.

Source

pub fn get_script_hash(&self, network: &SimplicityNetwork) -> [u8; 32]

Retrieves the 32-byte ScriptPubKey hash associated with the Simplicity address for the specified network.

Source

pub fn get_argument_types(&self) -> Result<Parameters, ProgramError>

Retrieves program ABI metadata for argument types.

§Errors

Returns a ProgramError if compilation fails or generating ABI metadata fails.

Source

pub fn get_witness_types(&self) -> Result<WitnessTypes, ProgramError>

Retrieves the witness types from the compiled program’s ABI metadata.

§Errors

Returns a ProgramError if compilation fails or generating ABI metadata fails.

Trait Implementations§

Source§

impl Clone for Program

Source§

fn clone(&self) -> Program

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl ProgramTrait for Program

Source§

fn get_argument_types(&self) -> Result<Parameters, ProgramError>

Retrieves the types of arguments required by a simplicity program. Read more
Source§

fn get_witness_types(&self) -> Result<WitnessTypes, ProgramError>

Retrieves the witness types required by a simplicity program. Read more
Source§

fn get_env( &self, pst: &PartiallySignedTransaction, input_index: usize, network: &SimplicityNetwork, ) -> Result<ElementsEnv<Arc<Transaction>>, ProgramError>

Constructs the Elements environment for a specified input index, PST, and network for further program execution. Read more
Source§

fn execute( &self, pst: &PartiallySignedTransaction, witness: &WitnessValues, input_index: usize, network: &SimplicityNetwork, ) -> Result<(Arc<Node<Redeem<Elements>>>, Value), ProgramError>

Executes a Simplicity program for the given input index of a partially signed transaction. Read more
Source§

fn finalize( &self, pst: &PartiallySignedTransaction, witness: &WitnessValues, input_index: usize, network: &SimplicityNetwork, ) -> Result<Vec<Vec<u8>>, ProgramError>

Finalizes and returns pruned_witness as output after executing the program on certain parameters. Read more

Auto Trait Implementations§

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<'p, T> Seq<'p, T> for T
where T: Clone,

Source§

type Item<'a> = &'a T where T: 'a

The item yielded by the iterator.
Source§

type Iter<'a> = Once<&'a T> where T: 'a

An iterator over the items within this container, by reference.
Source§

fn seq_iter(&self) -> <T as Seq<'p, T>>::Iter<'_>

Iterate over the elements of the container.
Source§

fn contains(&self, val: &T) -> bool
where T: PartialEq,

Check whether an item is contained within this sequence.
Source§

fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>
where 'p: 'b,

Convert an item of the sequence into a MaybeRef.
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, 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

Source§

impl<T> OrderedSeq<'_, T> for T
where T: Clone,