diff --git a/examples/capi.c b/examples/capi.c index 373e276..ac52432 100644 --- a/examples/capi.c +++ b/examples/capi.c @@ -22,16 +22,17 @@ static void query(union evm_variant* result, const union evm_variant* arg) { printf("EVM-C: QUERY %d\n", key); switch (key) { - case EVM_GAS_LIMIT: - result->int64 = 314; + case EVM_CODE_BY_ADDRESS: + result->data = NULL; + result->data_size = 0; break; case EVM_BALANCE: result->uint256be = balance(env, arg->address); break; - case EVM_ADDRESS: - result->address = address(env); + case EVM_ACCOUNT_EXISTS: + result->int64 = 0; break; default: @@ -63,13 +64,19 @@ static int64_t call( return EVM_CALL_FAILURE; } +static void get_tx_context(struct evm_tx_context* result, struct evm_env* env) +{ + +} + /// Example how the API is supposed to be used. int main(int argc, char *argv[]) { struct evm_factory factory = examplevm_get_factory(); if (factory.abi_version != EVM_ABI_VERSION) return 1; // Incompatible ABI version. - struct evm_instance* jit = factory.create(query, update, call); + struct evm_instance* jit = factory.create(query, update, call, + get_tx_context); uint8_t const code[] = "Place some EVM bytecode here"; const size_t code_size = sizeof(code); diff --git a/examples/examplevm.c b/examples/examplevm.c index 202b0bb..6b2e842 100644 --- a/examples/examplevm.c +++ b/examples/examplevm.c @@ -9,6 +9,7 @@ struct examplevm evm_query_fn query_fn; evm_update_fn update_fn; evm_call_fn call_fn; + evm_get_tx_context_fn get_tx_context_fn; }; static void evm_destroy(struct evm_instance* evm) @@ -93,7 +94,8 @@ static struct evm_result evm_execute(struct evm_instance* instance, static struct evm_instance* evm_create(evm_query_fn query_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) { struct examplevm* vm = calloc(1, sizeof(struct examplevm)); struct evm_instance* interface = &vm->instance; @@ -103,6 +105,7 @@ static struct evm_instance* evm_create(evm_query_fn query_fn, vm->query_fn = query_fn; vm->update_fn = update_fn; vm->call_fn = call_fn; + vm->get_tx_context_fn = get_tx_context_fn; return interface; } diff --git a/include/evm.h b/include/evm.h index db2eedd..32ddf51 100644 --- a/include/evm.h +++ b/include/evm.h @@ -29,6 +29,10 @@ enum { EVM_ABI_VERSION = 0 }; +/// Opaque struct representing execution enviroment managed by the host +/// application. +struct evm_env; + /// Big-endian 256-bit integer. /// /// 32 bytes of data representing big-endian 256-bit integer. I.e. bytes[0] is @@ -169,10 +173,6 @@ enum evm_query_key { }; -/// Opaque struct representing execution enviroment managed by the host -/// application. -struct evm_env; - /// Variant type to represent possible types of values used in EVM. /// /// Type-safety is lost around the code that uses this type. We should have