Skip to content

Commit

Permalink
Return bool from evmc_gen_balance_fn()
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Sep 6, 2018
1 parent 83a679c commit e38c9ed
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
4 changes: 2 additions & 2 deletions bindings/go/evmc/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ static inline void go_exported_functions_type_checks()
storage_status = setStorage(context, address, uint256be, uint256be);

evmc_get_balance_fn get_balance_fn = NULL;
get_balance_fn(uint256be, context, address);
getBalance(uint256be, context, address);
bool_flag = get_balance_fn(uint256be, context, address);
bool_flag = getBalance(uint256be, context, address);

evmc_get_code_size_fn get_code_size_fn = NULL;
size = get_code_size_fn(context, address);
Expand Down
10 changes: 7 additions & 3 deletions bindings/go/evmc/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type HostContext interface {
AccountExists(addr common.Address) bool
GetStorage(addr common.Address, key common.Hash) common.Hash
SetStorage(addr common.Address, key common.Hash, value common.Hash) StorageStatus
GetBalance(addr common.Address) common.Hash
GetBalance(addr common.Address) (common.Hash, error)
GetCodeSize(addr common.Address) int
GetCodeHash(addr common.Address) common.Hash
GetCode(addr common.Address) []byte
Expand Down Expand Up @@ -110,11 +110,15 @@ func setStorage(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pKey *C.struc
}

//export getBalance
func getBalance(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, pAddr *C.struct_evmc_address) {
func getBalance(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, pAddr *C.struct_evmc_address) C.bool {
idx := int((*C.struct_extended_context)(pCtx).index)
ctx := getHostContext(idx)
balance := ctx.GetBalance(goAddress(*pAddr))
balance, err := ctx.GetBalance(goAddress(*pAddr))
if err != nil {
return false
}
*pResult = evmcUint256be(balance)
return true
}

//export getCodeSize
Expand Down
3 changes: 2 additions & 1 deletion examples/example_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ static enum evmc_storage_status set_storage(evmc_context* context,
return EVMC_STORAGE_UNCHANGED;
}

static void get_balance(evmc_uint256be* result, evmc_context* context, const evmc_address* address)
static bool get_balance(evmc_uint256be* result, evmc_context* context, const evmc_address* address)
{
*result = balance(context, address);
return true;
}

static size_t get_code_size(evmc_context* context, const evmc_address* address)
Expand Down
18 changes: 11 additions & 7 deletions include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,18 @@ typedef enum evmc_storage_status (*evmc_set_storage_fn)(struct evmc_context* con
/**
* Get balance callback function.
*
* This callback function is used by an EVM to query the balance of the given
* address.
* @param[out] result The returned balance value.
* @param context The pointer to the Host execution context.
* @see ::evmc_context.
* @param address The address.
* This callback function is used by a VM to query the balance of the given address.
*
* @param[out] result The pointer to the place where to put the result balance.
* The pointed memory is only modified when the function returns true.
* @param context The pointer to the Host execution context.
* @param address The address.
* @return If the account exists its balance is put at the location
* pointed by @p result and true is returned.
* If the account does not exist false is returned without
* modifying the memory pointed by @p result.
*/
typedef void (*evmc_get_balance_fn)(struct evmc_uint256be* result,
typedef bool (*evmc_get_balance_fn)(struct evmc_uint256be* result,
struct evmc_context* context,
const struct evmc_address* address);

Expand Down

0 comments on commit e38c9ed

Please sign in to comment.