Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split block and tx context, use out parameter #624

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/example_vm/example_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ evmc_result execute(evmc_vm* instance,

case OP_NUMBER:
{
evmc_uint256be value =
to_uint256(static_cast<uint32_t>(host->get_tx_context(context).block_number));
evmc_tx_context tx = {};
host->get_tx_context(&tx, context);
evmc_uint256be value = to_uint256(static_cast<uint32_t>(tx.block_number));
stack.push(value);
break;
}
Expand Down
10 changes: 5 additions & 5 deletions include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ struct evmc_host_context;
/**
* Get transaction context callback function.
*
* This callback function is used by an EVM to retrieve the transaction and
* block context.
* This callback function is used by an EVM to retrieve the transaction and block context.
*
* @param context The pointer to the Host execution context.
* @return The transaction context.
* @param[out] tx_context The pointer to the transaction context struct to be filled.
* @param host The pointer to the Host execution context.
*/
typedef struct evmc_tx_context (*evmc_get_tx_context_fn)(struct evmc_host_context* context);
typedef void (*evmc_get_tx_context_fn)(struct evmc_tx_context* tx_context,
struct evmc_host_context* host);

/**
* Get block hash callback function.
Expand Down
6 changes: 3 additions & 3 deletions include/evmc/evmc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ class HostContext : public HostInterface
evmc_tx_context get_tx_context() const noexcept final
{
if (tx_context.block_timestamp == 0)
tx_context = host->get_tx_context(context);
host->get_tx_context(&tx_context, context);
return tx_context;
}

Expand Down Expand Up @@ -819,9 +819,9 @@ inline evmc_result call(evmc_host_context* h, const evmc_message* msg) noexcept
return Host::from_context(h)->call(*msg).release_raw();
}

inline evmc_tx_context get_tx_context(evmc_host_context* h) noexcept
inline void get_tx_context(evmc_tx_context* tx, evmc_host_context* h) noexcept
{
return Host::from_context(h)->get_tx_context();
*tx = Host::from_context(h)->get_tx_context();
}

inline evmc_bytes32 get_block_hash(evmc_host_context* h, int64_t block_number) noexcept
Expand Down