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

eth/tracers: make transaction trace response compatible with geth #648

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,32 @@ type StdTraceConfig struct {

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

// Create a response that is compatible with go-ethereum
// with txHash field but still keep transactionHash field
// to avoid breaking change for current user.
// FIXME: Remove this function and change transactionHash
// to txHash after everyone has changed to use the new one.
func (result txTraceResult) MarshalJSON() ([]byte, error) {
newResult := struct {
TxHash common.Hash `json:"txHash"`
TransactionHash common.Hash `json:"transactionHash"`
Result interface{} `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}{
TxHash: result.TransactionHash,
TransactionHash: result.TransactionHash,
Result: result.Result,
Error: result.Error,
}

return json.Marshal(&newResult)
}

// internalAndAccountResult is the result of a single transaction trace.
type internalAndAccountResult struct {
InternalTxs []*txTraceResult `json:"internalTxs,omitempty"` // Trace results produced by the tracer
Expand Down
Loading