pub struct Program { /* private fields */ }Expand description
Represents a program structure containing its public key, compiled program, and associated storage. A compiled program acts as a cache, instantiated during “loading”.
Abstraction giving the power to execute Simplicity contracts without specifying any additional parameters.
Implementations§
Source§impl Program
impl Program
Sourcepub const STORAGE_SLOT_BYTES: usize = 32
pub const STORAGE_SLOT_BYTES: usize = 32
The width of a storage slot.
Sourcepub fn new(
source: impl Into<Arc<str>>,
arguments: &dyn ArgumentsTrait,
) -> Program
pub fn new( source: impl Into<Arc<str>>, arguments: &dyn ArgumentsTrait, ) -> Program
Creates a new instance of the struct with the provided source string and arguments.
Sourcepub fn with_taproot_pubkey(self, pub_key: XOnlyPublicKey) -> Program
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.
Sourcepub fn with_debug_symbols(self, include: bool) -> Program
pub fn with_debug_symbols(self, include: bool) -> Program
Builds this program in the mode the protocol declares.
Sourcepub fn with_storage_capacity(self, capacity: usize) -> Program
pub fn with_storage_capacity(self, capacity: usize) -> Program
Sets storage capacity for further usage.
Sourcepub fn set_storage_at(&mut self, index: usize, new_value: impl Into<Vec<u8>>)
pub fn set_storage_at(&mut self, index: usize, new_value: impl Into<Vec<u8>>)
Sets a 32-byte value at the specified index in the storage.
§Panics
Panics if the index is out of bounds for the initialized storage, or if the value is not
STORAGE_SLOT_BYTES wide.
Sourcepub fn get_storage_len(&self) -> usize
pub fn get_storage_len(&self) -> usize
Returns the number of storage chunks for a program.
Sourcepub fn get_storage(&self) -> &[Vec<u8>]
pub fn get_storage(&self) -> &[Vec<u8>]
Returns storage as a whole array of 32-byte chunks.
Sourcepub fn get_storage_at(&self, index: usize) -> Vec<u8> ⓘ
pub fn get_storage_at(&self, index: usize) -> Vec<u8> ⓘ
Returns storage value at a certain index.
§Panics
Panics if the index is out of bounds for the initiated storage.
Sourcepub fn get_tr_address(&self, network: &SimplicityNetwork) -> Address
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.
Sourcepub fn get_script_pubkey(&self, network: &SimplicityNetwork) -> Script
pub fn get_script_pubkey(&self, network: &SimplicityNetwork) -> Script
Retrieves the ScriptPubKey associated with the Simplicity address for the specified network.
Sourcepub fn get_script_hash(&self, network: &SimplicityNetwork) -> [u8; 32]
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.
Sourcepub fn get_cmr(&self) -> [u8; 32]
pub fn get_cmr(&self) -> [u8; 32]
Compiles the program and returns its Commitment Merkle Root.
§Panics
Panics if the SimplicityHL compilation fails.
Sourcepub fn get_tapleaf_hash(&self) -> [u8; 32]
pub fn get_tapleaf_hash(&self) -> [u8; 32]
Returns the 32-byte tapleaf hash of the program’s Simplicity script.
§Panics
Panics if the SimplicityHL compilation fails.
Sourcepub fn get_argument_types(&self) -> Result<Parameters, ProgramError>
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.
Sourcepub fn get_witness_types(&self) -> Result<WitnessTypes, ProgramError>
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 ProgramTrait for Program
impl ProgramTrait for Program
Source§fn get_argument_types(&self) -> Result<Parameters, ProgramError>
fn get_argument_types(&self) -> Result<Parameters, ProgramError>
simplicity program. Read moreSource§fn get_witness_types(&self) -> Result<WitnessTypes, ProgramError>
fn get_witness_types(&self) -> Result<WitnessTypes, ProgramError>
simplicity program. Read moreSource§fn get_env(
&self,
pst: &PartiallySignedTransaction,
input_index: usize,
network: &SimplicityNetwork,
) -> Result<ElementsEnv<Arc<Transaction>>, ProgramError>
fn get_env( &self, pst: &PartiallySignedTransaction, input_index: usize, network: &SimplicityNetwork, ) -> Result<ElementsEnv<Arc<Transaction>>, ProgramError>
Source§fn execute(
&self,
pst: &PartiallySignedTransaction,
witness: &WitnessValues,
input_index: usize,
network: &SimplicityNetwork,
) -> Result<(Arc<Node<Redeem>>, Value), ProgramError>
fn execute( &self, pst: &PartiallySignedTransaction, witness: &WitnessValues, input_index: usize, network: &SimplicityNetwork, ) -> Result<(Arc<Node<Redeem>>, Value), ProgramError>
Source§fn finalize(
&self,
pst: &PartiallySignedTransaction,
witness: &WitnessValues,
input_index: usize,
network: &SimplicityNetwork,
) -> Result<Vec<Vec<u8>>, ProgramError>
fn finalize( &self, pst: &PartiallySignedTransaction, witness: &WitnessValues, input_index: usize, network: &SimplicityNetwork, ) -> Result<Vec<Vec<u8>>, ProgramError>
pruned_witness as output after executing the program on certain parameters. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for Program
impl !UnwindSafe for Program
impl Freeze for Program
impl Send for Program
impl Sync for Program
impl Unpin for Program
impl UnsafeUnpin for Program
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreimpl<T> OrderedSeq<'_, T> for Twhere
T: Clone,
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);