examples: Learn example_vm how to make calls

This commit is contained in:
Paweł Bylica 2019-08-06 10:44:55 +02:00
parent a0a1042b56
commit a6ee9a81d3
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
1 changed files with 14 additions and 0 deletions

View File

@ -108,6 +108,9 @@ 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";
// Assembly: PUSH(0) 6x DUP1 CALL
const char make_a_call[] = "\x60\x00\x80\x80\x80\x80\x80\x80\xf1";
if (msg->kind == EVMC_CREATE)
{
ret.status_code = EVMC_SUCCESS;
@ -157,6 +160,17 @@ static struct evmc_result execute(struct evmc_instance* instance,
ret.release = &free_result_output_data;
return ret;
}
else if (code_size == (sizeof(make_a_call) - 1) &&
strncmp((const char*)code, make_a_call, code_size) == 0)
{
struct evmc_message call_msg;
memset(&call_msg, 0, sizeof(call_msg));
call_msg.kind = EVMC_CALL;
call_msg.depth = msg->depth + 1;
call_msg.gas = msg->gas - (msg->gas / 64);
call_msg.sender = msg->destination;
return context->host->call(context, &call_msg);
}
ret.status_code = EVMC_FAILURE;
ret.gas_left = 0;