Skip to content

Commit

Permalink
Add return code to get_block_hash_fn
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Aug 31, 2018
1 parent 3a3aef2 commit ab46bee
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions bindings/go/evmc/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ static inline void go_exported_functions_type_checks()
tx_context = getTxContext(context);

evmc_get_block_hash_fn get_block_hash_fn = NULL;
get_block_hash_fn(uint256be, context, number);
getBlockHash(uint256be, context, number);
status = get_block_hash_fn(uint256be, context, number);
status = getBlockHash(uint256be, context, number);

evmc_emit_log_fn emit_log_fn = NULL;
emit_log_fn(context, address, data, size, uint256be, size);
Expand Down
14 changes: 12 additions & 2 deletions bindings/go/evmc/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,21 @@ func getTxContext(pCtx unsafe.Pointer) C.struct_evmc_tx_context {
}

//export getBlockHash
func getBlockHash(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, number int64) {
func getBlockHash(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, number int64) C.int {
idx := int((*C.struct_extended_context)(pCtx).index)
ctx := getHostContext(idx)

*pResult = evmcUint256be(ctx.GetBlockHash(number))
blockhash := ctx.GetBlockHash(number)

*pResult = evmcUint256be(blockhash)

r := C.int(0)
if blockhash != (common.Hash{}) {
// All zeroes hash is considered a failure in lookup.
// FIXME: should we instead adjust `ctx.GetBlockHash`?
r = 1
}
return r
}

//export emitLog
Expand Down
3 changes: 2 additions & 1 deletion examples/example_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ static evmc_tx_context get_tx_context(evmc_context* context)
return result;
}

static void get_block_hash(evmc_uint256be* result, evmc_context* context, int64_t number)
static int get_block_hash(evmc_uint256be* result, evmc_context* context, int64_t number)
{
(void)result;
(void)context;
(void)number;
return 0;
}

static void emit_log(evmc_context* context,
Expand Down
7 changes: 4 additions & 3 deletions include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ typedef struct evmc_tx_context (*evmc_get_tx_context_fn)(struct evmc_context* co
* @param context The pointer to the Host execution context.
* @param number The block number. Must be a value between
* (and including) 0 and 255.
* @return 1 if exists, 0 otherwise.
*/
typedef void (*evmc_get_block_hash_fn)(struct evmc_uint256be* result,
struct evmc_context* context,
int64_t number);
typedef int (*evmc_get_block_hash_fn)(struct evmc_uint256be* result,
struct evmc_context* context,
int64_t number);

/**
* The execution status code.
Expand Down

0 comments on commit ab46bee

Please sign in to comment.