@@ -33,8 +33,8 @@ import (
33
33
"path/filepath"
34
34
)
35
35
36
- // fileWritingTracer is a tracer which wraps either a different tracer ,
37
- // or a logger. On tx start, it creates a new file to direct output to,
36
+ // fileWritingTracer wraps either a tracer or a logger. On tx start ,
37
+ // it instantiates a tracer/ logger, creates a new file to direct output to,
38
38
// and on tx end it closes the file.
39
39
type fileWritingTracer struct {
40
40
txIndex int
@@ -43,8 +43,7 @@ type fileWritingTracer struct {
43
43
baseDir string
44
44
45
45
// for json-tracing
46
- logConfig * logger.Config
47
- callFrames bool
46
+ logConfig * logger.Config
48
47
49
48
// for custom tracing
50
49
tracerName string
@@ -53,20 +52,63 @@ type fileWritingTracer struct {
53
52
getResult func () (json.RawMessage , error )
54
53
}
55
54
56
- func newFileWritingTracer (baseDir string , logConfig * logger.Config , callFrames bool ) * fileWritingTracer {
57
- return & fileWritingTracer {
58
- baseDir : baseDir ,
59
- logConfig : logConfig ,
60
- callFrames : callFrames ,
55
+ // jsonToFile creates hooks which uses an underlying jsonlogger, and writes the
56
+ // jsonl-delimited output to a file, one per tx.
57
+ func jsonToFile (baseDir string , logConfig * logger.Config , callFrames bool ) * tracing.Hooks {
58
+ t := & fileWritingTracer {
59
+ baseDir : baseDir ,
60
+ logConfig : logConfig ,
61
61
}
62
+ hooks := t .hooks ()
63
+ if ! callFrames {
64
+ hooks .OnEnter = nil
65
+ }
66
+ return hooks
62
67
}
63
68
64
- func newFileWritingCustomTracer (baseDir , tracerName string , traceConfig json.RawMessage , chainConfig * params.ChainConfig ) * fileWritingTracer {
65
- return & fileWritingTracer {
69
+ // tracerToFile creates hooks which uses an underlying tracer, and writes the
70
+ // json-result to file, one per tx.
71
+ func tracerToFile (baseDir , tracerName string , traceConfig json.RawMessage , chainConfig * params.ChainConfig ) * tracing.Hooks {
72
+ t := & fileWritingTracer {
66
73
baseDir : baseDir ,
67
74
tracerName : tracerName ,
68
75
chainConfig : chainConfig ,
69
76
}
77
+ return t .hooks ()
78
+ }
79
+
80
+ func (l * fileWritingTracer ) hooks () * tracing.Hooks {
81
+ hooks := & tracing.Hooks {
82
+ OnTxStart : l .OnTxStartJSONL ,
83
+ OnTxEnd : l .OnTxEnd ,
84
+ // intentional no-op: we instantiate the l.inner on tx start, which has
85
+ // not yet happened at this point
86
+ //OnSystemCallStart: func() {},
87
+ OnEnter : func (depth int , typ byte , from common.Address , to common.Address , input []byte , gas uint64 , value * big.Int ) {
88
+ if l .inner != nil && l .inner .OnEnter != nil {
89
+ l .inner .OnEnter (depth , typ , from , to , input , gas , value )
90
+ }
91
+ },
92
+ OnExit : func (depth int , output []byte , gasUsed uint64 , err error , reverted bool ) {
93
+ if l .inner != nil && l .inner .OnExit != nil {
94
+ l .inner .OnExit (depth , output , gasUsed , err , reverted )
95
+ }
96
+ },
97
+ OnOpcode : func (pc uint64 , op byte , gas , cost uint64 , scope tracing.OpContext , rData []byte , depth int , err error ) {
98
+ if l .inner .OnOpcode != nil {
99
+ l .inner .OnOpcode (pc , op , gas , cost , scope , rData , depth , err )
100
+ }
101
+ },
102
+ OnFault : func (pc uint64 , op byte , gas , cost uint64 , scope tracing.OpContext , depth int , err error ) {
103
+ if l .inner != nil && l .inner .OnFault != nil {
104
+ l .inner .OnFault (pc , op , gas , cost , scope , depth , err )
105
+ }
106
+ },
107
+ }
108
+ if len (l .tracerName ) > 0 { // a custom tracer
109
+ hooks .OnTxStart = l .OnTxStartJSON
110
+ }
111
+ return hooks
70
112
}
71
113
72
114
// OnTxStartJSONL is the OnTxStart-handler for jsonl logger.
@@ -79,11 +121,7 @@ func (l *fileWritingTracer) OnTxStartJSONL(env *tracing.VMContext, tx *types.Tra
79
121
}
80
122
log .Debug ("Created tracing-file" , "path" , fname )
81
123
l .destination = traceFile
82
- if ! l .callFrames {
83
- l .inner = logger .NewJSONLogger (l .logConfig , traceFile )
84
- } else {
85
- l .inner = logger .NewJSONLoggerWithCallFrames (l .logConfig , traceFile )
86
- }
124
+ l .inner = logger .NewJSONLoggerWithCallFrames (l .logConfig , traceFile )
87
125
if l .inner .OnTxStart != nil {
88
126
l .inner .OnTxStart (env , tx , from )
89
127
}
@@ -129,41 +167,3 @@ func (l *fileWritingTracer) OnTxEnd(receipt *types.Receipt, err error) {
129
167
}
130
168
l .txIndex ++
131
169
}
132
-
133
- func (l * fileWritingTracer ) Tracer () * tracers.Tracer {
134
- hooks := & tracing.Hooks {
135
- OnTxStart : l .OnTxStartJSONL ,
136
- OnTxEnd : l .OnTxEnd ,
137
- // intentional no-op: we instantiate the l.inner on tx start, which has
138
- // not yet happened at this point
139
- //OnSystemCallStart: func() {},
140
- OnEnter : func (depth int , typ byte , from common.Address , to common.Address , input []byte , gas uint64 , value * big.Int ) {
141
- if l .inner != nil && l .inner .OnEnter != nil {
142
- l .inner .OnEnter (depth , typ , from , to , input , gas , value )
143
- }
144
- },
145
- OnExit : func (depth int , output []byte , gasUsed uint64 , err error , reverted bool ) {
146
- if l .inner != nil && l .inner .OnExit != nil {
147
- l .inner .OnExit (depth , output , gasUsed , err , reverted )
148
- }
149
- },
150
- OnOpcode : func (pc uint64 , op byte , gas , cost uint64 , scope tracing.OpContext , rData []byte , depth int , err error ) {
151
- if l .inner .OnOpcode != nil {
152
- l .inner .OnOpcode (pc , op , gas , cost , scope , rData , depth , err )
153
- }
154
- },
155
- OnFault : func (pc uint64 , op byte , gas , cost uint64 , scope tracing.OpContext , depth int , err error ) {
156
- if l .inner != nil && l .inner .OnFault != nil {
157
- l .inner .OnFault (pc , op , gas , cost , scope , depth , err )
158
- }
159
- },
160
- }
161
- if len (l .tracerName ) > 0 { // a custom tracer
162
- hooks .OnTxStart = l .OnTxStartJSON
163
- }
164
- return & tracers.Tracer {
165
- Hooks : hooks ,
166
- GetResult : func () (json.RawMessage , error ) { return nil , nil },
167
- Stop : func (err error ) {},
168
- }
169
- }
0 commit comments