Skip to content

Commit

Permalink
fix: eth: use correct types for trace_block action/results
Browse files Browse the repository at this point in the history
- The top-level type is call/create.
- The action/result is specific to the operation.
  • Loading branch information
Stebalien committed Feb 13, 2024
1 parent 4ccc5d2 commit e090ac4
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 150 deletions.
46 changes: 27 additions & 19 deletions chain/types/ethtypes/eth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,17 +987,12 @@ func (e *EthBlockNumberOrHash) UnmarshalJSON(b []byte) error {
}

type EthTrace struct {
Action EthTraceAction `json:"action"`
Result EthTraceResult `json:"result"`
Subtraces int `json:"subtraces"`
TraceAddress []int `json:"traceAddress"`
Type string `json:"type"`
Error string `json:"error,omitempty"`
}

func (t *EthTrace) SetCallType(callType string) {
t.Action.CallType = callType
t.Type = callType
Action any `json:"action"`
Result any `json:"result"`
Subtraces int `json:"subtraces"`
TraceAddress []int `json:"traceAddress"`
Type string `json:"type"`
Error string `json:"error,omitempty"`
}

type EthTraceBlock struct {
Expand All @@ -1016,16 +1011,29 @@ type EthTraceReplayBlockTransaction struct {
VmTrace *string `json:"vmTrace"`
}

type EthTraceAction struct {
CallType string `json:"callType"`
From EthAddress `json:"from"`
To *EthAddress `json:"to"`
Gas EthUint64 `json:"gas"`
Input EthBytes `json:"input"`
Value EthBigInt `json:"value"`
type EthCallTraceAction struct {
CallType string `json:"callType"`
From EthAddress `json:"from"`
To EthAddress `json:"to"`
Gas EthUint64 `json:"gas"`
Input EthBytes `json:"input"`
Value EthBigInt `json:"value"`
}

type EthTraceResult struct {
type EthCallTraceResult struct {
GasUsed EthUint64 `json:"gasUsed"`
Output EthBytes `json:"output"`
}

type EthCreateTraceAction struct {
From EthAddress `json:"from"`
Gas EthUint64 `json:"gas"`
Init EthBytes `json:"init"`
Value EthBigInt `json:"value"`
}

type EthCreateTraceResult struct {
GasUsed EthUint64 `json:"gasUsed"`
Code EthBytes `json:"code"`
Address *EthAddress `json:"address,omitempty"`
}
7 changes: 6 additions & 1 deletion node/impl/full/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,12 @@ func (a *EthModule) EthTraceReplayBlockTransactions(ctx context.Context, blkNum

var output []byte
if len(env.traces) > 0 {
output = env.traces[0].Result.Output
switch r := env.traces[0].Result.(type) {
case *ethtypes.EthCallTraceResult:
output = r.Output
case *ethtypes.EthCreateTraceResult:
output = r.Code
}
}

allTraces = append(allTraces, &ethtypes.EthTraceReplayBlockTransaction{
Expand Down
Loading

0 comments on commit e090ac4

Please sign in to comment.