diff --git a/bindings/go/evmc/host.c b/bindings/go/evmc/host.c index dc2cce2..c2bf70d 100644 --- a/bindings/go/evmc/host.c +++ b/bindings/go/evmc/host.c @@ -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); diff --git a/bindings/go/evmc/host.go b/bindings/go/evmc/host.go index aca9d9d..b83ddc1 100644 --- a/bindings/go/evmc/host.go +++ b/bindings/go/evmc/host.go @@ -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 @@ -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 diff --git a/examples/example_host.cpp b/examples/example_host.cpp index 4974df4..d98c6d9 100644 --- a/examples/example_host.cpp +++ b/examples/example_host.cpp @@ -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) diff --git a/include/evmc/evmc.h b/include/evmc/evmc.h index 50aa683..5d54b2e 100644 --- a/include/evmc/evmc.h +++ b/include/evmc/evmc.h @@ -475,14 +475,19 @@ 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. + * The pointer MUST NOT be null. + * @param context The pointer to the Host execution context. + * @param address The address of the account. + * @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);