diff --git a/examples/example_host.cpp b/examples/example_host.cpp index 21641ad..59f0424 100644 --- a/examples/example_host.cpp +++ b/examples/example_host.cpp @@ -18,10 +18,20 @@ using namespace evmc::literals; struct account { evmc::uint256be balance = {}; - size_t code_size = 0; - evmc::bytes32 code_hash = {}; std::vector code; std::map storage; + + virtual evmc::bytes32 code_hash() + { + // Extremely dumb "hash" function. + evmc::bytes32 ret{}; + for (std::vector::size_type i = 0; i != code.size(); i++) + { + auto v = code[i]; + ret.bytes[v % sizeof(ret.bytes)] ^= v; + } + return ret; + } }; class ExampleHost : public evmc::Host @@ -69,7 +79,7 @@ public: { auto it = accounts.find(addr); if (it != accounts.end()) - return it->second.code_size; + return it->second.code.size(); return 0; } @@ -77,7 +87,7 @@ public: { auto it = accounts.find(addr); if (it != accounts.end()) - return it->second.code_hash; + return it->second.code_hash(); return {}; }