From cd9109bfacb70ed275ef7d52cb56254777b4582f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 24 Apr 2019 11:38:55 +0100 Subject: [PATCH] examples: add EVMC_CREATE example to example_vm --- examples/example_vm.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/example_vm.c b/examples/example_vm.c index e4f8729..b4579fc 100644 --- a/examples/example_vm.c +++ b/examples/example_vm.c @@ -110,8 +110,17 @@ static struct evmc_result execute(struct evmc_instance* instance, // Assembly: `{ mstore(0, number()) return(0, msize()) }` const char return_block_number[] = "\x43\x60\x00\x52\x59\x60\x00\xf3"; - if (code_size == (sizeof(return_address) - 1) && - strncmp((const char*)code, return_address, code_size) == 0) + if (msg->kind == EVMC_CREATE) + { + evmc_address create_address = { + {1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + ret.status_code = EVMC_SUCCESS; + ret.create_address = create_address; + ret.gas_left = msg->gas / 10; + return ret; + } + else if (code_size == (sizeof(return_address) - 1) && + strncmp((const char*)code, return_address, code_size) == 0) { static const size_t address_size = sizeof(msg->destination); uint8_t* output_data = (uint8_t*)malloc(address_size);