core/vm: marshall returnData as hexstring in trace logs (#21715)

This commit is contained in:
Daniel Liu 2024-09-02 16:09:20 +08:00 committed by Daniel Liu
parent 4e832ee6f0
commit 05e52efbad

View file

@ -6,30 +6,36 @@ import (
"encoding/json" "encoding/json"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
"github.com/XinFinOrg/XDPoSChain/common/math"
"github.com/holiman/uint256" "github.com/holiman/uint256"
) )
var _ = (*structLogMarshaling)(nil)
// MarshalJSON marshals as JSON. // MarshalJSON marshals as JSON.
func (s StructLog) MarshalJSON() ([]byte, error) { func (s StructLog) MarshalJSON() ([]byte, error) {
type StructLog struct { type StructLog struct {
Pc uint64 `json:"pc"` Pc uint64 `json:"pc"`
Op OpCode `json:"op"` Op OpCode `json:"op"`
Gas uint64 `json:"gas"` Gas math.HexOrDecimal64 `json:"gas"`
GasCost uint64 `json:"gasCost"` GasCost math.HexOrDecimal64 `json:"gasCost"`
Memory []byte `json:"memory"` Memory hexutil.Bytes `json:"memory"`
MemorySize int `json:"memSize"` MemorySize int `json:"memSize"`
Stack []uint256.Int `json:"stack"` Stack []uint256.Int `json:"stack"`
ReturnData []byte `json:"returnData"` ReturnData hexutil.Bytes `json:"returnData"`
Storage map[common.Hash]common.Hash `json:"-"` Storage map[common.Hash]common.Hash `json:"-"`
Depth int `json:"depth"` Depth int `json:"depth"`
RefundCounter uint64 `json:"refund"` RefundCounter uint64 `json:"refund"`
Err error `json:"-"` Err error `json:"-"`
OpName string `json:"opName"`
ErrorString string `json:"error"`
} }
var enc StructLog var enc StructLog
enc.Pc = s.Pc enc.Pc = s.Pc
enc.Op = s.Op enc.Op = s.Op
enc.Gas = s.Gas enc.Gas = math.HexOrDecimal64(s.Gas)
enc.GasCost = s.GasCost enc.GasCost = math.HexOrDecimal64(s.GasCost)
enc.Memory = s.Memory enc.Memory = s.Memory
enc.MemorySize = s.MemorySize enc.MemorySize = s.MemorySize
enc.Stack = s.Stack enc.Stack = s.Stack
@ -38,6 +44,8 @@ func (s StructLog) MarshalJSON() ([]byte, error) {
enc.Depth = s.Depth enc.Depth = s.Depth
enc.RefundCounter = s.RefundCounter enc.RefundCounter = s.RefundCounter
enc.Err = s.Err enc.Err = s.Err
enc.OpName = s.OpName()
enc.ErrorString = s.ErrorString()
return json.Marshal(&enc) return json.Marshal(&enc)
} }
@ -46,12 +54,12 @@ func (s *StructLog) UnmarshalJSON(input []byte) error {
type StructLog struct { type StructLog struct {
Pc *uint64 `json:"pc"` Pc *uint64 `json:"pc"`
Op *OpCode `json:"op"` Op *OpCode `json:"op"`
Gas *uint64 `json:"gas"` Gas *math.HexOrDecimal64 `json:"gas"`
GasCost *uint64 `json:"gasCost"` GasCost *math.HexOrDecimal64 `json:"gasCost"`
Memory []byte `json:"memory"` Memory *hexutil.Bytes `json:"memory"`
MemorySize *int `json:"memSize"` MemorySize *int `json:"memSize"`
Stack []uint256.Int `json:"stack"` Stack []uint256.Int `json:"stack"`
ReturnData []byte `json:"returnData"` ReturnData *hexutil.Bytes `json:"returnData"`
Storage map[common.Hash]common.Hash `json:"-"` Storage map[common.Hash]common.Hash `json:"-"`
Depth *int `json:"depth"` Depth *int `json:"depth"`
RefundCounter *uint64 `json:"refund"` RefundCounter *uint64 `json:"refund"`
@ -68,13 +76,13 @@ func (s *StructLog) UnmarshalJSON(input []byte) error {
s.Op = *dec.Op s.Op = *dec.Op
} }
if dec.Gas != nil { if dec.Gas != nil {
s.Gas = *dec.Gas s.Gas = uint64(*dec.Gas)
} }
if dec.GasCost != nil { if dec.GasCost != nil {
s.GasCost = *dec.GasCost s.GasCost = uint64(*dec.GasCost)
} }
if dec.Memory != nil { if dec.Memory != nil {
s.Memory = dec.Memory s.Memory = *dec.Memory
} }
if dec.MemorySize != nil { if dec.MemorySize != nil {
s.MemorySize = *dec.MemorySize s.MemorySize = *dec.MemorySize
@ -83,7 +91,7 @@ func (s *StructLog) UnmarshalJSON(input []byte) error {
s.Stack = dec.Stack s.Stack = dec.Stack
} }
if dec.ReturnData != nil { if dec.ReturnData != nil {
s.ReturnData = dec.ReturnData s.ReturnData = *dec.ReturnData
} }
if dec.Storage != nil { if dec.Storage != nil {
s.Storage = dec.Storage s.Storage = dec.Storage