mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
change callFrame to CallFrame
This commit is contained in:
parent
12677e670f
commit
86d6a68a61
3 changed files with 36 additions and 40 deletions
|
|
@ -32,17 +32,13 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate go run github.com/fjl/gencodec -type callFrame -field-override callFrameMarshaling -out gen_callframe_json.go
|
//go:generate go run github.com/fjl/gencodec -type CallFrame -field-override CallFrameMarshaling -out gen_CallFrame_json.go
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
tracers.DefaultDirectory.Register("callTracer", newCallTracer, false)
|
tracers.DefaultDirectory.Register("callTracer", newCallTracer, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CallFrame struct {
|
type CallLog struct {
|
||||||
callFrame
|
|
||||||
}
|
|
||||||
|
|
||||||
type callLog struct {
|
|
||||||
Address common.Address `json:"address"`
|
Address common.Address `json:"address"`
|
||||||
Topics []common.Hash `json:"topics"`
|
Topics []common.Hash `json:"topics"`
|
||||||
Data hexutil.Bytes `json:"data"`
|
Data hexutil.Bytes `json:"data"`
|
||||||
|
|
@ -51,7 +47,7 @@ type callLog struct {
|
||||||
Position hexutil.Uint `json:"position"`
|
Position hexutil.Uint `json:"position"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type callFrame struct {
|
type CallFrame struct {
|
||||||
Type vm.OpCode `json:"type"`
|
Type vm.OpCode `json:"type"`
|
||||||
From common.Address `json:"from"`
|
From common.Address `json:"from"`
|
||||||
Gas uint64 `json:"gas"`
|
Gas uint64 `json:"gas"`
|
||||||
|
|
@ -61,23 +57,23 @@ type callFrame struct {
|
||||||
Output []byte `json:"output,omitempty" rlp:"optional"`
|
Output []byte `json:"output,omitempty" rlp:"optional"`
|
||||||
Error string `json:"error,omitempty" rlp:"optional"`
|
Error string `json:"error,omitempty" rlp:"optional"`
|
||||||
RevertReason string `json:"revertReason,omitempty"`
|
RevertReason string `json:"revertReason,omitempty"`
|
||||||
Calls []callFrame `json:"calls,omitempty" rlp:"optional"`
|
Calls []CallFrame `json:"calls,omitempty" rlp:"optional"`
|
||||||
Logs []callLog `json:"logs,omitempty" rlp:"optional"`
|
Logs []CallLog `json:"logs,omitempty" rlp:"optional"`
|
||||||
// Placed at end on purpose. The RLP will be decoded to 0 instead of
|
// Placed at end on purpose. The RLP will be decoded to 0 instead of
|
||||||
// nil if there are non-empty elements after in the struct.
|
// nil if there are non-empty elements after in the struct.
|
||||||
Value *big.Int `json:"value,omitempty" rlp:"optional"`
|
Value *big.Int `json:"value,omitempty" rlp:"optional"`
|
||||||
revertedSnapshot bool
|
revertedSnapshot bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f callFrame) TypeString() string {
|
func (f CallFrame) TypeString() string {
|
||||||
return f.Type.String()
|
return f.Type.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f callFrame) failed() bool {
|
func (f CallFrame) failed() bool {
|
||||||
return len(f.Error) > 0 && f.revertedSnapshot
|
return len(f.Error) > 0 && f.revertedSnapshot
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *callFrame) processOutput(output []byte, err error, reverted bool) {
|
func (f *CallFrame) processOutput(output []byte, err error, reverted bool) {
|
||||||
output = common.CopyBytes(output)
|
output = common.CopyBytes(output)
|
||||||
// Clear error if tx wasn't reverted. This happened
|
// Clear error if tx wasn't reverted. This happened
|
||||||
// for pre-homestead contract storage OOG.
|
// for pre-homestead contract storage OOG.
|
||||||
|
|
@ -105,7 +101,7 @@ func (f *callFrame) processOutput(output []byte, err error, reverted bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type callFrameMarshaling struct {
|
type CallFrameMarshaling struct {
|
||||||
TypeString string `json:"type"`
|
TypeString string `json:"type"`
|
||||||
Gas hexutil.Uint64
|
Gas hexutil.Uint64
|
||||||
GasUsed hexutil.Uint64
|
GasUsed hexutil.Uint64
|
||||||
|
|
@ -115,7 +111,7 @@ type callFrameMarshaling struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type callTracer struct {
|
type callTracer struct {
|
||||||
callstack []callFrame
|
callstack []CallFrame
|
||||||
config callTracerConfig
|
config callTracerConfig
|
||||||
gasLimit uint64
|
gasLimit uint64
|
||||||
depth int
|
depth int
|
||||||
|
|
@ -153,9 +149,9 @@ func newCallTracerObject(ctx *tracers.Context, cfg json.RawMessage) (*callTracer
|
||||||
if err := json.Unmarshal(cfg, &config); err != nil {
|
if err := json.Unmarshal(cfg, &config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// First callframe contains tx context info
|
// First CallFrame contains tx context info
|
||||||
// and is populated on start and end.
|
// and is populated on start and end.
|
||||||
return &callTracer{callstack: make([]callFrame, 0, 1), config: config}, nil
|
return &callTracer{callstack: make([]CallFrame, 0, 1), config: config}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnEnter is called when EVM enters a new scope (via call, create or selfdestruct).
|
// OnEnter is called when EVM enters a new scope (via call, create or selfdestruct).
|
||||||
|
|
@ -170,7 +166,7 @@ func (t *callTracer) OnEnter(depth int, typ byte, from common.Address, to common
|
||||||
}
|
}
|
||||||
|
|
||||||
toCopy := to
|
toCopy := to
|
||||||
call := callFrame{
|
call := CallFrame{
|
||||||
Type: vm.OpCode(typ),
|
Type: vm.OpCode(typ),
|
||||||
From: from,
|
From: from,
|
||||||
To: &toCopy,
|
To: &toCopy,
|
||||||
|
|
@ -250,7 +246,7 @@ func (t *callTracer) OnLog(log *types.Log) {
|
||||||
if t.interrupt.Load() {
|
if t.interrupt.Load() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
l := callLog{
|
l := CallLog{
|
||||||
Address: log.Address,
|
Address: log.Address,
|
||||||
Topics: log.Topics,
|
Topics: log.Topics,
|
||||||
Data: log.Data,
|
Data: log.Data,
|
||||||
|
|
@ -279,9 +275,9 @@ func (t *callTracer) Stop(err error) {
|
||||||
t.interrupt.Store(true)
|
t.interrupt.Store(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// clearFailedLogs clears the logs of a callframe and all its children
|
// clearFailedLogs clears the logs of a CallFrame and all its children
|
||||||
// in case of execution failure.
|
// in case of execution failure.
|
||||||
func clearFailedLogs(cf *callFrame, parentFailed bool) {
|
func clearFailedLogs(cf *CallFrame, parentFailed bool) {
|
||||||
failed := cf.failed() || parentFailed
|
failed := cf.failed() || parentFailed
|
||||||
// Clear own logs
|
// Clear own logs
|
||||||
if failed {
|
if failed {
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ func (t *flatCallTracer) isPrecompiled(addr common.Address) bool {
|
||||||
return slices.Contains(t.activePrecompiles, addr)
|
return slices.Contains(t.activePrecompiles, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func flatFromNested(input *callFrame, traceAddress []int, convertErrs bool, ctx *tracers.Context) (output []flatCallFrame, err error) {
|
func flatFromNested(input *CallFrame, traceAddress []int, convertErrs bool, ctx *tracers.Context) (output []flatCallFrame, err error) {
|
||||||
var frame *flatCallFrame
|
var frame *flatCallFrame
|
||||||
switch input.Type {
|
switch input.Type {
|
||||||
case vm.CREATE, vm.CREATE2:
|
case vm.CREATE, vm.CREATE2:
|
||||||
|
|
@ -288,7 +288,7 @@ func flatFromNested(input *callFrame, traceAddress []int, convertErrs bool, ctx
|
||||||
return output, nil
|
return output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFlatCreate(input *callFrame) *flatCallFrame {
|
func newFlatCreate(input *CallFrame) *flatCallFrame {
|
||||||
var (
|
var (
|
||||||
actionInit = input.Input[:]
|
actionInit = input.Input[:]
|
||||||
resultCode = input.Output[:]
|
resultCode = input.Output[:]
|
||||||
|
|
@ -311,7 +311,7 @@ func newFlatCreate(input *callFrame) *flatCallFrame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFlatCall(input *callFrame) *flatCallFrame {
|
func newFlatCall(input *CallFrame) *flatCallFrame {
|
||||||
var (
|
var (
|
||||||
actionInput = input.Input[:]
|
actionInput = input.Input[:]
|
||||||
resultOutput = input.Output[:]
|
resultOutput = input.Output[:]
|
||||||
|
|
@ -334,7 +334,7 @@ func newFlatCall(input *callFrame) *flatCallFrame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFlatSelfdestruct(input *callFrame) *flatCallFrame {
|
func newFlatSelfdestruct(input *CallFrame) *flatCallFrame {
|
||||||
return &flatCallFrame{
|
return &flatCallFrame{
|
||||||
Type: "suicide",
|
Type: "suicide",
|
||||||
Action: flatCallAction{
|
Action: flatCallAction{
|
||||||
|
|
@ -345,20 +345,20 @@ func newFlatSelfdestruct(input *callFrame) *flatCallFrame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fillCallFrameFromContext(callFrame *flatCallFrame, ctx *tracers.Context) {
|
func fillCallFrameFromContext(CallFrame *flatCallFrame, ctx *tracers.Context) {
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ctx.BlockHash != (common.Hash{}) {
|
if ctx.BlockHash != (common.Hash{}) {
|
||||||
callFrame.BlockHash = &ctx.BlockHash
|
CallFrame.BlockHash = &ctx.BlockHash
|
||||||
}
|
}
|
||||||
if ctx.BlockNumber != nil {
|
if ctx.BlockNumber != nil {
|
||||||
callFrame.BlockNumber = ctx.BlockNumber.Uint64()
|
CallFrame.BlockNumber = ctx.BlockNumber.Uint64()
|
||||||
}
|
}
|
||||||
if ctx.TxHash != (common.Hash{}) {
|
if ctx.TxHash != (common.Hash{}) {
|
||||||
callFrame.TransactionHash = &ctx.TxHash
|
CallFrame.TransactionHash = &ctx.TxHash
|
||||||
}
|
}
|
||||||
callFrame.TransactionPosition = uint64(ctx.TxIndex)
|
CallFrame.TransactionPosition = uint64(ctx.TxIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertErrorToParity(call *flatCallFrame) {
|
func convertErrorToParity(call *flatCallFrame) {
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = (*callFrameMarshaling)(nil)
|
var _ = (*CallFrameMarshaling)(nil)
|
||||||
|
|
||||||
// MarshalJSON marshals as JSON.
|
// MarshalJSON marshals as JSON.
|
||||||
func (c callFrame) MarshalJSON() ([]byte, error) {
|
func (c CallFrame) MarshalJSON() ([]byte, error) {
|
||||||
type callFrame0 struct {
|
type CallFrame0 struct {
|
||||||
Type vm.OpCode `json:"type"`
|
Type vm.OpCode `json:"type"`
|
||||||
From common.Address `json:"from"`
|
From common.Address `json:"from"`
|
||||||
Gas hexutil.Uint64 `json:"gas"`
|
Gas hexutil.Uint64 `json:"gas"`
|
||||||
|
|
@ -25,12 +25,12 @@ func (c callFrame) MarshalJSON() ([]byte, error) {
|
||||||
Output hexutil.Bytes `json:"output,omitempty" rlp:"optional"`
|
Output hexutil.Bytes `json:"output,omitempty" rlp:"optional"`
|
||||||
Error string `json:"error,omitempty" rlp:"optional"`
|
Error string `json:"error,omitempty" rlp:"optional"`
|
||||||
RevertReason string `json:"revertReason,omitempty"`
|
RevertReason string `json:"revertReason,omitempty"`
|
||||||
Calls []callFrame `json:"calls,omitempty" rlp:"optional"`
|
Calls []CallFrame `json:"calls,omitempty" rlp:"optional"`
|
||||||
Logs []callLog `json:"logs,omitempty" rlp:"optional"`
|
Logs []CallLog `json:"logs,omitempty" rlp:"optional"`
|
||||||
Value *hexutil.Big `json:"value,omitempty" rlp:"optional"`
|
Value *hexutil.Big `json:"value,omitempty" rlp:"optional"`
|
||||||
TypeString string `json:"type"`
|
TypeString string `json:"type"`
|
||||||
}
|
}
|
||||||
var enc callFrame0
|
var enc CallFrame0
|
||||||
enc.Type = c.Type
|
enc.Type = c.Type
|
||||||
enc.From = c.From
|
enc.From = c.From
|
||||||
enc.Gas = hexutil.Uint64(c.Gas)
|
enc.Gas = hexutil.Uint64(c.Gas)
|
||||||
|
|
@ -48,8 +48,8 @@ func (c callFrame) MarshalJSON() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalJSON unmarshals from JSON.
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
func (c *callFrame) UnmarshalJSON(input []byte) error {
|
func (c *CallFrame) UnmarshalJSON(input []byte) error {
|
||||||
type callFrame0 struct {
|
type CallFrame0 struct {
|
||||||
Type *vm.OpCode `json:"type"`
|
Type *vm.OpCode `json:"type"`
|
||||||
From *common.Address `json:"from"`
|
From *common.Address `json:"from"`
|
||||||
Gas *hexutil.Uint64 `json:"gas"`
|
Gas *hexutil.Uint64 `json:"gas"`
|
||||||
|
|
@ -59,11 +59,11 @@ func (c *callFrame) UnmarshalJSON(input []byte) error {
|
||||||
Output *hexutil.Bytes `json:"output,omitempty" rlp:"optional"`
|
Output *hexutil.Bytes `json:"output,omitempty" rlp:"optional"`
|
||||||
Error *string `json:"error,omitempty" rlp:"optional"`
|
Error *string `json:"error,omitempty" rlp:"optional"`
|
||||||
RevertReason *string `json:"revertReason,omitempty"`
|
RevertReason *string `json:"revertReason,omitempty"`
|
||||||
Calls []callFrame `json:"calls,omitempty" rlp:"optional"`
|
Calls []CallFrame `json:"calls,omitempty" rlp:"optional"`
|
||||||
Logs []callLog `json:"logs,omitempty" rlp:"optional"`
|
Logs []CallLog `json:"logs,omitempty" rlp:"optional"`
|
||||||
Value *hexutil.Big `json:"value,omitempty" rlp:"optional"`
|
Value *hexutil.Big `json:"value,omitempty" rlp:"optional"`
|
||||||
}
|
}
|
||||||
var dec callFrame0
|
var dec CallFrame0
|
||||||
if err := json.Unmarshal(input, &dec); err != nil {
|
if err := json.Unmarshal(input, &dec); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue