Engine

Struct Engine 

Source
pub struct Engine {
    pub database: Database,
    pub exec_context: ExecContext,
    pub chain_spec: ChainSpec,
    pub chain_extension_handler: ChainExtensionHandler,
    /* private fields */
}
Expand description

The off-chain engine.

Fields§

§database: Database

The environment database.

§exec_context: ExecContext

The current execution context.

§chain_spec: ChainSpec

The chain specification.

§chain_extension_handler: ChainExtensionHandler

Handler for registered chain extensions.

Implementations§

Source§

impl Engine

Source

pub fn new() -> Self

Source§

impl Engine

Source

pub fn transfer(&mut self, account_id: &[u8], value: &[u8]) -> Result<(), Error>

Transfers value from the contract to the destination account.

Source

pub fn deposit_event(&mut self, topics: &[u8], data: &[u8])

Deposits an event identified by the supplied topics and data.

Source

pub fn set_storage(&mut self, key: &[u8], encoded_value: &[u8]) -> Option<u32>

Writes the encoded value into the storage at the given key. Returns the size of the previously stored value at the key if any.

Source

pub fn get_storage(&mut self, key: &[u8]) -> Result<&[u8], Error>

Returns the contract storage bytes at the key if any.

Source

pub fn take_storage(&mut self, key: &[u8]) -> Result<Vec<u8>, Error>

Removes the storage entries at the given key, returning previously stored value at the key if any.

Source

pub fn contains_storage(&mut self, key: &[u8]) -> Option<u32>

Returns the size of the value stored in the contract storage at the key if any.

Source

pub fn clear_storage(&mut self, key: &[u8]) -> Option<u32>

Removes the storage entries at the given key. Returns the size of the previously stored value at the key if any.

Source

pub fn terminate(&mut self, beneficiary: &[u8]) -> !

Remove the calling account and transfer remaining balance.

This function never returns. Either the termination was successful and the execution of the destroyed contract is halted. Or it failed during the termination which is considered fatal.

Source

pub fn caller(&self, output: &mut &mut [u8])

Returns the address of the caller.

Source

pub fn balance(&self, output: &mut &mut [u8])

Returns the balance of the executed contract.

Source

pub fn value_transferred(&self, output: &mut &mut [u8])

Returns the transferred value for the called contract.

Source

pub fn address(&self, output: &mut &mut [u8])

Returns the address of the executed contract.

Source

pub fn debug_message(&mut self, message: &str)

Records the given debug message and appends to stdout.

Source

pub fn hash_blake2_256(input: &[u8], output: &mut [u8; 32])

Conduct the BLAKE-2 256-bit hash and place the result into output.

Source

pub fn hash_blake2_128(input: &[u8], output: &mut [u8; 16])

Conduct the BLAKE-2 128-bit hash and place the result into output.

Source

pub fn hash_sha2_256(input: &[u8], output: &mut [u8; 32])

Conduct the SHA-2 256-bit hash and place the result into output.

Source

pub fn hash_keccak_256(input: &[u8], output: &mut [u8; 32])

Conduct the KECCAK 256-bit hash and place the result into output.

Source

pub fn block_number(&self, output: &mut &mut [u8])

Returns the current block number.

Source

pub fn block_timestamp(&self, output: &mut &mut [u8])

Returns the timestamp of the current block.

Source

pub fn gas_left(&self, _output: &mut &mut [u8])

Source

pub fn minimum_balance(&self, output: &mut &mut [u8])

Returns the minimum balance that is required for creating an account (i.e. the chain’s existential deposit).

Source

pub fn instantiate( &mut self, _code_hash: &[u8], _gas_limit: u64, _endowment: &[u8], _input: &[u8], _out_address: &mut &mut [u8], _out_return_value: &mut &mut [u8], _salt: &[u8], ) -> Result<(), Error>

Source

pub fn call( &mut self, _callee: &[u8], _gas_limit: u64, _value: &[u8], _input: &[u8], _output: &mut &mut [u8], ) -> Result<(), Error>

Source

pub fn weight_to_fee(&self, gas: u64, output: &mut &mut [u8])

Emulates gas price calculation.

Source

pub fn call_chain_extension( &mut self, id: u32, input: &[u8], output: &mut &mut [u8], )

Calls the chain extension method registered at func_id with input.

Source

pub fn ecdsa_recover( &mut self, signature: &[u8; 65], message_hash: &[u8; 32], output: &mut [u8; 33], ) -> Result<(), Error>

Recovers the compressed ECDSA public key for given signature and message_hash, and stores the result in output.

Source§

impl Engine

Source

pub fn initialize_or_reset(&mut self)

Resets the environment.

Source

pub fn get_contract_storage_rw(&self, account_id: Vec<u8>) -> (usize, usize)

Returns the total number of reads and writes of the contract’s storage.

Source

pub fn count_reads(&self) -> usize

Returns the total number of reads executed.

Source

pub fn count_writes(&self) -> usize

Returns the total number of writes executed.

Source

pub fn set_caller(&mut self, caller: Vec<u8>)

Sets a caller for the next call.

Source

pub fn set_contract(&mut self, caller: Vec<u8>)

Sets a known contract by adding it to a vector of known contracts accounts

Source

pub fn set_callee(&mut self, callee: Vec<u8>)

Sets the callee for the next call.

Source

pub fn count_used_storage_cells( &self, account_id: &[u8], ) -> Result<usize, Error>

Returns the amount of storage cells used by the account account_id.

Returns None if the account_id is non-existent.

Source

pub fn advance_block(&mut self)

Advances the chain by a single block.

Source

pub fn get_callee(&self) -> Vec<u8>

Returns the callee, i.e. the currently executing contract.

Source

pub fn is_contract(&self, account_id: Vec<u8>) -> bool

Returns boolean value indicating whether the account is a contract

Source

pub fn get_emitted_debug_messages(&self) -> RecordedDebugMessages

Returns the contents of the past performed environmental debug_message in order.

Source

pub fn get_emitted_events(&self) -> impl Iterator<Item = EmittedEvent>

Returns the recorded emitted events in order.

Source

pub fn get_balance(&self, account_id: Vec<u8>) -> Result<u128, Error>

Returns the current balance of account_id.

Source

pub fn set_balance(&mut self, account_id: Vec<u8>, new_balance: u128)

Sets the balance of account_id to new_balance.

Source

pub fn set_value_transferred(&mut self, value: u128)

Sets the value transferred from the caller to the callee as part of the call.

Source

pub fn set_block_timestamp(&mut self, new_block_timestamp: u64)

Set the block timestamp for the execution context.

Source

pub fn set_block_number(&mut self, new_block_number: u32)

Set the block number for the execution context.

Trait Implementations§

Source§

impl Default for Engine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Engine

§

impl !RefUnwindSafe for Engine

§

impl !Send for Engine

§

impl !Sync for Engine

§

impl Unpin for Engine

§

impl !UnwindSafe for Engine

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

Source§

type Output = T

Should always be Self
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.