mirror of https://github.com/status-im/evmc.git
Return bool from evmc_get_balance_fn()
This commit is contained in:
parent
ae4a79a9b9
commit
ca85b77f57
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue