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§
Sourcefn from_storage<S: State>(
code_hash: H256,
meter: &mut ResourceMeter<T, S>,
) -> Result<Self, DispatchError>
fn from_storage<S: State>( code_hash: H256, meter: &mut ResourceMeter<T, S>, ) -> Result<Self, DispatchError>
Sourcefn from_evm_init_code(
code: Vec<u8>,
owner: <T as Config>::AccountId,
) -> Result<Self, DispatchError>
fn from_evm_init_code( code: Vec<u8>, owner: <T as Config>::AccountId, ) -> Result<Self, DispatchError>
Load the executable from EVM bytecode
Sourcefn execute<E: Ext<T = T>>(
self,
ext: &mut E,
function: ExportedFunction,
input_data: Vec<u8>,
) -> Result<ExecReturnValue, ExecError>
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.
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.