Return bool from evmc_get_code_hash_fn()

This commit is contained in:
Paweł Bylica 2018-09-06 11:46:00 +02:00
parent ca85b77f57
commit d6ef551541
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
4 changed files with 26 additions and 11 deletions

View File

@ -77,8 +77,8 @@ static inline void go_exported_functions_type_checks()
size = getCodeSize(context, address);
evmc_get_code_hash_fn get_code_hash_fn = NULL;
get_code_hash_fn(uint256be, context, address);
getCodeHash(uint256be, context, address);
bool_flag = get_code_hash_fn(uint256be, context, address);
bool_flag = getCodeHash(uint256be, context, address);
evmc_copy_code_fn copy_code_fn = NULL;
size = copy_code_fn(context, address, size, data, size);

View File

@ -75,7 +75,7 @@ type HostContext interface {
SetStorage(addr common.Address, key common.Hash, value common.Hash) StorageStatus
GetBalance(addr common.Address) (common.Hash, error)
GetCodeSize(addr common.Address) int
GetCodeHash(addr common.Address) common.Hash
GetCodeHash(addr common.Address) (common.Hash, error)
GetCode(addr common.Address) []byte
Selfdestruct(addr common.Address, beneficiary common.Address)
GetTxContext() (gasPrice common.Hash, origin common.Address, coinbase common.Address, number int64, timestamp int64,
@ -129,10 +129,15 @@ func getCodeSize(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address) C.size_t {
}
//export getCodeHash
func getCodeHash(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, pAddr *C.struct_evmc_address) {
func getCodeHash(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)
*pResult = evmcUint256be(ctx.GetCodeHash(goAddress(*pAddr)))
codeHash, err := ctx.GetCodeHash(goAddress(*pAddr))
if err != nil {
return false
}
*pResult = evmcUint256be(codeHash)
return true
}
//export copyCode

View File

@ -67,13 +67,14 @@ static size_t get_code_size(evmc_context* context, const evmc_address* address)
return 0;
}
static void get_code_hash(evmc_uint256be* result,
static bool get_code_hash(evmc_uint256be* result,
evmc_context* context,
const evmc_address* address)
{
(void)result;
(void)context;
(void)address;
return false;
}
static size_t copy_code(evmc_context* context,

View File

@ -504,12 +504,21 @@ typedef size_t (*evmc_get_code_size_fn)(struct evmc_context* context,
/**
* Get code size callback function.
*
* This callback function is used by an EVM to get the keccak256 hash of the code stored
* in the account at the given address. For accounts not having a code, this
* function returns keccak256 hash of empty data. For accounts not existing in the state,
* this function returns 0.
* This callback function is used by a VM to get the keccak256 hash of the code stored
* in the account at the given address. For existing accounts not having a code, this
* function returns keccak256 hash of empty data.
*
* @param[out] result The pointer to the place where to put the result code hash.
* 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 the hash of its code 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_code_hash_fn)(struct evmc_uint256be* result,
typedef bool (*evmc_get_code_hash_fn)(struct evmc_uint256be* result,
struct evmc_context* context,
const struct evmc_address* address);