diff --git a/bindings/go/evmc/host.c b/bindings/go/evmc/host.c index 88cb7b8..5cb35a7 100644 --- a/bindings/go/evmc/host.c +++ b/bindings/go/evmc/host.c @@ -46,8 +46,9 @@ static inline void go_exported_functions_type_checks() size_t size = 0; int64_t number = 0; struct evmc_message* message = NULL; - struct evmc_tx_context* tx_context = NULL; + struct evmc_tx_context tx_context; + (void)tx_context; struct evmc_result result; (void)result; enum evmc_storage_status storage_status; @@ -92,8 +93,8 @@ static inline void go_exported_functions_type_checks() result = call(context, message); evmc_get_tx_context_fn get_tx_context_fn = NULL; - get_tx_context_fn(tx_context, context); - getTxContext(tx_context, context); + tx_context = get_tx_context_fn(context); + tx_context = getTxContext(context); evmc_get_block_hash_fn get_block_hash_fn = NULL; get_block_hash_fn(uint256be, context, number); diff --git a/bindings/go/evmc/host.go b/bindings/go/evmc/host.go index f3b804b..992bc8d 100644 --- a/bindings/go/evmc/host.go +++ b/bindings/go/evmc/host.go @@ -164,13 +164,13 @@ func selfdestruct(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pBeneficiar } //export getTxContext -func getTxContext(pResult unsafe.Pointer, pCtx unsafe.Pointer) { +func getTxContext(pCtx unsafe.Pointer) C.struct_evmc_tx_context { idx := int((*C.struct_extended_context)(pCtx).index) ctx := getHostContext(idx) gasPrice, origin, coinbase, number, timestamp, gasLimit, difficulty := ctx.GetTxContext() - *(*C.struct_evmc_tx_context)(pResult) = C.struct_evmc_tx_context{ + return C.struct_evmc_tx_context{ evmcUint256be(gasPrice), evmcAddress(origin), evmcAddress(coinbase), diff --git a/examples/capi.c b/examples/capi.c index 8b23226..c16ceb8 100644 --- a/examples/capi.c +++ b/examples/capi.c @@ -126,10 +126,12 @@ static struct evmc_result call(struct evmc_context* context, const struct evmc_m return result; } -static void get_tx_context(struct evmc_tx_context* result, struct evmc_context* context) +static struct evmc_tx_context get_tx_context(struct evmc_context* context) { - (void)result; (void)context; + struct evmc_tx_context result; + memset(&result, 0, sizeof(struct evmc_tx_context)); + return result; } static void get_block_hash(struct evmc_uint256be* result, diff --git a/include/evmc/evmc.h b/include/evmc/evmc.h index bd81912..c3d716d 100644 --- a/include/evmc/evmc.h +++ b/include/evmc/evmc.h @@ -145,13 +145,10 @@ struct evmc_context; * This callback function is used by an EVM to retrieve the transaction and * block context. * - * @param[out] result The returned transaction context. - * @see ::evmc_tx_context. * @param context The pointer to the Host execution context. - * @see ::evmc_context. + * @return The transaction context. */ -typedef void (*evmc_get_tx_context_fn)(struct evmc_tx_context* result, - struct evmc_context* context); +typedef struct evmc_tx_context (*evmc_get_tx_context_fn)(struct evmc_context* context); /** * Get block hash callback function. diff --git a/test/vmtester/mock_context.cpp b/test/vmtester/mock_context.cpp index eb12f0e..c4a42fb 100644 --- a/test/vmtester/mock_context.cpp +++ b/test/vmtester/mock_context.cpp @@ -97,10 +97,11 @@ static evmc_result call(evmc_context* context, const evmc_message* msg) return result; } -static void get_tx_context(evmc_tx_context* result, evmc_context* context) +static evmc_tx_context get_tx_context(evmc_context* context) { - (void)result; (void)context; + evmc_tx_context result{}; + return result; } static void get_block_hash(evmc_uint256be* result, evmc_context* context, int64_t number)