github.com/zhiqiangxu/go-ethereum@v1.9.16-0.20210824055606-be91cfdebc48/core/vm/gen_structlog.go (about) 1 // Code generated by github.com/fjl/gencodec. DO NOT EDIT. 2 3 package vm 4 5 import ( 6 "encoding/json" 7 "math/big" 8 9 "github.com/zhiqiangxu/go-ethereum/common" 10 "github.com/zhiqiangxu/go-ethereum/common/hexutil" 11 "github.com/zhiqiangxu/go-ethereum/common/math" 12 ) 13 14 var _ = (*structLogMarshaling)(nil) 15 16 // MarshalJSON marshals as JSON. 17 func (s StructLog) MarshalJSON() ([]byte, error) { 18 type StructLog struct { 19 Pc uint64 `json:"pc"` 20 Op OpCode `json:"op"` 21 Gas math.HexOrDecimal64 `json:"gas"` 22 GasCost math.HexOrDecimal64 `json:"gasCost"` 23 Memory hexutil.Bytes `json:"memory"` 24 MemorySize int `json:"memSize"` 25 Stack []*math.HexOrDecimal256 `json:"stack"` 26 ReturnStack []math.HexOrDecimal64 `json:"returnStack"` 27 Storage map[common.Hash]common.Hash `json:"-"` 28 Depth int `json:"depth"` 29 RefundCounter uint64 `json:"refund"` 30 Err error `json:"-"` 31 OpName string `json:"opName"` 32 ErrorString string `json:"error"` 33 } 34 var enc StructLog 35 enc.Pc = s.Pc 36 enc.Op = s.Op 37 enc.Gas = math.HexOrDecimal64(s.Gas) 38 enc.GasCost = math.HexOrDecimal64(s.GasCost) 39 enc.Memory = s.Memory 40 enc.MemorySize = s.MemorySize 41 if s.Stack != nil { 42 enc.Stack = make([]*math.HexOrDecimal256, len(s.Stack)) 43 for k, v := range s.Stack { 44 enc.Stack[k] = (*math.HexOrDecimal256)(v) 45 } 46 } 47 if s.ReturnStack != nil { 48 enc.ReturnStack = make([]math.HexOrDecimal64, len(s.ReturnStack)) 49 for k, v := range s.ReturnStack { 50 enc.ReturnStack[k] = math.HexOrDecimal64(v) 51 } 52 } 53 enc.Storage = s.Storage 54 enc.Depth = s.Depth 55 enc.RefundCounter = s.RefundCounter 56 enc.Err = s.Err 57 enc.OpName = s.OpName() 58 enc.ErrorString = s.ErrorString() 59 return json.Marshal(&enc) 60 } 61 62 // UnmarshalJSON unmarshals from JSON. 63 func (s *StructLog) UnmarshalJSON(input []byte) error { 64 type StructLog struct { 65 Pc *uint64 `json:"pc"` 66 Op *OpCode `json:"op"` 67 Gas *math.HexOrDecimal64 `json:"gas"` 68 GasCost *math.HexOrDecimal64 `json:"gasCost"` 69 Memory *hexutil.Bytes `json:"memory"` 70 MemorySize *int `json:"memSize"` 71 Stack []*math.HexOrDecimal256 `json:"stack"` 72 ReturnStack []math.HexOrDecimal64 `json:"returnStack"` 73 Storage map[common.Hash]common.Hash `json:"-"` 74 Depth *int `json:"depth"` 75 RefundCounter *uint64 `json:"refund"` 76 Err error `json:"-"` 77 } 78 var dec StructLog 79 if err := json.Unmarshal(input, &dec); err != nil { 80 return err 81 } 82 if dec.Pc != nil { 83 s.Pc = *dec.Pc 84 } 85 if dec.Op != nil { 86 s.Op = *dec.Op 87 } 88 if dec.Gas != nil { 89 s.Gas = uint64(*dec.Gas) 90 } 91 if dec.GasCost != nil { 92 s.GasCost = uint64(*dec.GasCost) 93 } 94 if dec.Memory != nil { 95 s.Memory = *dec.Memory 96 } 97 if dec.MemorySize != nil { 98 s.MemorySize = *dec.MemorySize 99 } 100 if dec.Stack != nil { 101 s.Stack = make([]*big.Int, len(dec.Stack)) 102 for k, v := range dec.Stack { 103 s.Stack[k] = (*big.Int)(v) 104 } 105 } 106 if dec.ReturnStack != nil { 107 s.ReturnStack = make([]uint64, len(dec.ReturnStack)) 108 for k, v := range dec.ReturnStack { 109 s.ReturnStack[k] = uint64(v) 110 } 111 } 112 if dec.Storage != nil { 113 s.Storage = dec.Storage 114 } 115 if dec.Depth != nil { 116 s.Depth = *dec.Depth 117 } 118 if dec.RefundCounter != nil { 119 s.RefundCounter = *dec.RefundCounter 120 } 121 if dec.Err != nil { 122 s.Err = dec.Err 123 } 124 return nil 125 }