tracing opcode return value
This commit is contained in:
parent
186ffe2288
commit
0140ff5d5a
|
@ -39,6 +39,11 @@ proc traceTransaction*(db: BaseChainDB, header: BlockHeader,
|
||||||
result = vmState.getTracingResult()
|
result = vmState.getTracingResult()
|
||||||
result["gas"] = %gasUsed
|
result["gas"] = %gasUsed
|
||||||
|
|
||||||
|
const returnValue = "returnValue"
|
||||||
|
let j = result["structLogs"].elems[^1]
|
||||||
|
if j.hasKey(returnValue):
|
||||||
|
result[returnValue] = j[returnValue]
|
||||||
|
|
||||||
# now we dump captured state db
|
# now we dump captured state db
|
||||||
if TracerFlags.DisableState notin tracerFlags:
|
if TracerFlags.DisableState notin tracerFlags:
|
||||||
var n = newJObject()
|
var n = newJObject()
|
||||||
|
|
|
@ -59,6 +59,7 @@ func output*(c: BaseComputation): seq[byte] =
|
||||||
|
|
||||||
func `output=`*(c: var BaseComputation, value: openarray[byte]) =
|
func `output=`*(c: var BaseComputation, value: openarray[byte]) =
|
||||||
c.rawOutput = @value
|
c.rawOutput = @value
|
||||||
|
c.lastOpCodeHasRetVal = true
|
||||||
|
|
||||||
proc outputHex*(c: BaseComputation): string =
|
proc outputHex*(c: BaseComputation): string =
|
||||||
if c.shouldEraseReturnData:
|
if c.shouldEraseReturnData:
|
||||||
|
|
|
@ -194,6 +194,7 @@ proc opTableToCaseStmt(opTable: array[Op, NimNode], computation: NimNode): NimNo
|
||||||
if `computation`.tracingEnabled:
|
if `computation`.tracingEnabled:
|
||||||
`computation`.traceOpCodeStarted($`asOp`)
|
`computation`.traceOpCodeStarted($`asOp`)
|
||||||
`computation`.gasMeter.consumeGas(`computation`.gasCosts[`asOp`].cost, reason = $`asOp`)
|
`computation`.gasMeter.consumeGas(`computation`.gasCosts[`asOp`].cost, reason = $`asOp`)
|
||||||
|
`computation`.lastOpCodeHasRetVal = false
|
||||||
`opImpl`(`computation`)
|
`opImpl`(`computation`)
|
||||||
if `computation`.tracingEnabled:
|
if `computation`.tracingEnabled:
|
||||||
`computation`.traceOpCodeEnded()
|
`computation`.traceOpCodeEnded()
|
||||||
|
@ -202,6 +203,7 @@ proc opTableToCaseStmt(opTable: array[Op, NimNode], computation: NimNode): NimNo
|
||||||
quote do:
|
quote do:
|
||||||
if `computation`.tracingEnabled:
|
if `computation`.tracingEnabled:
|
||||||
`computation`.traceOpCodeStarted($`asOp`)
|
`computation`.traceOpCodeStarted($`asOp`)
|
||||||
|
`computation`.lastOpCodeHasRetVal = false
|
||||||
`opImpl`(`computation`)
|
`opImpl`(`computation`)
|
||||||
if `computation`.tracingEnabled:
|
if `computation`.tracingEnabled:
|
||||||
`computation`.traceOpCodeEnded()
|
`computation`.traceOpCodeEnded()
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import
|
import
|
||||||
json, strutils,
|
json, strutils, nimcrypto, eth_common, stint,
|
||||||
eth_common, stint, byteutils,
|
../vm_types, memory, stack, ../db/[db_chain, state_db],
|
||||||
../vm_types, memory, stack,
|
eth_trie/hexary, ./message, ranges/typedranges
|
||||||
../db/[db_chain, state_db],
|
|
||||||
eth_trie/hexary, ./message,
|
|
||||||
ranges/typedranges
|
|
||||||
|
|
||||||
proc initTracer*(tracer: var TransactionTracer, flags: set[TracerFlags] = {}) =
|
proc initTracer*(tracer: var TransactionTracer, flags: set[TracerFlags] = {}) =
|
||||||
tracer.trace = newJObject()
|
tracer.trace = newJObject()
|
||||||
|
@ -60,6 +57,9 @@ proc traceOpCodeEnded*(tracer: var TransactionTracer, c: BaseComputation) =
|
||||||
|
|
||||||
j["gasCost"] = %(tracer.gasRemaining - c.gasMeter.gasRemaining)
|
j["gasCost"] = %(tracer.gasRemaining - c.gasMeter.gasRemaining)
|
||||||
|
|
||||||
|
if c.lastOpCodeHasRetVal:
|
||||||
|
j["returnValue"] = %("0x" & toHex(c.rawOutput, true))
|
||||||
|
|
||||||
proc traceError*(tracer: var TransactionTracer, c: BaseComputation) =
|
proc traceError*(tracer: var TransactionTracer, c: BaseComputation) =
|
||||||
let j = tracer.trace["structLogs"].elems[^1]
|
let j = tracer.trace["structLogs"].elems[^1]
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,7 @@ type
|
||||||
opcodes*: Table[Op, proc(computation: var BaseComputation){.nimcall.}]
|
opcodes*: Table[Op, proc(computation: var BaseComputation){.nimcall.}]
|
||||||
gasCosts*: GasCosts # TODO - will be hidden at a lower layer
|
gasCosts*: GasCosts # TODO - will be hidden at a lower layer
|
||||||
opCodeExec*: OpcodeExecutor
|
opCodeExec*: OpcodeExecutor
|
||||||
|
lastOpCodeHasRetVal*: bool
|
||||||
|
|
||||||
Error* = ref object
|
Error* = ref object
|
||||||
info*: string
|
info*: string
|
||||||
|
|
Loading…
Reference in New Issue