EVMC: Using `{.show.}` trace all calls from the host into the EVM

Show calls from the host into the EVM.  Shows the call, `evmc_message` fields,
and `evmc_result` fields when the call returns.

(When `show_tx_calls` is manually set to true.)

Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
Jamie Lokier 2021-05-24 18:00:38 +01:00
parent ffd34a69fe
commit a5dc0bd283
No known key found for this signature in database
GPG Key ID: CBC25C68435C30A2
2 changed files with 6 additions and 1 deletions

View File

@ -90,7 +90,8 @@ proc evmc_create_nimbus_evm(): ptr evmc_vm {.cdecl, importc.}
# a separate library yet.
import ./evmc_vm_glue
proc evmcExecComputation*(host: TransactionHost): EvmcResult =
# This must be named `call` to show as "call" when traced by the `show` macro.
proc call(host: TransactionHost): EvmcResult {.show, inline.} =
let vm = evmc_create_nimbus_evm()
if vm.isNil:
echo "Warning: No EVM"
@ -121,3 +122,6 @@ proc evmcExecComputation*(host: TransactionHost): EvmcResult =
evmc_revision(host.vmState.fork), host.msg,
if host.code.len > 0: host.code[0].unsafeAddr else: nil,
host.code.len.csize_t)
proc evmcExecComputation*(host: TransactionHost): EvmcResult =
call(host)

View File

@ -18,6 +18,7 @@ func `$`(address: HostAddress): string = toHex(address)
func `$`(txc: EvmcTxContext): string = &"gas_price={txc.tx_gas_price.fromEvmc}"
func `$`(n: typeof(EvmcMessage().sender)): string = $n.fromEvmc
func `$`(n: typeof(EvmcMessage().value)): string = $n.fromEvmc
func `$`(host: TransactionHost): string = &"(fork={host.vmState.fork} message=${host.msg})"
macro show*(fn: untyped): auto =
if not show_tx_calls: