This commit is contained in:
Sina Mahmoodi 2025-02-05 16:01:24 +01:00
parent 0ccd62465c
commit 6879bbf7de
2 changed files with 20 additions and 47 deletions

View file

@ -20,7 +20,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"math/big"
"os" "os"
"path/filepath" "path/filepath"
@ -115,38 +114,12 @@ func (l *fileWritingTracer) OnTxEnd(receipt *types.Receipt, err error) {
} }
func (l *fileWritingTracer) hooks() *tracing.Hooks { func (l *fileWritingTracer) hooks() *tracing.Hooks {
return &tracing.Hooks{ // Shallow copy
OnTxStart: l.OnTxStart, tmp := *l.inner
OnTxEnd: l.OnTxEnd, hooks := &tmp
OnEnter: func(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
if l.inner != nil && l.inner.OnEnter != nil { hooks.OnTxStart = l.OnTxStart
l.inner.OnEnter(depth, typ, from, to, input, gas, value) hooks.OnTxEnd = l.OnTxEnd
}
}, return hooks
OnExit: func(depth int, output []byte, gasUsed uint64, err error, reverted bool) {
if l.inner != nil && l.inner.OnExit != nil {
l.inner.OnExit(depth, output, gasUsed, err, reverted)
}
},
OnOpcode: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
if l.inner != nil && l.inner.OnOpcode != nil {
l.inner.OnOpcode(pc, op, gas, cost, scope, rData, depth, err)
}
},
OnFault: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, depth int, err error) {
if l.inner != nil && l.inner.OnFault != nil {
l.inner.OnFault(pc, op, gas, cost, scope, depth, err)
}
},
OnSystemCallStart: func() {
if l.inner != nil && l.inner.OnSystemCallStart != nil {
l.inner.OnSystemCallStart()
}
},
OnSystemCallEnd: func() {
if l.inner != nil && l.inner.OnSystemCallEnd != nil {
l.inner.OnSystemCallEnd()
}
},
}
} }

View file

@ -69,11 +69,11 @@ func NewJSONLogger(cfg *Config, writer io.Writer) *tracing.Hooks {
l.cfg = &Config{} l.cfg = &Config{}
} }
l.hooks = &tracing.Hooks{ l.hooks = &tracing.Hooks{
OnTxStart: l.OnTxStart, OnTxStart: l.OnTxStart,
OnSystemCallStart: l.onSystemCallStart, OnSystemCallStartV2: l.onSystemCallStartV2,
OnExit: l.OnExit, OnExit: l.OnExit,
OnOpcode: l.OnOpcode, OnOpcode: l.OnOpcode,
OnFault: l.OnFault, OnFault: l.OnFault,
} }
return l.hooks return l.hooks
} }
@ -86,12 +86,12 @@ func NewJSONLoggerWithCallFrames(cfg *Config, writer io.Writer) *tracing.Hooks {
l.cfg = &Config{} l.cfg = &Config{}
} }
l.hooks = &tracing.Hooks{ l.hooks = &tracing.Hooks{
OnTxStart: l.OnTxStart, OnTxStart: l.OnTxStart,
OnSystemCallStart: l.onSystemCallStart, OnSystemCallStartV2: l.onSystemCallStartV2,
OnEnter: l.OnEnter, OnEnter: l.OnEnter,
OnExit: l.OnExit, OnExit: l.OnExit,
OnOpcode: l.OnOpcode, OnOpcode: l.OnOpcode,
OnFault: l.OnFault, OnFault: l.OnFault,
} }
return l.hooks return l.hooks
} }
@ -127,7 +127,7 @@ func (l *jsonLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracin
l.encoder.Encode(log) l.encoder.Encode(log)
} }
func (l *jsonLogger) onSystemCallStart() { func (l *jsonLogger) onSystemCallStartV2(ctx *tracing.VMContext) {
// Process no events while in system call. // Process no events while in system call.
hooks := *l.hooks hooks := *l.hooks
*l.hooks = tracing.Hooks{ *l.hooks = tracing.Hooks{