Executable

Trait Executable 

Source
pub trait Executable<T: Config>: Sized {
    // Required methods
    fn from_storage<S: State>(
        code_hash: H256,
        meter: &mut ResourceMeter<T, S>,
    ) -> Result<Self, DispatchError>;
    fn from_evm_init_code(
        code: Vec<u8>,
        owner: <T as Config>::AccountId,
    ) -> Result<Self, DispatchError>;
    fn execute<E: Ext<T = T>>(
        self,
        ext: &mut E,
        function: ExportedFunction,
        input_data: Vec<u8>,
    ) -> Result<ExecReturnValue, ExecError>;
    fn code_info(&self) -> &CodeInfo<T>;
    fn code(&self) -> &[u8] ;
    fn code_hash(&self) -> &H256;
}
Expand description

A trait that represents something that can be executed.

In the on-chain environment this would be represented by a vm binary module. This trait exists in order to be able to mock the vm logic for testing.

Required Methods§

Source

fn from_storage<S: State>( code_hash: H256, meter: &mut ResourceMeter<T, S>, ) -> Result<Self, DispatchError>

Load the executable from storage.

§Note

Charges size base load weight from the weight meter.

Source

fn from_evm_init_code( code: Vec<u8>, owner: <T as Config>::AccountId, ) -> Result<Self, DispatchError>

Load the executable from EVM bytecode

Source

fn execute<E: Ext<T = T>>( self, ext: &mut E, function: ExportedFunction, input_data: Vec<u8>, ) -> Result<ExecReturnValue, ExecError>

Execute the specified exported function and return the result.

When the specified function is Constructor the executable is stored and its refcount incremented.

§Note

This functions expects to be executed in a storage transaction that rolls back all of its emitted storage changes.

Source

fn code_info(&self) -> &CodeInfo<T>

The code info of the executable.

Source

fn code(&self) -> &[u8]

The raw code of the executable.

Source

fn code_hash(&self) -> &H256

The code hash of the executable.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§