Skip to main content

ProgramTrait

Trait ProgramTrait 

Source
pub trait ProgramTrait: DynClone {
    // Required methods
    fn get_argument_types(&self) -> Result<Parameters, ProgramError>;
    fn get_witness_types(&self) -> Result<WitnessTypes, ProgramError>;
    fn get_env(
        &self,
        pst: &PartiallySignedTransaction,
        input_index: usize,
        network: &SimplicityNetwork,
    ) -> Result<ElementsEnv<Arc<Transaction>>, ProgramError>;
    fn execute(
        &self,
        pst: &PartiallySignedTransaction,
        witness: &WitnessValues,
        input_index: usize,
        network: &SimplicityNetwork,
    ) -> Result<(Arc<Node<Redeem<Elements>>>, Value), ProgramError>;
    fn finalize(
        &self,
        pst: &PartiallySignedTransaction,
        witness: &WitnessValues,
        input_index: usize,
        network: &SimplicityNetwork,
    ) -> Result<Vec<Vec<u8>>, ProgramError>;
}
Expand description

Executes simplicity programs at runtime.

This trait defines a core behavior related to testing and execution.

Required Methods§

Source

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

Retrieves the types of arguments required by a simplicity program.

§Errors

Returns a ProgramError if parsing or generating ABI metadata fails.

Source

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

Retrieves the witness types required by a simplicity program.

§Errors

Returns a ProgramError if parsing or generating ABI metadata fails.

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.

§Errors

Returns a ProgramError if the input index is out of bounds or if the script pubkey of the UTXO mismatches the expected program script.

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.

This function evaluates a Simplicity script associated with a specific transaction input in a given network, producing the result of the computation along with the redeem node used during execution.

§Errors

Returns a ProgramError if loading the program, satisfying the witness, retrieving the environment, or executing the BitMachine fails.

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.

§Errors

Returns a ProgramError if program execution or constructing the control block fails.

Implementors§