Drop EVMC_STORAGE_NON_EXISTING_ACCOUNT status

This commit is contained in:
Paweł Bylica 2018-09-09 02:02:18 +02:00
parent 21e6605f98
commit 941c0a9723
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
3 changed files with 8 additions and 28 deletions

View File

@ -72,7 +72,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
SetStorage(addr common.Address, key common.Hash, value common.Hash) (StorageStatus, error)
SetStorage(addr common.Address, key common.Hash, value common.Hash) StorageStatus
GetBalance(addr common.Address) (common.Hash, error)
GetCodeSize(addr common.Address) (int, error)
GetCodeHash(addr common.Address) (common.Hash, error)
@ -105,11 +105,7 @@ func getStorage(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pKey *C.evmc_
func setStorage(pCtx unsafe.Pointer, pAddr *C.evmc_address, pKey *C.evmc_bytes32, pVal *C.evmc_bytes32) C.enum_evmc_storage_status {
idx := int((*C.struct_extended_context)(pCtx).index)
ctx := getHostContext(idx)
status, err := ctx.SetStorage(goAddress(*pAddr), goHash(*pKey), goHash(*pVal))
if err != nil {
return C.EVMC_STORAGE_NON_EXISTING_ACCOUNT
}
return C.enum_evmc_storage_status(status)
return C.enum_evmc_storage_status(ctx.SetStorage(goAddress(*pAddr), goHash(*pKey), goHash(*pVal)));
}
//export getBalance

View File

@ -52,25 +52,14 @@ static enum evmc_storage_status set_storage(evmc_context* context,
const evmc_bytes32* value)
{
example_host_context* host = static_cast<example_host_context*>(context);
auto accountIt = host->accounts.find(*address);
if (accountIt == host->accounts.end())
return EVMC_STORAGE_NON_EXISTING_ACCOUNT;
auto& account = host->accounts[*address];
auto prevValue = account.storage[*key];
account.storage[*key] = *value;
auto storageIt = accountIt->second.storage.find(*key);
if (storageIt == accountIt->second.storage.end())
{
accountIt->second.storage.emplace(std::make_pair(*key, *value));
return EVMC_STORAGE_ADDED;
}
else if (storageIt->second == *value)
{
if (prevValue == *value)
return EVMC_STORAGE_UNCHANGED;
}
else
{
storageIt->second = *value;
return EVMC_STORAGE_MODIFIED;
}
}
static bool get_balance(evmc_uint256be* result, evmc_context* context, const evmc_address* address)

View File

@ -460,12 +460,7 @@ enum evmc_storage_status
/**
* A storage item has been deleted: X -> 0.
*/
EVMC_STORAGE_DELETED = 4,
/**
* An attempt to modify storage of an non-existing account.
*/
EVMC_STORAGE_NON_EXISTING_ACCOUNT = 5
EVMC_STORAGE_DELETED = 4
};
@ -478,7 +473,7 @@ enum evmc_storage_status
* @param address The address of the contract.
* @param key The index of the storage entry.
* @param value The value to be stored.
* @return The effect on the storage item. @see ::evmc_storage_status.
* @return The effect on the storage item.
*/
typedef enum evmc_storage_status (*evmc_set_storage_fn)(struct evmc_context* context,
const evmc_address* address,