github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/core/vm/gen_structlog.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:35</date> 10 //</624342621807972352> 11 12 //代码由github.com/fjl/gencodec生成。不要编辑。 13 14 package vm 15 16 import ( 17 "encoding/json" 18 "math/big" 19 20 "github.com/ethereum/go-ethereum/common" 21 "github.com/ethereum/go-ethereum/common/hexutil" 22 "github.com/ethereum/go-ethereum/common/math" 23 ) 24 25 var _ = (*structLogMarshaling)(nil) 26 27 func (s StructLog) MarshalJSON() ([]byte, error) { 28 type StructLog struct { 29 Pc uint64 `json:"pc"` 30 Op OpCode `json:"op"` 31 Gas math.HexOrDecimal64 `json:"gas"` 32 GasCost math.HexOrDecimal64 `json:"gasCost"` 33 Memory hexutil.Bytes `json:"memory"` 34 MemorySize int `json:"memSize"` 35 Stack []*math.HexOrDecimal256 `json:"stack"` 36 Storage map[common.Hash]common.Hash `json:"-"` 37 Depth int `json:"depth"` 38 Err error `json:"-"` 39 OpName string `json:"opName"` 40 ErrorString string `json:"error"` 41 } 42 var enc StructLog 43 enc.Pc = s.Pc 44 enc.Op = s.Op 45 enc.Gas = math.HexOrDecimal64(s.Gas) 46 enc.GasCost = math.HexOrDecimal64(s.GasCost) 47 enc.Memory = s.Memory 48 enc.MemorySize = s.MemorySize 49 if s.Stack != nil { 50 enc.Stack = make([]*math.HexOrDecimal256, len(s.Stack)) 51 for k, v := range s.Stack { 52 enc.Stack[k] = (*math.HexOrDecimal256)(v) 53 } 54 } 55 enc.Storage = s.Storage 56 enc.Depth = s.Depth 57 enc.Err = s.Err 58 enc.OpName = s.OpName() 59 enc.ErrorString = s.ErrorString() 60 return json.Marshal(&enc) 61 } 62 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 Storage map[common.Hash]common.Hash `json:"-"` 73 Depth *int `json:"depth"` 74 Err error `json:"-"` 75 } 76 var dec StructLog 77 if err := json.Unmarshal(input, &dec); err != nil { 78 return err 79 } 80 if dec.Pc != nil { 81 s.Pc = *dec.Pc 82 } 83 if dec.Op != nil { 84 s.Op = *dec.Op 85 } 86 if dec.Gas != nil { 87 s.Gas = uint64(*dec.Gas) 88 } 89 if dec.GasCost != nil { 90 s.GasCost = uint64(*dec.GasCost) 91 } 92 if dec.Memory != nil { 93 s.Memory = *dec.Memory 94 } 95 if dec.MemorySize != nil { 96 s.MemorySize = *dec.MemorySize 97 } 98 if dec.Stack != nil { 99 s.Stack = make([]*big.Int, len(dec.Stack)) 100 for k, v := range dec.Stack { 101 s.Stack[k] = (*big.Int)(v) 102 } 103 } 104 if dec.Storage != nil { 105 s.Storage = dec.Storage 106 } 107 if dec.Depth != nil { 108 s.Depth = *dec.Depth 109 } 110 if dec.Err != nil { 111 s.Err = dec.Err 112 } 113 return nil 114 } 115