@@ -30,7 +30,7 @@ import (
3030
3131// TraceTransaction returns the structured logs created during the execution of EVM
3232// and returns them as a JSON object.
33- func (b * Backend ) TraceTransaction (hash common.Hash , config * evmtypes .TraceConfig ) (interface {}, error ) {
33+ func (b * Backend ) TraceTransaction (hash common.Hash , config * rpctypes .TraceConfig ) (interface {}, error ) {
3434 // Get transaction by hash
3535 transaction , _ , err := b .GetTxByEthHash (hash )
3636 if err != nil {
@@ -80,7 +80,10 @@ func (b *Backend) TraceTransaction(hash common.Hash, config *evmtypes.TraceConfi
8080 }
8181
8282 if config != nil {
83- traceTxRequest .TraceConfig = config
83+ traceTxRequest .TraceConfig , err = convertConfig (config )
84+ if err != nil {
85+ return nil , err
86+ }
8487 }
8588
8689 // minus one to get the context of block beginning
@@ -109,7 +112,7 @@ func (b *Backend) TraceTransaction(hash common.Hash, config *evmtypes.TraceConfi
109112// executes all the transactions contained within. The return value will be one item
110113// per transaction, dependent on the requested tracer.
111114func (b * Backend ) TraceBlock (height rpctypes.BlockNumber ,
112- config * evmtypes .TraceConfig ,
115+ config * rpctypes .TraceConfig ,
113116 block * tmrpctypes.ResultBlock ,
114117) ([]* evmtypes.TxTraceResult , error ) {
115118 txs := block .Block .Txs
@@ -135,9 +138,14 @@ func (b *Backend) TraceBlock(height rpctypes.BlockNumber,
135138 }
136139 ctxWithHeight := rpctypes .ContextWithHeight (int64 (contextHeight ))
137140
141+ traceConfig , err := convertConfig (config )
142+ if err != nil {
143+ return nil , err
144+ }
145+
138146 traceBlockRequest := & evmtypes.QueryTraceBlockRequest {
139147 Txs : msgs ,
140- TraceConfig : config ,
148+ TraceConfig : traceConfig ,
141149 BlockNumber : block .Block .Height ,
142150 BlockTime : block .Block .Time ,
143151 BlockHash : common .Bytes2Hex (block .BlockID .Hash ),
@@ -157,3 +165,31 @@ func (b *Backend) TraceBlock(height rpctypes.BlockNumber,
157165
158166 return decodedResults , nil
159167}
168+
169+ func convertConfig (config * rpctypes.TraceConfig ) (* evmtypes.TraceConfig , error ) {
170+ if config == nil {
171+ return & evmtypes.TraceConfig {}, nil
172+ }
173+
174+ cfg := config .TraceConfig
175+
176+ if config .TracerConfig != nil {
177+ switch v := config .TracerConfig .(type ) {
178+ case string :
179+ // It's already a string, use it directly
180+ cfg .TracerJsonConfig = v
181+ case map [string ]interface {}:
182+ // this is the compliant style
183+ // we need to encode it to a string before passing it to the ethermint side
184+ jsonBytes , err := json .Marshal (v )
185+ if err != nil {
186+ return nil , fmt .Errorf ("unable to encode traceConfig to JSON: %w" , err )
187+ }
188+ cfg .TracerJsonConfig = string (jsonBytes )
189+ default :
190+ return nil , errors .New ("unexpected traceConfig type" )
191+ }
192+ }
193+
194+ return & cfg , nil
195+ }
0 commit comments