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