mirror of https://github.com/status-im/evmc.git
Return bool from get_storage() to indicate non-existing accounts
This commit is contained in:
parent
d128fe45d7
commit
a48893437f
|
@ -71,7 +71,7 @@ func goByteSlice(data *C.uint8_t, size C.size_t) []byte {
|
|||
|
||||
type HostContext interface {
|
||||
AccountExists(addr common.Address) bool
|
||||
GetStorage(addr common.Address, key common.Hash) common.Hash
|
||||
GetStorage(addr common.Address, key common.Hash) (common.Hash, error)
|
||||
SetStorage(addr common.Address, key common.Hash, value common.Hash) (StorageStatus, error)
|
||||
GetBalance(addr common.Address) (common.Hash, error)
|
||||
GetCodeSize(addr common.Address) (int, error)
|
||||
|
@ -95,11 +95,15 @@ func accountExists(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address) C.bool {
|
|||
}
|
||||
|
||||
//export getStorage
|
||||
func getStorage(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pKey *C.struct_evmc_uint256be) {
|
||||
func getStorage(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pKey *C.struct_evmc_uint256be) C.bool {
|
||||
idx := int((*C.struct_extended_context)(pCtx).index)
|
||||
ctx := getHostContext(idx)
|
||||
value := ctx.GetStorage(goAddress(*pAddr), goHash(*pKey))
|
||||
value, err := ctx.GetStorage(goAddress(*pAddr), goHash(*pKey))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
*pResult = evmcUint256be(value)
|
||||
return true
|
||||
}
|
||||
|
||||
//export setStorage
|
||||
|
|
|
@ -52,15 +52,19 @@ static bool account_exists(evmc_context* context, const evmc_address* address)
|
|||
return host->accounts.find(*address) != host->accounts.end();
|
||||
}
|
||||
|
||||
static void get_storage(evmc_uint256be* result,
|
||||
static bool get_storage(evmc_uint256be* result,
|
||||
evmc_context* context,
|
||||
const evmc_address* address,
|
||||
const evmc_uint256be* key)
|
||||
{
|
||||
(void)result;
|
||||
(void)context;
|
||||
(void)address;
|
||||
(void)key;
|
||||
example_host_context* host = static_cast<example_host_context*>(context);
|
||||
auto it = host->accounts.find(*address);
|
||||
if (it != host->accounts.end())
|
||||
{
|
||||
*result = it->second.storage[*key];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static enum evmc_storage_status set_storage(evmc_context* context,
|
||||
|
|
|
@ -409,15 +409,18 @@ typedef bool (*evmc_account_exists_fn)(struct evmc_context* context,
|
|||
/**
|
||||
* Get storage callback function.
|
||||
*
|
||||
* This callback function is used by an EVM to query the given contract
|
||||
* storage entry.
|
||||
* @param[out] result The returned storage value.
|
||||
* @param context The pointer to the Host execution context.
|
||||
* @see ::evmc_context.
|
||||
* @param address The address of the contract.
|
||||
* @param key The index of the storage entry.
|
||||
* This callback function is used by a VM to query the given contract storage entry.
|
||||
*
|
||||
* @param[out] result The pointer to the place where to put the result value.
|
||||
* @param context The pointer to the Host execution context.
|
||||
* @param address The address of the account.
|
||||
* @param key The index of the account's storage entry.
|
||||
* @return If the account exists the value 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_storage_fn)(struct evmc_uint256be* result,
|
||||
typedef bool (*evmc_get_storage_fn)(struct evmc_uint256be* result,
|
||||
struct evmc_context* context,
|
||||
const struct evmc_address* address,
|
||||
const struct evmc_uint256be* key);
|
||||
|
|
Loading…
Reference in New Issue