@@ -105,10 +105,10 @@ func (s *StructLog) ErrorString() string {
105105// if you need to retain them beyond the current call.
106106type EVMLogger interface {
107107 CaptureStart (env * EVM , from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int )
108- CaptureState (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error )
108+ CaptureState (pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error )
109109 CaptureEnter (typ OpCode , from common.Address , to common.Address , input []byte , gas uint64 , value * big.Int )
110110 CaptureExit (output []byte , gasUsed uint64 , err error )
111- CaptureFault (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error )
111+ CaptureFault (pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error )
112112 CaptureEnd (output []byte , gasUsed uint64 , t time.Duration , err error )
113113}
114114
@@ -119,6 +119,7 @@ type EVMLogger interface {
119119// contract their storage.
120120type StructLogger struct {
121121 cfg LogConfig
122+ env * EVM
122123
123124 storage map [common.Address ]Storage
124125 logs []StructLog
@@ -147,12 +148,13 @@ func (l *StructLogger) Reset() {
147148
148149// CaptureStart implements the EVMLogger interface to initialize the tracing operation.
149150func (l * StructLogger ) CaptureStart (env * EVM , from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int ) {
151+ l .env = env
150152}
151153
152154// CaptureState logs a new structured log message and pushes it out to the environment
153155//
154156// CaptureState also tracks SLOAD/SSTORE ops to track storage change.
155- func (l * StructLogger ) CaptureState (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error ) {
157+ func (l * StructLogger ) CaptureState (pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error ) {
156158 memory := scope .Memory
157159 stack := scope .Stack
158160 contract := scope .Contract
@@ -186,7 +188,7 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
186188 if op == SLOAD && stack .len () >= 1 {
187189 var (
188190 address = common .Hash (stack .data [stack .len ()- 1 ].Bytes32 ())
189- value = env .StateDB .GetState (contract .Address (), address )
191+ value = l . env .StateDB .GetState (contract .Address (), address )
190192 )
191193 l .storage [contract .Address ()][address ] = value
192194 storage = l .storage [contract .Address ()].Copy ()
@@ -206,13 +208,13 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
206208 copy (rdata , rData )
207209 }
208210 // create a new snapshot of the EVM.
209- log := StructLog {pc , op , gas , cost , mem , memory .Len (), stck , rdata , storage , depth , env .StateDB .GetRefund (), err }
211+ log := StructLog {pc , op , gas , cost , mem , memory .Len (), stck , rdata , storage , depth , l . env .StateDB .GetRefund (), err }
210212 l .logs = append (l .logs , log )
211213}
212214
213215// CaptureFault implements the EVMLogger interface to trace an execution fault
214216// while running an opcode.
215- func (l * StructLogger ) CaptureFault (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error ) {
217+ func (l * StructLogger ) CaptureFault (pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error ) {
216218}
217219
218220// CaptureEnd is called after the call finishes to finalize the tracing.
@@ -291,19 +293,21 @@ func WriteLogs(writer io.Writer, logs []*types.Log) {
291293type mdLogger struct {
292294 out io.Writer
293295 cfg * LogConfig
296+ env * EVM
294297}
295298
296299// NewMarkdownLogger creates a logger which outputs information in a format adapted
297300// for human readability, and is also a valid markdown table
298301func NewMarkdownLogger (cfg * LogConfig , writer io.Writer ) * mdLogger {
299- l := & mdLogger {writer , cfg }
302+ l := & mdLogger {out : writer , cfg : cfg }
300303 if l .cfg == nil {
301304 l .cfg = & LogConfig {}
302305 }
303306 return l
304307}
305308
306309func (t * mdLogger ) CaptureStart (env * EVM , from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int ) {
310+ t .env = env
307311 if ! create {
308312 fmt .Fprintf (t .out , "From: `%v`\n To: `%v`\n Data: `0x%x`\n Gas: `%d`\n Value `%v` wei\n " ,
309313 from .String (), to .String (),
@@ -321,7 +325,7 @@ func (t *mdLogger) CaptureStart(env *EVM, from common.Address, to common.Address
321325}
322326
323327// CaptureState also tracks SLOAD/SSTORE ops to track storage change.
324- func (t * mdLogger ) CaptureState (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error ) {
328+ func (t * mdLogger ) CaptureState (pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , rData []byte , depth int , err error ) {
325329 stack := scope .Stack
326330 fmt .Fprintf (t .out , "| %4d | %10v | %3d |" , pc , op , cost )
327331
@@ -334,14 +338,14 @@ func (t *mdLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64
334338 b := fmt .Sprintf ("[%v]" , strings .Join (a , "," ))
335339 fmt .Fprintf (t .out , "%10v |" , b )
336340 }
337- fmt .Fprintf (t .out , "%10v |" , env .StateDB .GetRefund ())
341+ fmt .Fprintf (t .out , "%10v |" , t . env .StateDB .GetRefund ())
338342 fmt .Fprintln (t .out , "" )
339343 if err != nil {
340344 fmt .Fprintf (t .out , "Error: %v\n " , err )
341345 }
342346}
343347
344- func (t * mdLogger ) CaptureFault (env * EVM , pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error ) {
348+ func (t * mdLogger ) CaptureFault (pc uint64 , op OpCode , gas , cost uint64 , scope * ScopeContext , depth int , err error ) {
345349 fmt .Fprintf (t .out , "\n Error: at pc=%d, op=%v: %v\n " , pc , op , err )
346350}
347351
0 commit comments