mirror of https://github.com/status-im/evmc.git
EVM-C: Fix C examples
This commit is contained in:
parent
da456c0ae6
commit
25a5fe0ceb
|
@ -22,16 +22,17 @@ static void query(union evm_variant* result,
|
||||||
const union evm_variant* arg) {
|
const union evm_variant* arg) {
|
||||||
printf("EVM-C: QUERY %d\n", key);
|
printf("EVM-C: QUERY %d\n", key);
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case EVM_GAS_LIMIT:
|
case EVM_CODE_BY_ADDRESS:
|
||||||
result->int64 = 314;
|
result->data = NULL;
|
||||||
|
result->data_size = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVM_BALANCE:
|
case EVM_BALANCE:
|
||||||
result->uint256be = balance(env, arg->address);
|
result->uint256be = balance(env, arg->address);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVM_ADDRESS:
|
case EVM_ACCOUNT_EXISTS:
|
||||||
result->address = address(env);
|
result->int64 = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -63,13 +64,19 @@ static int64_t call(
|
||||||
return EVM_CALL_FAILURE;
|
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.
|
/// Example how the API is supposed to be used.
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
struct evm_factory factory = examplevm_get_factory();
|
struct evm_factory factory = examplevm_get_factory();
|
||||||
if (factory.abi_version != EVM_ABI_VERSION)
|
if (factory.abi_version != EVM_ABI_VERSION)
|
||||||
return 1; // Incompatible 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";
|
uint8_t const code[] = "Place some EVM bytecode here";
|
||||||
const size_t code_size = sizeof(code);
|
const size_t code_size = sizeof(code);
|
||||||
|
|
|
@ -9,6 +9,7 @@ struct examplevm
|
||||||
evm_query_fn query_fn;
|
evm_query_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;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void evm_destroy(struct evm_instance* evm)
|
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,
|
static struct evm_instance* evm_create(evm_query_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)
|
||||||
{
|
{
|
||||||
struct examplevm* vm = calloc(1, sizeof(struct examplevm));
|
struct examplevm* vm = calloc(1, sizeof(struct examplevm));
|
||||||
struct evm_instance* interface = &vm->instance;
|
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->query_fn = query_fn;
|
||||||
vm->update_fn = update_fn;
|
vm->update_fn = update_fn;
|
||||||
vm->call_fn = call_fn;
|
vm->call_fn = call_fn;
|
||||||
|
vm->get_tx_context_fn = get_tx_context_fn;
|
||||||
return interface;
|
return interface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,10 @@ enum {
|
||||||
EVM_ABI_VERSION = 0
|
EVM_ABI_VERSION = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Opaque struct representing execution enviroment managed by the host
|
||||||
|
/// application.
|
||||||
|
struct evm_env;
|
||||||
|
|
||||||
/// Big-endian 256-bit integer.
|
/// Big-endian 256-bit integer.
|
||||||
///
|
///
|
||||||
/// 32 bytes of data representing big-endian 256-bit integer. I.e. bytes[0] is
|
/// 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.
|
/// 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
|
/// Type-safety is lost around the code that uses this type. We should have
|
||||||
|
|
Loading…
Reference in New Issue