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
impl Engine
Sourcepub fn transfer(&mut self, account_id: &[u8], value: &[u8]) -> Result<(), Error>
pub fn transfer(&mut self, account_id: &[u8], value: &[u8]) -> Result<(), Error>
Transfers value from the contract to the destination account.
Sourcepub fn deposit_event(&mut self, topics: &[u8], data: &[u8])
pub fn deposit_event(&mut self, topics: &[u8], data: &[u8])
Deposits an event identified by the supplied topics and data.
Sourcepub fn set_storage(&mut self, key: &[u8], encoded_value: &[u8]) -> Option<u32>
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.
Sourcepub fn get_storage(&mut self, key: &[u8]) -> Result<&[u8], Error>
pub fn get_storage(&mut self, key: &[u8]) -> Result<&[u8], Error>
Returns the contract storage bytes at the key if any.
Sourcepub fn take_storage(&mut self, key: &[u8]) -> Result<Vec<u8>, Error>
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.
Sourcepub fn contains_storage(&mut self, key: &[u8]) -> Option<u32>
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.
Sourcepub fn clear_storage(&mut self, key: &[u8]) -> Option<u32>
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.
Sourcepub fn terminate(&mut self, beneficiary: &[u8]) -> !
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.
Sourcepub fn value_transferred(&self, output: &mut &mut [u8])
pub fn value_transferred(&self, output: &mut &mut [u8])
Returns the transferred value for the called contract.
Sourcepub fn debug_message(&mut self, message: &str)
pub fn debug_message(&mut self, message: &str)
Records the given debug message and appends to stdout.
Sourcepub fn hash_blake2_256(input: &[u8], output: &mut [u8; 32])
pub fn hash_blake2_256(input: &[u8], output: &mut [u8; 32])
Conduct the BLAKE-2 256-bit hash and place the result into output
.
Sourcepub fn hash_blake2_128(input: &[u8], output: &mut [u8; 16])
pub fn hash_blake2_128(input: &[u8], output: &mut [u8; 16])
Conduct the BLAKE-2 128-bit hash and place the result into output
.
Sourcepub fn hash_sha2_256(input: &[u8], output: &mut [u8; 32])
pub fn hash_sha2_256(input: &[u8], output: &mut [u8; 32])
Conduct the SHA-2 256-bit hash and place the result into output
.
Sourcepub fn hash_keccak_256(input: &[u8], output: &mut [u8; 32])
pub fn hash_keccak_256(input: &[u8], output: &mut [u8; 32])
Conduct the KECCAK 256-bit hash and place the result into output
.
Sourcepub fn block_number(&self, output: &mut &mut [u8])
pub fn block_number(&self, output: &mut &mut [u8])
Returns the current block number.
Sourcepub fn block_timestamp(&self, output: &mut &mut [u8])
pub fn block_timestamp(&self, output: &mut &mut [u8])
Returns the timestamp of the current block.
pub fn gas_left(&self, _output: &mut &mut [u8])
Sourcepub fn minimum_balance(&self, output: &mut &mut [u8])
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).
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>
pub fn call( &mut self, _callee: &[u8], _gas_limit: u64, _value: &[u8], _input: &[u8], _output: &mut &mut [u8], ) -> Result<(), Error>
Sourcepub fn weight_to_fee(&self, gas: u64, output: &mut &mut [u8])
pub fn weight_to_fee(&self, gas: u64, output: &mut &mut [u8])
Emulates gas price calculation.
Sourcepub fn call_chain_extension(
&mut self,
id: u32,
input: &[u8],
output: &mut &mut [u8],
)
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§impl Engine
impl Engine
Sourcepub fn initialize_or_reset(&mut self)
pub fn initialize_or_reset(&mut self)
Resets the environment.
Sourcepub fn get_contract_storage_rw(&self, account_id: Vec<u8>) -> (usize, usize)
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.
Sourcepub fn count_reads(&self) -> usize
pub fn count_reads(&self) -> usize
Returns the total number of reads executed.
Sourcepub fn count_writes(&self) -> usize
pub fn count_writes(&self) -> usize
Returns the total number of writes executed.
Sourcepub fn set_caller(&mut self, caller: Vec<u8>)
pub fn set_caller(&mut self, caller: Vec<u8>)
Sets a caller for the next call.
Sourcepub fn set_contract(&mut self, caller: Vec<u8>)
pub fn set_contract(&mut self, caller: Vec<u8>)
Sets a known contract by adding it to a vector of known contracts accounts
Sourcepub fn set_callee(&mut self, callee: Vec<u8>)
pub fn set_callee(&mut self, callee: Vec<u8>)
Sets the callee for the next call.
Sourcepub fn count_used_storage_cells(
&self,
account_id: &[u8],
) -> Result<usize, Error>
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.
Sourcepub fn advance_block(&mut self)
pub fn advance_block(&mut self)
Advances the chain by a single block.
Sourcepub fn get_callee(&self) -> Vec<u8> ⓘ
pub fn get_callee(&self) -> Vec<u8> ⓘ
Returns the callee, i.e. the currently executing contract.
Sourcepub fn is_contract(&self, account_id: Vec<u8>) -> bool
pub fn is_contract(&self, account_id: Vec<u8>) -> bool
Returns boolean value indicating whether the account is a contract
Sourcepub fn get_emitted_debug_messages(&self) -> RecordedDebugMessages
pub fn get_emitted_debug_messages(&self) -> RecordedDebugMessages
Returns the contents of the past performed environmental debug_message
in order.
Sourcepub fn get_emitted_events(&self) -> impl Iterator<Item = EmittedEvent>
pub fn get_emitted_events(&self) -> impl Iterator<Item = EmittedEvent>
Returns the recorded emitted events in order.
Sourcepub fn get_balance(&self, account_id: Vec<u8>) -> Result<u128, Error>
pub fn get_balance(&self, account_id: Vec<u8>) -> Result<u128, Error>
Returns the current balance of account_id
.
Sourcepub fn set_balance(&mut self, account_id: Vec<u8>, new_balance: u128)
pub fn set_balance(&mut self, account_id: Vec<u8>, new_balance: u128)
Sets the balance of account_id
to new_balance
.
Sourcepub fn set_value_transferred(&mut self, value: u128)
pub fn set_value_transferred(&mut self, value: u128)
Sets the value transferred from the caller to the callee as part of the call.
Sourcepub fn set_block_timestamp(&mut self, new_block_timestamp: u64)
pub fn set_block_timestamp(&mut self, new_block_timestamp: u64)
Set the block timestamp for the execution context.
Sourcepub fn set_block_number(&mut self, new_block_number: u32)
pub fn set_block_number(&mut self, new_block_number: u32)
Set the block number for the execution context.