EVM-C: Improve query state callback function

This commit is contained in:
Paweł Bylica 2017-01-20 13:38:11 +01:00 committed by Alex Beregszaszi
parent 58ad722339
commit 104a4a12c3
3 changed files with 13 additions and 10 deletions

View File

@ -4,7 +4,8 @@
#include "evm.h" #include "evm.h"
struct evm_uint256be balance(struct evm_env* env, struct evm_uint160be address) struct evm_uint256be balance(struct evm_env* env,
const struct evm_uint160be* address)
{ {
struct evm_uint256be ret = {.bytes = {1, 2, 3, 4}}; struct evm_uint256be ret = {.bytes = {1, 2, 3, 4}};
return ret; return ret;
@ -19,7 +20,8 @@ struct evm_uint160be address(struct evm_env* env)
static void query(union evm_variant* result, static void query(union evm_variant* result,
struct evm_env* env, struct evm_env* env,
enum evm_query_key key, enum evm_query_key key,
const union evm_variant* arg) { const struct evm_uint160be* address,
const struct evm_uint256be* storage_key) {
printf("EVM-C: QUERY %d\n", key); printf("EVM-C: QUERY %d\n", key);
switch (key) { switch (key) {
case EVM_CODE_BY_ADDRESS: case EVM_CODE_BY_ADDRESS:
@ -28,7 +30,7 @@ static void query(union evm_variant* result,
break; break;
case EVM_BALANCE: case EVM_BALANCE:
result->uint256be = balance(env, arg->address); result->uint256be = balance(env, address);
break; break;
case EVM_ACCOUNT_EXISTS: case EVM_ACCOUNT_EXISTS:

View File

@ -6,7 +6,7 @@
struct examplevm struct examplevm
{ {
struct evm_instance instance; struct evm_instance instance;
evm_query_fn query_fn; evm_query_state_fn query_fn;
evm_update_fn update_fn; evm_update_fn update_fn;
evm_call_fn call_fn; evm_call_fn call_fn;
evm_get_tx_context_fn get_tx_context_fn; evm_get_tx_context_fn get_tx_context_fn;
@ -93,7 +93,7 @@ static struct evm_result evm_execute(struct evm_instance* instance,
return ret; return ret;
} }
static struct evm_instance* evm_create(evm_query_fn query_fn, static struct evm_instance* evm_create(evm_query_state_fn query_fn,
evm_update_fn update_fn, evm_update_fn update_fn,
evm_call_fn call_fn, evm_call_fn call_fn,
evm_get_tx_context_fn get_tx_context_fn, evm_get_tx_context_fn get_tx_context_fn,

View File

@ -275,10 +275,11 @@ union evm_variant {
/// @param arg evm_variant::uint256be The index of the storage entry. /// @param arg evm_variant::uint256be The index of the storage entry.
/// @result evm_variant::uint256be The current value of the storage entry. /// @result evm_variant::uint256be The current value of the storage entry.
/// ///
typedef void (*evm_query_fn)(union evm_variant* result, typedef void (*evm_query_state_fn)(union evm_variant* result,
struct evm_env* env, struct evm_env* env,
enum evm_query_key key, enum evm_query_key key,
const union evm_variant* arg); const struct evm_uint160be* address,
const struct evm_uint256be* storage_key);
/// The update callback key. /// The update callback key.
enum evm_update_key { enum evm_update_key {
@ -374,7 +375,7 @@ struct evm_instance; ///< Forward declaration.
/// @param update_fn Pointer to update callback function. Nonnull. /// @param update_fn Pointer to update callback function. Nonnull.
/// @param call_fn Pointer to call callback function. Nonnull. /// @param call_fn Pointer to call callback function. Nonnull.
/// @return Pointer to the created EVM instance. /// @return Pointer to the created EVM instance.
typedef struct evm_instance* (*evm_create_fn)(evm_query_fn query_fn, typedef struct evm_instance* (*evm_create_fn)(evm_query_state_fn query_fn,
evm_update_fn update_fn, evm_update_fn update_fn,
evm_call_fn call_fn, evm_call_fn call_fn,
evm_get_tx_context_fn, evm_get_tx_context_fn,