diff --git a/examples/example.c b/examples/example.c index 37516ab..36cbf3b 100644 --- a/examples/example.c +++ b/examples/example.c @@ -43,7 +43,9 @@ int main(int argc, char* argv[]) const evmc_uint256be value = {{1, 0}}; const evmc_address addr = {{0, 1, 2}}; const int64_t gas = 200000; - struct evmc_context* ctx = example_host_create_context(); + struct evmc_tx_context tx_context; + memset(&tx_context, 0, sizeof(tx_context)); + struct evmc_context* ctx = example_host_create_context(tx_context); struct evmc_message msg; msg.sender = addr; msg.destination = addr; diff --git a/examples/example_host.cpp b/examples/example_host.cpp index dc4d49e..4744bc6 100644 --- a/examples/example_host.cpp +++ b/examples/example_host.cpp @@ -25,8 +25,12 @@ struct account class ExampleHost : public evmc::Host { std::map accounts; + evmc_tx_context tx_context{}; public: + ExampleHost() = default; + explicit ExampleHost(evmc_tx_context& _tx_context) noexcept : tx_context{_tx_context} {}; + bool account_exists(const evmc::address& addr) noexcept final { return accounts.find(addr) != accounts.end(); @@ -98,7 +102,7 @@ public: return {EVMC_REVERT, msg.gas, msg.input_data, msg.input_size}; } - evmc_tx_context get_tx_context() noexcept final { return {}; } + evmc_tx_context get_tx_context() noexcept final { return tx_context; } evmc::bytes32 get_block_hash(int64_t number) noexcept final { @@ -126,9 +130,9 @@ public: extern "C" { -evmc_context* example_host_create_context() +evmc_context* example_host_create_context(evmc_tx_context tx_context) { - return new ExampleHost; + return new ExampleHost(tx_context); } void example_host_destroy_context(evmc_context* context) diff --git a/examples/example_host.h b/examples/example_host.h index 7497be8..1a15e66 100644 --- a/examples/example_host.h +++ b/examples/example_host.h @@ -9,7 +9,7 @@ extern "C" { #endif -struct evmc_context* example_host_create_context(); +struct evmc_context* example_host_create_context(struct evmc_tx_context tx_context); void example_host_destroy_context(struct evmc_context* context); diff --git a/test/unittests/test_cpp.cpp b/test/unittests/test_cpp.cpp index 731be12..64d24ac 100644 --- a/test/unittests/test_cpp.cpp +++ b/test/unittests/test_cpp.cpp @@ -346,7 +346,7 @@ TEST(cpp, host) { // Use example host to execute all methods from the C++ host wrapper. - auto* host_context = example_host_create_context(); + auto* host_context = example_host_create_context(evmc_tx_context{}); auto host = evmc::HostContext{host_context}; const auto a = evmc::address{{{1}}}; @@ -380,7 +380,7 @@ TEST(cpp, host_call) { // Use example host to test Host::call() method. - auto* host_context = example_host_create_context(); + auto* host_context = example_host_create_context(evmc_tx_context{}); auto host = evmc::HostContext{host_context}; EXPECT_EQ(host.call({}).gas_left, 0); diff --git a/test/vmtester/tests.cpp b/test/vmtester/tests.cpp index c8be7e2..6aab228 100644 --- a/test/vmtester/tests.cpp +++ b/test/vmtester/tests.cpp @@ -59,7 +59,7 @@ TEST_F(evmc_vm_test, capabilities) TEST_F(evmc_vm_test, execute_call) { - evmc_context* context = example_host_create_context(); + evmc_context* context = example_host_create_context(evmc_tx_context{}); evmc_message msg{}; std::array code = {{0xfe, 0x00}}; @@ -92,7 +92,7 @@ TEST_F(evmc_vm_test, execute_call) TEST_F(evmc_vm_test, execute_create) { - evmc_context* context = example_host_create_context(); + evmc_context* context = example_host_create_context(evmc_tx_context{}); evmc_message msg{ EVMC_CREATE, 0, 0, 65536, evmc_address{}, evmc_address{}, nullptr, 0, evmc_uint256be{}, evmc_bytes32{}};