Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit d238a19

Browse files
committed
eth/tracers: make transaction trace response compatible with geth
The current transactionHash field in transaction trace response should be named txHash to be compatible with go-ethereum. This commit adds txHash instead of replacing the current transactionHash field and make them have the same value. This can help to avoid breaking change for current users of these methods since users are unlikely to use strict DisallowUnknownFields when decoding the json response.
1 parent 1d3b00e commit d238a19

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

eth/tracers/api.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,32 @@ type StdTraceConfig struct {
184184

185185
// txTraceResult is the result of a single transaction trace.
186186
type txTraceResult struct {
187-
TransactionHash common.Hash `json:"transactionHash,omitempty"`
187+
TransactionHash common.Hash `json:"transactionHash"`
188188
Result interface{} `json:"result,omitempty"` // Trace results produced by the tracer
189189
Error string `json:"error,omitempty"` // Trace failure produced by the tracer
190190
}
191191

192+
// Create a response that is compatible with go-ethereum
193+
// with txHash field but still keep transactionHash field
194+
// to avoid breaking change for current user.
195+
// FIXME: Remove this function and change transactionHash
196+
// to txHash after everyone has changed to use the new one.
197+
func (result txTraceResult) MarshalJSON() ([]byte, error) {
198+
newResult := struct {
199+
TxHash common.Hash `json:"txHash"`
200+
TransactionHash common.Hash `json:"transactionHash"`
201+
Result interface{} `json:"result,omitempty"`
202+
Error string `json:"error,omitempty"`
203+
}{
204+
TxHash: result.TransactionHash,
205+
TransactionHash: result.TransactionHash,
206+
Result: result.Result,
207+
Error: result.Error,
208+
}
209+
210+
return json.Marshal(&newResult)
211+
}
212+
192213
// internalAndAccountResult is the result of a single transaction trace.
193214
type internalAndAccountResult struct {
194215
InternalTxs []*txTraceResult `json:"internalTxs,omitempty"` // Trace results produced by the tracer

0 commit comments

Comments
 (0)