EVMC
evmc::HostContext Class Reference

Wrapper around EVMC host context / host interface. More...

#include <evmc.hpp>

Inherits evmc::HostInterface.

Public Member Functions

 HostContext ()=default
 Default constructor for null Host context.
 
 HostContext (const evmc_host_interface &interface, evmc_host_context *ctx) noexcept
 Constructor from the EVMC Host primitives. More...
 
bool account_exists (const address &address) const noexcept final
 Check account existence callback function. More...
 
bytes32 get_storage (const address &address, const bytes32 &key) const noexcept final
 Get storage callback function. More...
 
evmc_storage_status set_storage (const address &address, const bytes32 &key, const bytes32 &value) noexcept final
 Set storage callback function. More...
 
uint256be get_balance (const address &address) const noexcept final
 Get balance callback function. More...
 
size_t get_code_size (const address &address) const noexcept final
 Get code size callback function. More...
 
bytes32 get_code_hash (const address &address) const noexcept final
 Get code hash callback function. More...
 
size_t copy_code (const address &address, size_t code_offset, uint8_t *buffer_data, size_t buffer_size) const noexcept final
 Copy code callback function. More...
 
void selfdestruct (const address &addr, const address &beneficiary) noexcept final
 Selfdestruct callback function. More...
 
result call (const evmc_message &message) noexcept final
 Call callback function. More...
 
evmc_tx_context get_tx_context () const noexcept final
 Get transaction context callback function. More...
 
bytes32 get_block_hash (int64_t number) const noexcept final
 Get block hash callback function. More...
 
void emit_log (const address &addr, const uint8_t *data, size_t data_size, const bytes32 topics[], size_t topics_count) noexcept final
 Emit log callback function. More...
 

Detailed Description

Wrapper around EVMC host context / host interface.

To be used by VM implementations as better alternative to using evmc_host_context directly.

Definition at line 459 of file evmc.hpp.

Constructor & Destructor Documentation

◆ HostContext()

evmc::HostContext::HostContext ( const evmc_host_interface interface,
evmc_host_context ctx 
)
inlinenoexcept

Constructor from the EVMC Host primitives.

Parameters
interfaceThe reference to the Host interface.
ctxThe pointer to the Host context object. This parameter MAY be null.

Definition at line 472 of file evmc.hpp.

473  : host{&interface}, context{ctx}
474  {}

Member Function Documentation

◆ account_exists()

bool evmc::HostContext::account_exists ( const address addr) const
inlinefinalvirtualnoexcept

Check account existence callback function.

Implements evmc::HostInterface.

Definition at line 476 of file evmc.hpp.

477  {
478  return host->account_exists(context, &address);
479  }
The big-endian 160-bit hash suitable for keeping an Ethereum address.
Definition: evmc.hpp:21
evmc_account_exists_fn account_exists
Check account existence callback function.
Definition: evmc.h:624

◆ call()

result evmc::HostContext::call ( const evmc_message msg)
inlinefinalvirtualnoexcept

Call callback function.

Implements evmc::HostInterface.

Definition at line 521 of file evmc.hpp.

522  {
523  return result{host->call(context, &message)};
524  }
The EVM code execution result.
Definition: evmc.hpp:331
evmc_call_fn call
Call callback function.
Definition: evmc.h:648

◆ copy_code()

size_t evmc::HostContext::copy_code ( const address addr,
size_t  code_offset,
uint8_t *  buffer_data,
size_t  buffer_size 
) const
inlinefinalvirtualnoexcept

Copy code callback function.

Implements evmc::HostInterface.

Definition at line 508 of file evmc.hpp.

512  {
513  return host->copy_code(context, &address, code_offset, buffer_data, buffer_size);
514  }
evmc_copy_code_fn copy_code
Copy code callback function.
Definition: evmc.h:642
The big-endian 160-bit hash suitable for keeping an Ethereum address.
Definition: evmc.hpp:21

◆ emit_log()

void evmc::HostContext::emit_log ( const address addr,
const uint8_t *  data,
size_t  data_size,
const bytes32  topics[],
size_t  num_topics 
)
inlinefinalvirtualnoexcept

Emit log callback function.

Implements evmc::HostInterface.

Definition at line 544 of file evmc.hpp.

549  {
550  host->emit_log(context, &addr, data, data_size, topics, topics_count);
551  }
evmc_emit_log_fn emit_log
Emit log callback function.
Definition: evmc.h:657

