diff --git a/bindings/go/evmc/host.c b/bindings/go/evmc/host.c index d007fa3..dc2cce2 100644 --- a/bindings/go/evmc/host.c +++ b/bindings/go/evmc/host.c @@ -53,12 +53,12 @@ static inline void go_exported_functions_type_checks() (void)result; enum evmc_storage_status storage_status; (void)storage_status; - int status; - (void)status; + bool bool_flag; + (void)bool_flag; evmc_account_exists_fn account_exists_fn = NULL; - status = account_exists_fn(context, address); - status = accountExists(context, address); + bool_flag = account_exists_fn(context, address); + bool_flag = accountExists(context, address); evmc_get_storage_fn get_storage_fn = NULL; get_storage_fn(uint256be, context, address, uint256be); @@ -97,8 +97,8 @@ static inline void go_exported_functions_type_checks() tx_context = getTxContext(context); evmc_get_block_hash_fn get_block_hash_fn = NULL; - status = get_block_hash_fn(uint256be, context, number); - status = getBlockHash(uint256be, context, number); + bool_flag = get_block_hash_fn(uint256be, context, number); + bool_flag = getBlockHash(uint256be, context, number); evmc_emit_log_fn emit_log_fn = NULL; emit_log_fn(context, address, data, size, uint256be, size); diff --git a/bindings/go/evmc/host.go b/bindings/go/evmc/host.go index c6161d4..aca9d9d 100644 --- a/bindings/go/evmc/host.go +++ b/bindings/go/evmc/host.go @@ -88,15 +88,10 @@ type HostContext interface { } //export accountExists -func accountExists(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address) C.int { +func accountExists(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address) C.bool { idx := int((*C.struct_extended_context)(pCtx).index) ctx := getHostContext(idx) - exists := ctx.AccountExists(goAddress(*pAddr)) - r := C.int(0) - if exists { - r = 1 - } - return r + return C.bool(ctx.AccountExists(goAddress(*pAddr))) } //export getStorage @@ -183,17 +178,17 @@ func getTxContext(pCtx unsafe.Pointer) C.struct_evmc_tx_context { } //export getBlockHash -func getBlockHash(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, number int64) C.int { +func getBlockHash(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, number int64) C.bool { idx := int((*C.struct_extended_context)(pCtx).index) ctx := getHostContext(idx) blockhash, err := ctx.GetBlockHash(number) if err != nil { - return C.int(0) + return false } *pResult = evmcUint256be(blockhash) - return C.int(1) + return true } //export emitLog diff --git a/examples/example_host.cpp b/examples/example_host.cpp index 105f316..4974df4 100644 --- a/examples/example_host.cpp +++ b/examples/example_host.cpp @@ -24,11 +24,11 @@ static evmc_uint256be balance(evmc_context* context, const evmc_address* address return ret; } -static int account_exists(evmc_context* context, const evmc_address* address) +static bool account_exists(evmc_context* context, const evmc_address* address) { (void)context; (void)address; - return 0; + return false; } static void get_storage(evmc_uint256be* result, @@ -114,17 +114,17 @@ static evmc_tx_context get_tx_context(evmc_context* context) return result; } -static int get_block_hash(evmc_uint256be* result, evmc_context* context, int64_t number) +static bool get_block_hash(evmc_uint256be* result, evmc_context* context, int64_t number) { example_host_context* host = static_cast(context); int64_t current_block_number = host->tx_context.block_number; if (number >= current_block_number || number < current_block_number - 256) - return 0; + return false; evmc_uint256be example_block_hash{}; *result = example_block_hash; - return 1; + return true; } static void emit_log(evmc_context* context, diff --git a/include/evmc/evmc.h b/include/evmc/evmc.h index 7584668..21e5e1e 100644 --- a/include/evmc/evmc.h +++ b/include/evmc/evmc.h @@ -11,8 +11,9 @@ #ifndef EVMC_H #define EVMC_H -#include /* Definition of size_t. */ -#include /* Definition of int64_t, uint64_t. */ +#include /* Definition of bool, true and false. */ +#include /* Definition of size_t. */ +#include /* Definition of int64_t, uint64_t. */ #if __cplusplus extern "C" { @@ -147,19 +148,19 @@ typedef struct evmc_tx_context (*evmc_get_tx_context_fn)(struct evmc_context* co /** * Get block hash callback function. * - * This callback function is used by an VM to query the block hash of - * a given block. If the requested block is not found, then an appropriate - * result code is returned. + * This callback function is used by an VM to query the block hash of + * a given block. If the requested block is not found, then an appropriate + * result code is returned. * - * @param[out] result The returned block hash value. Only written to - * if the return value is 1 (information is avialable). - * @param context The pointer to the Host execution context. - * @param number The block number. - * @return 1 if the information is available, 0 otherwise. + * @param[out] result The returned block hash value. Only written to + * if the return value is 1 (information is avialable). + * @param context The pointer to the Host execution context. + * @param number The block number. + * @return true if the information is available, false otherwise. */ -typedef int (*evmc_get_block_hash_fn)(struct evmc_uint256be* result, - struct evmc_context* context, - int64_t number); +typedef bool (*evmc_get_block_hash_fn)(struct evmc_uint256be* result, + struct evmc_context* context, + int64_t number); /** * The execution status code. @@ -387,17 +388,16 @@ struct evmc_result /** - * Check account existence callback function + * Check account existence callback function. * - * This callback function is used by the EVM to check if - * there exists an account at given address. - * @param context The pointer to the Host execution context. - * @see ::evmc_context. - * @param address The address of the account the query is about. - * @return 1 if exists, 0 otherwise. + * This callback function is used by the VM to check if + * there exists an account at given address. + * @param context The pointer to the Host execution context. + * @param address The address of the account the query is about. + * @return true if exists, false otherwise. */ -typedef int (*evmc_account_exists_fn)(struct evmc_context* context, - const struct evmc_address* address); +typedef bool (*evmc_account_exists_fn)(struct evmc_context* context, + const struct evmc_address* address); /** * Get storage callback function.