From 05e52efbadb1ffcd91e9dcf2359b8f460cc02b53 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Mon, 2 Sep 2024 16:09:20 +0800 Subject: [PATCH] core/vm: marshall returnData as hexstring in trace logs (#21715) --- core/vm/gen_structlog.go | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/core/vm/gen_structlog.go b/core/vm/gen_structlog.go index 74c4ec39b3..1230944d57 100644 --- a/core/vm/gen_structlog.go +++ b/core/vm/gen_structlog.go @@ -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