mirror of https://github.com/status-im/evmc.git
EVM-C: Simplify set_storage callback
This commit is contained in:
parent
cde8027511
commit
06b25bf87d
|
@ -42,13 +42,12 @@ static void query(union evm_variant* result,
|
|||
}
|
||||
}
|
||||
|
||||
static void update(struct evm_env* env,
|
||||
enum evm_update_key key,
|
||||
const struct evm_uint160be* addr,
|
||||
const union evm_variant* arg1,
|
||||
const union evm_variant* arg2)
|
||||
static void set_storage(struct evm_env* env,
|
||||
const struct evm_uint160be* addr,
|
||||
const struct evm_uint256be* key,
|
||||
const struct evm_uint256be* value)
|
||||
{
|
||||
printf("EVM-C: UPDATE %d\n", key);
|
||||
printf("EVM-C: SSTORE");
|
||||
}
|
||||
|
||||
static void call(struct evm_result* result,
|
||||
|
@ -76,7 +75,7 @@ int main(int argc, char *argv[]) {
|
|||
if (factory.abi_version != EVM_ABI_VERSION)
|
||||
return 1; // Incompatible ABI version.
|
||||
|
||||
struct evm_instance* jit = factory.create(query, update, NULL, call,
|
||||
struct evm_instance* jit = factory.create(query, set_storage, NULL, call,
|
||||
get_tx_context, get_block_hash,
|
||||
NULL);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ struct examplevm
|
|||
{
|
||||
struct evm_instance instance;
|
||||
evm_query_state_fn query_fn;
|
||||
evm_update_state_fn update_fn;
|
||||
evm_set_storage_fn set_storage_fn;
|
||||
evm_call_fn call_fn;
|
||||
evm_get_tx_context_fn get_tx_context_fn;
|
||||
evm_get_block_hash_fn get_block_hash_fn;
|
||||
|
@ -102,9 +102,7 @@ static struct evm_result execute(struct evm_instance* instance,
|
|||
const struct evm_uint256be index = {{0,}};
|
||||
vm->query_fn(&value, env, EVM_SLOAD, &msg->address, &index);
|
||||
value.uint256be.bytes[31] += 1;
|
||||
union evm_variant arg;
|
||||
arg.uint256be = index;
|
||||
vm->update_fn(env, EVM_SSTORE, &msg->address, &arg, &value);
|
||||
vm->set_storage_fn(env, &msg->address, &index, &value.uint256be);
|
||||
ret.code = EVM_SUCCESS;
|
||||
return ret;
|
||||
}
|
||||
|
@ -117,7 +115,7 @@ static struct evm_result execute(struct evm_instance* instance,
|
|||
}
|
||||
|
||||
static struct evm_instance* evm_create(evm_query_state_fn query_fn,
|
||||
evm_update_state_fn update_fn,
|
||||
evm_set_storage_fn update_fn,
|
||||
evm_selfdestruct_fn selfdestruct_fn,
|
||||
evm_call_fn call_fn,
|
||||
evm_get_tx_context_fn get_tx_context_fn,
|
||||
|
@ -130,7 +128,7 @@ static struct evm_instance* evm_create(evm_query_state_fn query_fn,
|
|||
interface->execute = execute;
|
||||
interface->set_option = evm_set_option;
|
||||
vm->query_fn = query_fn;
|
||||
vm->update_fn = update_fn;
|
||||
vm->set_storage_fn = update_fn;
|
||||
vm->call_fn = call_fn;
|
||||
vm->get_tx_context_fn = get_tx_context_fn;
|
||||
vm->get_block_hash_fn = get_block_hash_fn;
|
||||
|
|
|
@ -270,30 +270,19 @@ typedef void (*evm_query_state_fn)(union evm_variant* result,
|
|||
const struct evm_uint160be* address,
|
||||
const struct evm_uint256be* storage_key);
|
||||
|
||||
/// The update callback key.
|
||||
enum evm_update_key {
|
||||
EVM_SSTORE = 0, ///< Update storage entry
|
||||
};
|
||||
|
||||
|
||||
/// Update callback function.
|
||||
/// Set storage callback function.
|
||||
///
|
||||
/// This callback function is used by the EVM to modify contract state in the
|
||||
/// host application.
|
||||
/// @param env Pointer to execution environment managed by the host
|
||||
/// application.
|
||||
/// @param key The kind of the update. See evm_update_key and details below.
|
||||
///
|
||||
/// ## Kinds of updates
|
||||
///
|
||||
/// - ::EVM_SSTORE
|
||||
/// @param arg1 evm_variant::uint256be The index of the storage entry.
|
||||
/// @param arg2 evm_variant::uint256be The value to be stored.
|
||||
typedef void (*evm_update_state_fn)(struct evm_env* env,
|
||||
enum evm_update_key key,
|
||||
const struct evm_uint160be* address,
|
||||
const union evm_variant* arg1,
|
||||
const union evm_variant* arg2);
|
||||
/// This callback function is used by an EVM to update the given contract
|
||||
/// storage entry
|
||||
/// @param env Pointer to execution environment managed by the host
|
||||
/// application.
|
||||
/// @param address The address of the contract.
|
||||
/// @param key The index of the storage entry.
|
||||
/// @param value The value to be stored.
|
||||
typedef void (*evm_set_storage_fn)(struct evm_env* env,
|
||||
const struct evm_uint160be* address,
|
||||
const struct evm_uint256be* key,
|
||||
const struct evm_uint256be* value);
|
||||
|
||||
/// Selfdestruct callback function.
|
||||
///
|
||||
|
@ -351,7 +340,7 @@ struct evm_instance; ///< Forward declaration.
|
|||
/// @param get_block_hash_fn Pointer to get block hash function. Nonnull.
|
||||
/// @return Pointer to the created EVM instance.
|
||||
typedef struct evm_instance* (*evm_create_fn)(evm_query_state_fn query_fn,
|
||||
evm_update_state_fn update_fn,
|
||||
evm_set_storage_fn update_fn,
|
||||
evm_selfdestruct_fn selfdestruct_fn,
|
||||
evm_call_fn call_fn,
|
||||
evm_get_tx_context_fn get_tx_context_fn,
|
||||
|
|
Loading…
Reference in New Issue