◆ get_balance()

uint256be evmc::HostContext::get_balance ( const address addr) const
inlinefinalvirtualnoexcept

Get balance callback function.

Implements evmc::HostInterface.

Definition at line 493 of file evmc.hpp.

494  {
495  return host->get_balance(context, &address);
496  }
evmc_get_balance_fn get_balance
Get balance callback function.
Definition: evmc.h:633
The big-endian 160-bit hash suitable for keeping an Ethereum address.
Definition: evmc.hpp:21

◆ get_block_hash()

bytes32 evmc::HostContext::get_block_hash ( int64_t  block_number) const
inlinefinalvirtualnoexcept

Get block hash callback function.

Implements evmc::HostInterface.

Definition at line 539 of file evmc.hpp.

540  {
541  return host->get_block_hash(context, number);
542  }
evmc_get_block_hash_fn get_block_hash
Get block hash callback function.
Definition: evmc.h:654

◆ get_code_hash()

bytes32 evmc::HostContext::get_code_hash ( const address addr) const
inlinefinalvirtualnoexcept

Get code hash callback function.

Implements evmc::HostInterface.

Definition at line 503 of file evmc.hpp.

504  {
505  return host->get_code_hash(context, &address);
506  }
The big-endian 160-bit hash suitable for keeping an Ethereum address.
Definition: evmc.hpp:21
evmc_get_code_hash_fn get_code_hash
Get code hash callback function.
Definition: evmc.h:639

◆ get_code_size()

size_t evmc::HostContext::get_code_size ( const address addr) const
inlinefinalvirtualnoexcept

Get code size callback function.

Implements evmc::HostInterface.

Definition at line 498 of file evmc.hpp.

499  {
500  return host->get_code_size(context, &address);
501  }
evmc_get_code_size_fn get_code_size
Get code size callback function.
Definition: evmc.h:636
The big-endian 160-bit hash suitable for keeping an Ethereum address.
Definition: evmc.hpp:21

◆ get_storage()

bytes32 evmc::HostContext::get_storage ( const address addr,
const bytes32 key 
) const
inlinefinalvirtualnoexcept

Get storage callback function.

Implements evmc::HostInterface.

Definition at line 481 of file evmc.hpp.

482  {
483  return host->get_storage(context, &address, &key);
484  }
evmc_get_storage_fn get_storage
Get storage callback function.
Definition: evmc.h:627
The big-endian 160-bit hash suitable for keeping an Ethereum address.
Definition: evmc.hpp:21

◆ get_tx_context()

evmc_tx_context evmc::HostContext::get_tx_context ( ) const
inlinefinalvirtualnoexcept

Get transaction context callback function.

The implementation caches the received transaction context by assuming that the block timestamp should never be zero.

Returns
The cached transaction context.

Implements evmc::HostInterface.

Definition at line 532 of file evmc.hpp.

533  {
534  if (tx_context.block_timestamp == 0)
535  tx_context = host->get_tx_context(context);
536  return tx_context;
537  }
evmc_get_tx_context_fn get_tx_context
Get transaction context callback function.
Definition: evmc.h:651
int64_t block_timestamp
The block timestamp.
Definition: evmc.h:153

◆ selfdestruct()

void evmc::HostContext::selfdestruct ( const address addr,
const address beneficiary 
)
inlinefinalvirtualnoexcept

Selfdestruct callback function.

Implements evmc::HostInterface.

Definition at line 516 of file evmc.hpp.

517  {
518  host->selfdestruct(context, &addr, &beneficiary);
519  }
evmc_selfdestruct_fn selfdestruct
Selfdestruct callback function.
Definition: evmc.h:645

◆ set_storage()

evmc_storage_status evmc::HostContext::set_storage ( const address addr,
const bytes32 key,
const bytes32 value 
)
inlinefinalvirtualnoexcept

Set storage callback function.

Implements evmc::HostInterface.

Definition at line 486 of file evmc.hpp.

489  {
490  return host->set_storage(context, &address, &key, &value);
491  }
evmc_set_storage_fn set_storage
Set storage callback function.
Definition: evmc.h:630
The big-endian 160-bit hash suitable for keeping an Ethereum address.
Definition: evmc.hpp:21

The documentation for this class was generated from the following file: