mirror of https://github.com/status-im/evmc.git
Return bytes32 from get_storage() directly
This commit is contained in:
parent
48b85bd29d
commit
21e6605f98
|
@ -41,7 +41,7 @@ static inline void go_exported_functions_type_checks()
|
|||
{
|
||||
struct evmc_context* context = NULL;
|
||||
evmc_address* address = NULL;
|
||||
evmc_bytes32* bytes32 = NULL;
|
||||
evmc_bytes32 bytes32;
|
||||
evmc_uint256be* uint256be = NULL;
|
||||
uint8_t* data = NULL;
|
||||
size_t size = 0;
|
||||
|
@ -62,12 +62,12 @@ static inline void go_exported_functions_type_checks()
|
|||
bool_flag = accountExists(context, address);
|
||||
|
||||
evmc_get_storage_fn get_storage_fn = NULL;
|
||||
get_storage_fn(bytes32, context, address, bytes32);
|
||||
getStorage(bytes32, context, address, bytes32);
|
||||
bytes32 = get_storage_fn(context, address, &bytes32);
|
||||
bytes32 = getStorage(context, address, &bytes32);
|
||||
|
||||
evmc_set_storage_fn set_storage_fn = NULL;
|
||||
storage_status = set_storage_fn(context, address, bytes32, bytes32);
|
||||
storage_status = setStorage(context, address, bytes32, bytes32);
|
||||
storage_status = set_storage_fn(context, address, &bytes32, &bytes32);
|
||||
storage_status = setStorage(context, address, &bytes32, &bytes32);
|
||||
|
||||
evmc_get_balance_fn get_balance_fn = NULL;
|
||||
bool_flag = get_balance_fn(uint256be, context, address);
|
||||
|
@ -78,8 +78,8 @@ static inline void go_exported_functions_type_checks()
|
|||
bool_flag = getCodeSize(&size, context, address);
|
||||
|
||||
evmc_get_code_hash_fn get_code_hash_fn = NULL;
|
||||
bool_flag = get_code_hash_fn(bytes32, context, address);
|
||||
bool_flag = getCodeHash(bytes32, context, address);
|
||||
bool_flag = get_code_hash_fn(&bytes32, context, address);
|
||||
bool_flag = getCodeHash(&bytes32, context, address);
|
||||
|
||||
evmc_copy_code_fn copy_code_fn = NULL;
|
||||
size = copy_code_fn(context, address, size, data, size);
|
||||
|
@ -98,10 +98,10 @@ static inline void go_exported_functions_type_checks()
|
|||
tx_context = getTxContext(context);
|
||||
|
||||
evmc_get_block_hash_fn get_block_hash_fn = NULL;
|
||||
bool_flag = get_block_hash_fn(bytes32, context, number);
|
||||
bool_flag = getBlockHash(bytes32, context, number);
|
||||
bool_flag = get_block_hash_fn(&bytes32, context, number);
|
||||
bool_flag = getBlockHash(&bytes32, context, number);
|
||||
|
||||
evmc_emit_log_fn emit_log_fn = NULL;
|
||||
emit_log_fn(context, address, data, size, bytes32, size);
|
||||
emitLog(context, address, data, size, bytes32, size);
|
||||
emit_log_fn(context, address, data, size, &bytes32, size);
|
||||
emitLog(context, address, data, size, &bytes32, size);
|
||||
}
|
||||
|
|
|
@ -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, error)
|
||||
GetStorage(addr common.Address, key common.Hash) common.Hash
|
||||
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,15 +95,10 @@ func accountExists(pCtx unsafe.Pointer, pAddr *C.evmc_address) C.bool {
|
|||
}
|
||||
|
||||
//export getStorage
|
||||
func getStorage(pResult *C.evmc_bytes32, pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pKey *C.evmc_bytes32) C.bool {
|
||||
func getStorage(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pKey *C.evmc_bytes32) C.evmc_bytes32 {
|
||||
idx := int((*C.struct_extended_context)(pCtx).index)
|
||||
ctx := getHostContext(idx)
|
||||
value, err := ctx.GetStorage(goAddress(*pAddr), goHash(*pKey))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
*pResult = evmcBytes32(value)
|
||||
return true
|
||||
return evmcBytes32(ctx.GetStorage(goAddress(*pAddr), goHash(*pKey)))
|
||||
}
|
||||
|
||||
//export setStorage
|
||||
|
|
|
@ -35,19 +35,15 @@ static bool account_exists(evmc_context* context, const evmc_address* address)
|
|||
return host->accounts.find(*address) != host->accounts.end();
|
||||
}
|
||||
|
||||
static bool get_storage(evmc_bytes32* result,
|
||||
evmc_context* context,
|
||||
static evmc_bytes32 get_storage(evmc_context* context,
|
||||
const evmc_address* address,
|
||||
const evmc_bytes32* 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;
|
||||
return it->second.storage[*key];
|
||||
return {};
|
||||
}
|
||||
|
||||
static enum evmc_storage_status set_storage(evmc_context* context,
|
||||
|
|
|
@ -120,9 +120,8 @@ static struct evmc_result execute(struct evmc_instance* instance,
|
|||
}
|
||||
else if (code_size == strlen(counter) && strncmp((const char*)code, counter, code_size) == 0)
|
||||
{
|
||||
evmc_bytes32 value;
|
||||
const evmc_bytes32 key = {{0}};
|
||||
context->host->get_storage(&value, context, &msg->destination, &key);
|
||||
evmc_bytes32 value = context->host->get_storage(context, &msg->destination, &key);
|
||||
value.bytes[31]++;
|
||||
context->host->set_storage(context, &msg->destination, &key, &value);
|
||||
ret.status_code = EVMC_SUCCESS;
|
||||
|
|
|
@ -413,17 +413,13 @@ typedef bool (*evmc_account_exists_fn)(struct evmc_context* context, const evmc_
|
|||
*
|
||||
* 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 context 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.
|
||||
* @return The storage value at the given storage key or null bytes
|
||||
* if the account does not exist.
|
||||
*/
|
||||
typedef bool (*evmc_get_storage_fn)(evmc_bytes32* result,
|
||||
struct evmc_context* context,
|
||||
typedef evmc_bytes32 (*evmc_get_storage_fn)(struct evmc_context* context,
|
||||
const evmc_address* address,
|
||||
const evmc_bytes32* key);
|
||||
|
||||
|
|
Loading…
Reference in New Issue