@@ -15,6 +15,14 @@ import (
15
15
"github.com/jackc/pgx/v4"
16
16
)
17
17
18
+ var defaultTraceConfig = & traceConfig {
19
+ DisableStorage : false ,
20
+ DisableStack : false ,
21
+ EnableMemory : false ,
22
+ EnableReturnData : false ,
23
+ Tracer : nil ,
24
+ }
25
+
18
26
// DebugEndpoints is the debug jsonrpc endpoint
19
27
type DebugEndpoints struct {
20
28
state types.StateInterface
@@ -125,36 +133,38 @@ func (d *DebugEndpoints) buildTraceBlock(ctx context.Context, txs []*ethTypes.Tr
125
133
}
126
134
127
135
func (d * DebugEndpoints ) buildTraceTransaction (ctx context.Context , hash common.Hash , cfg * traceConfig , dbTx pgx.Tx ) (interface {}, types.Error ) {
128
- traceConfig := state.TraceConfig {}
129
-
130
- if cfg != nil {
131
- traceConfig .DisableStack = cfg .DisableStack
132
- traceConfig .DisableStorage = cfg .DisableStorage
133
- traceConfig .EnableMemory = cfg .EnableMemory
134
- traceConfig .EnableReturnData = cfg .EnableReturnData
135
- traceConfig .Tracer = cfg .Tracer
136
+ trcCfg := cfg
137
+ if trcCfg == nil {
138
+ trcCfg = defaultTraceConfig
136
139
}
137
140
138
- result , err := d .state .DebugTransaction (ctx , hash , traceConfig , dbTx )
141
+ stateTraceConfig := state.TraceConfig {
142
+ DisableStack : trcCfg .DisableStack ,
143
+ DisableStorage : trcCfg .DisableStorage ,
144
+ EnableMemory : trcCfg .EnableMemory ,
145
+ EnableReturnData : trcCfg .EnableReturnData ,
146
+ Tracer : trcCfg .Tracer ,
147
+ }
148
+ result , err := d .state .DebugTransaction (ctx , hash , stateTraceConfig , dbTx )
139
149
if errors .Is (err , state .ErrNotFound ) {
140
150
return rpcErrorResponse (types .DefaultErrorCode , "transaction not found" , nil )
141
151
} else if err != nil {
142
152
const errorMessage = "failed to get trace"
143
- log .Infof ("%v: %v" , errorMessage , err )
153
+ log .Errorf ("%v: %v" , errorMessage , err )
144
154
return nil , types .NewRPCError (types .DefaultErrorCode , errorMessage )
145
155
}
146
156
147
- if traceConfig .Tracer != nil && * traceConfig .Tracer != "" && len (result .ExecutorTraceResult ) > 0 {
157
+ if stateTraceConfig .Tracer != nil && * stateTraceConfig .Tracer != "" && len (result .ExecutorTraceResult ) > 0 {
148
158
return result .ExecutorTraceResult , nil
149
159
}
150
160
151
161
failed := result .Failed ()
152
162
var returnValue interface {}
153
- if traceConfig .EnableReturnData {
163
+ if stateTraceConfig .EnableReturnData {
154
164
returnValue = common .Bytes2Hex (result .ReturnValue )
155
165
}
156
166
157
- structLogs := d .buildStructLogs (result .StructLogs , cfg )
167
+ structLogs := d .buildStructLogs (result .StructLogs , * trcCfg )
158
168
159
169
resp := traceTransactionResponse {
160
170
Gas : result .GasUsed ,
@@ -166,7 +176,7 @@ func (d *DebugEndpoints) buildTraceTransaction(ctx context.Context, hash common.
166
176
return resp , nil
167
177
}
168
178
169
- func (d * DebugEndpoints ) buildStructLogs (stateStructLogs []instrumentation.StructLog , cfg * traceConfig ) []StructLogRes {
179
+ func (d * DebugEndpoints ) buildStructLogs (stateStructLogs []instrumentation.StructLog , cfg traceConfig ) []StructLogRes {
170
180
structLogs := make ([]StructLogRes , 0 , len (stateStructLogs ))
171
181
for _ , structLog := range stateStructLogs {
172
182
errRes := ""
0 commit comments