From 104a4a12c3863b03c39aac88c59ba483ad5270f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 20 Jan 2017 13:38:11 +0100 Subject: [PATCH] EVM-C: Improve query state callback function --- examples/capi.c | 8 +++++--- examples/examplevm.c | 4 ++-- include/evm.h | 11 ++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/capi.c b/examples/capi.c index de94733..ff155f3 100644 --- a/examples/capi.c +++ b/examples/capi.c @@ -4,7 +4,8 @@ #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}}; return ret; @@ -19,7 +20,8 @@ struct evm_uint160be address(struct evm_env* env) static void query(union evm_variant* result, struct evm_env* env, 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); switch (key) { case EVM_CODE_BY_ADDRESS: @@ -28,7 +30,7 @@ static void query(union evm_variant* result, break; case EVM_BALANCE: - result->uint256be = balance(env, arg->address); + result->uint256be = balance(env, address); break; case EVM_ACCOUNT_EXISTS: diff --git a/examples/examplevm.c b/examples/examplevm.c index 8e70918..f523276 100644 --- a/examples/examplevm.c +++ b/examples/examplevm.c @@ -6,7 +6,7 @@ struct examplevm { struct evm_instance instance; - evm_query_fn query_fn; + evm_query_state_fn query_fn; evm_update_fn update_fn; evm_call_fn call_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; } -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_call_fn call_fn, evm_get_tx_context_fn get_tx_context_fn, diff --git a/include/evm.h b/include/evm.h index 71888f5..c2714f7 100644 --- a/include/evm.h +++ b/include/evm.h @@ -275,10 +275,11 @@ union evm_variant { /// @param arg evm_variant::uint256be The index of the storage entry. /// @result evm_variant::uint256be The current value of the storage entry. /// -typedef void (*evm_query_fn)(union evm_variant* result, - struct evm_env* env, - enum evm_query_key key, - const union evm_variant* arg); +typedef void (*evm_query_state_fn)(union evm_variant* result, + struct evm_env* env, + enum evm_query_key key, + const struct evm_uint160be* address, + const struct evm_uint256be* storage_key); /// The update callback key. enum evm_update_key { @@ -374,7 +375,7 @@ struct evm_instance; ///< Forward declaration. /// @param update_fn Pointer to update callback function. Nonnull. /// @param call_fn Pointer to call callback function. Nonnull. /// @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_call_fn call_fn, evm_get_tx_context_fn,