@@ -106,10 +106,10 @@ func (s *StructLog) ErrorString() string {
106106// if you need to retain them beyond the current call.
107107type EVMLogger interface {
108108 CaptureStart (env * EVM , from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int )
109- CaptureState (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error )
109+ CaptureState (pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error )
110110 CaptureEnter (typ OpCode , from common.Address , to common.Address , input []byte , gas uint64 , value * big.Int )
111111 CaptureExit (output []byte , gasUsed uint64 , err error )
112- CaptureFault (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error )
112+ CaptureFault (pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error )
113113 CaptureEnd (output []byte , gasUsed uint64 , t time.Duration , err error )
114114}
115115
@@ -120,6 +120,7 @@ type EVMLogger interface {
120120// contract their storage.
121121type StructLogger struct {
122122 cfg LogConfig
123+ env * EVM
123124
124125 storage map [common.Address ]Storage
125126 logs []StructLog
@@ -148,12 +149,13 @@ func (l *StructLogger) Reset() {
148149
149150// CaptureStart implements the EVMLogger interface to initialize the tracing operation.
150151func (l * StructLogger ) CaptureStart (env * EVM , from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int ) {
152+ l .env = env
151153}
152154
153155// CaptureState logs a new structured log message and pushes it out to the environment
154156//
155157// CaptureState also tracks SLOAD/SSTORE ops to track storage change.
156- func (l * StructLogger ) CaptureState (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error ) {
158+ func (l * StructLogger ) CaptureState (pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error ) {
157159 memory := scope .Memory
158160 stack := scope .Stack
159161 contract := scope .Contract
@@ -187,7 +189,7 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
187189 if op == SLOAD && stack .len () >= 1 {
188190 var (
189191 address = common .Hash (stack .data [stack .len ()- 1 ].Bytes32 ())
190- value = env .StateDB .GetState (contract .Address (), address )
192+ value = l . env .StateDB .GetState (contract .Address (), address )
191193 )
192194 l .storage [contract .Address ()][address ] = value
193195 storage = l .storage [contract .Address ()].Copy ()
@@ -207,13 +209,13 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
207209 copy (rdata , rData )
208210 }
209211 // create a new snapshot of the EVM.
210- log := StructLog {pc , op , gas , cost , mem , memory .Len (), stck , rdata , storage , depth , env .StateDB .GetRefund (), err }
212+ log := StructLog {pc , op , gas , cost , mem , memory .Len (), stck , rdata , storage , depth , l . env .StateDB .GetRefund (), err }
211213 l .logs = append (l .logs , log )
212214}
213215
214216// CaptureFault implements the EVMLogger interface to trace an execution fault
215217// while running an opcode.
216- func (l * StructLogger ) CaptureFault (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error ) {
218+ func (l * StructLogger ) CaptureFault (pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error ) {
217219}
218220
219221// CaptureEnd is called after the call finishes to finalize the tracing.
@@ -292,19 +294,21 @@ func WriteLogs(writer io.Writer, logs []*types.Log) {
292294type mdLogger struct {
293295 out io.Writer
294296 cfg * LogConfig
297+ env * EVM
295298}
296299
297300// NewMarkdownLogger creates a logger which outputs information in a format adapted
298301// for human readability, and is also a valid markdown table
299302func NewMarkdownLogger (cfg * LogConfig , writer io.Writer ) * mdLogger {
300- l := & mdLogger {writer , cfg }
303+ l := & mdLogger {out : writer , cfg : cfg }
301304 if l .cfg == nil {
302305 l .cfg = & LogConfig {}
303306 }
304307 return l
305308}
306309
307310func (t * mdLogger ) CaptureStart (env * EVM , from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int ) {
311+ t .env = env
308312 if ! create {
309313 fmt .Fprintf (t .out , "From: `%v`\n To: `%v`\n Data: `%#x`\n Gas: `%d`\n Value `%v` wei\n " ,
310314 from .String (), to .String (),
@@ -322,7 +326,7 @@ func (t *mdLogger) CaptureStart(env *EVM, from common.Address, to common.Address
322326}
323327
324328// CaptureState also tracks SLOAD/SSTORE ops to track storage change.
325- func (t * mdLogger ) CaptureState (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error ) {
329+ func (t * mdLogger ) CaptureState (pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error ) {
326330 stack := scope .Stack
327331 fmt .Fprintf (t .out , "| %4d | %10v | %3d |" , pc , op , cost )
328332
@@ -335,14 +339,14 @@ func (t *mdLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64
335339 b := fmt .Sprintf ("[%v]" , strings .Join (a , "," ))
336340 fmt .Fprintf (t .out , "%10v |" , b )
337341 }
338- fmt .Fprintf (t .out , "%10v |" , env .StateDB .GetRefund ())
342+ fmt .Fprintf (t .out , "%10v |" , t . env .StateDB .GetRefund ())
339343 fmt .Fprintln (t .out , "" )
340344 if err != nil {
341345 fmt .Fprintf (t .out , "Error: %v\n " , err )
342346 }
343347}
344348
345- func (t * mdLogger ) CaptureFault (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error ) {
349+ func (t * mdLogger ) CaptureFault (pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error ) {
346350 fmt .Fprintf (t .out , "\n Error: at pc=%d, op=%v: %v\n " , pc , op , err )
347351}
348352
0 commit comments