@@ -76,4 +76,92 @@ class vm
7676private:
7777 evmc_instance* const m_instance = nullptr ;
7878};
79+
80+
81+ // / Wrapper around EVMC host context / host interface.
82+ class host
83+ {
84+ evmc_context* context = nullptr ;
85+ evmc_tx_context tx_context = {};
86+
87+ public:
88+ host (evmc_context* context) noexcept : context{context} {}
89+
90+ bool account_exists (const evmc_address& address) noexcept
91+ {
92+ return context->host ->account_exists (context, &address);
93+ }
94+
95+ evmc_bytes32 get_storage (const evmc_address& address, const evmc_bytes32& key) noexcept
96+ {
97+ return context->host ->get_storage (context, &address, &key);
98+ }
99+
100+ evmc_storage_status set_storage (const evmc_address& address,
101+ const evmc_bytes32& key,
102+ const evmc_bytes32& value) noexcept
103+ {
104+ return context->host ->set_storage (context, &address, &key, &value);
105+ }
106+
107+ evmc_uint256be get_balance (const evmc_address& address) noexcept
108+ {
109+ return context->host ->get_balance (context, &address);
110+ }
111+
112+ size_t get_code_size (const evmc_address& address) noexcept
113+ {
114+ return context->host ->get_code_size (context, &address);
115+ }
116+
117+ evmc_bytes32 get_code_hash (const evmc_address& address) noexcept
118+ {
119+ return context->host ->get_code_hash (context, &address);
120+ }
121+
122+ size_t copy_code (const evmc_address& address,
123+ size_t code_offset,
124+ uint8_t * buffer_data,
125+ size_t buffer_size) noexcept
126+ {
127+ return context->host ->copy_code (context, &address, code_offset, buffer_data, buffer_size);
128+ }
129+
130+ void selfdestruct (const evmc_address& address, const evmc_address& beneficiary)
131+ {
132+ context->host ->selfdestruct (context, &address, &beneficiary);
133+ }
134+
135+ result call (const evmc_message& message) noexcept
136+ {
137+ return result{context->host ->call (context, &message)};
138+ }
139+
140+ // / Gets the transaction and block context from the Host.
141+ // /
142+ // / The implementation caches the received transaction context
143+ // / by assuming that the block timestamp should never be zero.
144+ // /
145+ // / @return Reference to the cached transaction context.
146+ const evmc_tx_context& get_tx_context () noexcept
147+ {
148+ if (tx_context.block_timestamp == 0 )
149+ tx_context = context->host ->get_tx_context (context);
150+ return tx_context;
151+ }
152+
153+ evmc_bytes32 get_block_hash (int64_t number) noexcept
154+ {
155+ return context->host ->get_block_hash (context, number);
156+ }
157+
158+ void emit_log (const evmc_address& address,
159+ const uint8_t * data,
160+ size_t data_size,
161+ const evmc_bytes32 topics[],
162+ size_t topics_count) noexcept
163+ {
164+ context->host ->emit_log (context, &address, data, data_size, topics, topics_count);
165+ }
166+ };
79167} // namespace evmc
0 commit comments