EVMC
evmc::Host Class Reference

Abstract class to be used by Host implementations. More...

#include <evmc.hpp>

Inherits evmc::HostInterface.

Public Member Functions

evmc_host_contextto_context () noexcept
 Converts the Host object to the opaque host context pointer. More...
 
- Public Member Functions inherited from evmc::HostInterface
virtual bool account_exists (const address &addr) noexcept=0
 Check account existence callback function. More...
 
virtual bytes32 get_storage (const address &addr, const bytes32 &key) noexcept=0
 Get storage callback function. More...
 
virtual evmc_storage_status set_storage (const address &addr, const bytes32 &key, const bytes32 &value) noexcept=0
 Set storage callback function. More...
 
virtual uint256be get_balance (const address &addr) noexcept=0
 Get balance callback function. More...
 
virtual size_t get_code_size (const address &addr) noexcept=0
 Get code size callback function. More...
 
virtual bytes32 get_code_hash (const address &addr) noexcept=0
 Get code hash callback function. More...
 
virtual size_t copy_code (const address &addr, size_t code_offset, uint8_t *buffer_data, size_t buffer_size) noexcept=0
 Copy code callback function. More...
 
virtual void selfdestruct (const address &addr, const address &beneficiary) noexcept=0
 Selfdestruct callback function. More...
 
virtual result call (const evmc_message &msg) noexcept=0
 Call callback function. More...
 
virtual evmc_tx_context get_tx_context () noexcept=0
 Get transaction context callback function. More...
 
virtual bytes32 get_block_hash (int64_t block_number) noexcept=0
 Get block hash callback function. More...
 
virtual void emit_log (const address &addr, const uint8_t *data, size_t data_size, const bytes32 topics[], size_t num_topics) noexcept=0
 Emit log callback function. More...
 

Static Public Member Functions

static const evmc_host_interfaceget_interface () noexcept
 Provides access to the global host interface. More...
 
template<typename DerivedClass = Host>
static DerivedClass * from_context (evmc_host_context *context) noexcept
 Converts the opaque host context pointer back to the original Host object. More...
 

Detailed Description

Abstract class to be used by Host implementations.

When implementing EVMC Host, you can directly inherit from the evmc::Host class. This way your implementation will be simpler by avoiding manual handling of the evmc_host_context and the evmc_host_interface.

Definition at line 495 of file evmc.hpp.

Member Function Documentation

◆ from_context()

template<typename DerivedClass = Host>
static DerivedClass* evmc::Host::from_context ( evmc_host_context context)
inlinestaticnoexcept

Converts the opaque host context pointer back to the original Host object.

Template Parameters
DerivedClassThe class derived from the Host class.
Parameters
contextThe opaque host context pointer.
Returns
The pointer to DerivedClass.

Definition at line 511 of file evmc.hpp.

512  {
513  // Get pointer of the Host base class.
514  auto* h = reinterpret_cast<Host*>(context);
515 
516  // Additional downcast, only possible if DerivedClass inherits from Host.
517  return static_cast<DerivedClass*>(h);
518  }
Abstract class to be used by Host implementations.
Definition: evmc.hpp:495

◆ get_interface()

const evmc_host_interface & evmc::Host::get_interface ( )
inlinestaticnoexcept

Provides access to the global host interface.

Returns
Reference to the host interface object.

Definition at line 717 of file evmc.hpp.

718 {
719  static constexpr evmc_host_interface interface{
720  ::evmc::internal::account_exists, ::evmc::internal::get_storage,
721  ::evmc::internal::set_storage, ::evmc::internal::get_balance,
722  ::evmc::internal::get_code_size, ::evmc::internal::get_code_hash,
723  ::evmc::internal::copy_code, ::evmc::internal::selfdestruct,
724  ::evmc::internal::call, ::evmc::internal::get_tx_context,
725  ::evmc::internal::get_block_hash, ::evmc::internal::emit_log};
726  return interface;
727 }
The Host interface.
Definition: evmc.h:621

◆ to_context()

evmc_host_context* evmc::Host::to_context ( )
inlinenoexcept

Converts the Host object to the opaque host context pointer.

Returns
Pointer to evmc_host_context.

Definition at line 504 of file evmc.hpp.

504 { return reinterpret_cast<evmc_host_context*>(this); }
The opaque data type representing the Host execution context.

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