Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add Type back to CallFrame #3507

Merged
merged 3 commits into from
Oct 7, 2024
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
28 changes: 25 additions & 3 deletions packages/evm/jsonrpc/tracer_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/big"
"strings"
"sync/atomic"

"github.com/ethereum/go-ethereum/accounts/abi"
Expand Down Expand Up @@ -32,8 +33,29 @@ type callLog struct {
Position hexutil.Uint `json:"position"`
}

type OpCodeJSON struct {
vm.OpCode
}

func NewOpCodeJSON(code vm.OpCode) OpCodeJSON {
return OpCodeJSON{OpCode: code}
}

func (o OpCodeJSON) MarshalJSON() ([]byte, error) {
return json.Marshal(strings.ToLower(o.String()))
}

func (o *OpCodeJSON) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
o.OpCode = vm.StringToOp(strings.ToUpper(s))
return nil
}

type CallFrame struct {
Type vm.OpCode `json:"-"`
Type OpCodeJSON `json:"type"`
From common.Address `json:"from"`
Gas hexutil.Uint64 `json:"gas"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
Expand Down Expand Up @@ -71,7 +93,7 @@ func (f *CallFrame) processOutput(output []byte, err error, reverted bool) {
}
f.Error = err.Error()
f.revertedSnapshot = reverted
if f.Type == vm.CREATE || f.Type == vm.CREATE2 {
if f.Type.OpCode == vm.CREATE || f.Type.OpCode == vm.CREATE2 {
f.To = nil
}
if !errors.Is(err, vm.ErrExecutionReverted) || len(output) == 0 {
Expand Down Expand Up @@ -161,7 +183,7 @@ func (t *callTracer) OnEnter(depth int, typ byte, from common.Address, to common

toCopy := to
call := CallFrame{
Type: vm.OpCode(typ),
Type: NewOpCodeJSON(vm.OpCode(typ)),
From: from,
To: &toCopy,
Input: common.CopyBytes(input),
Expand Down
Loading