gitee.com/liu-zhao234568/cntest@v1.0.0/tests/gen_stenv.go (about) 1 // Code generated by github.com/fjl/gencodec. DO NOT EDIT. 2 3 package tests 4 5 import ( 6 "encoding/json" 7 "errors" 8 "math/big" 9 10 "gitee.com/liu-zhao234568/cntest/common" 11 "gitee.com/liu-zhao234568/cntest/common/math" 12 ) 13 14 var _ = (*stEnvMarshaling)(nil) 15 16 // MarshalJSON marshals as JSON. 17 func (s stEnv) MarshalJSON() ([]byte, error) { 18 type stEnv struct { 19 Coinbase common.UnprefixedAddress `json:"currentCoinbase" gencodec:"required"` 20 Difficulty *math.HexOrDecimal256 `json:"currentDifficulty" gencodec:"required"` 21 GasLimit math.HexOrDecimal64 `json:"currentGasLimit" gencodec:"required"` 22 Number math.HexOrDecimal64 `json:"currentNumber" gencodec:"required"` 23 Timestamp math.HexOrDecimal64 `json:"currentTimestamp" gencodec:"required"` 24 BaseFee *math.HexOrDecimal256 `json:"currentBaseFee" gencodec:"optional"` 25 } 26 var enc stEnv 27 enc.Coinbase = common.UnprefixedAddress(s.Coinbase) 28 enc.Difficulty = (*math.HexOrDecimal256)(s.Difficulty) 29 enc.GasLimit = math.HexOrDecimal64(s.GasLimit) 30 enc.Number = math.HexOrDecimal64(s.Number) 31 enc.Timestamp = math.HexOrDecimal64(s.Timestamp) 32 enc.BaseFee = (*math.HexOrDecimal256)(s.BaseFee) 33 return json.Marshal(&enc) 34 } 35 36 // UnmarshalJSON unmarshals from JSON. 37 func (s *stEnv) UnmarshalJSON(input []byte) error { 38 type stEnv struct { 39 Coinbase *common.UnprefixedAddress `json:"currentCoinbase" gencodec:"required"` 40 Difficulty *math.HexOrDecimal256 `json:"currentDifficulty" gencodec:"required"` 41 GasLimit *math.HexOrDecimal64 `json:"currentGasLimit" gencodec:"required"` 42 Number *math.HexOrDecimal64 `json:"currentNumber" gencodec:"required"` 43 Timestamp *math.HexOrDecimal64 `json:"currentTimestamp" gencodec:"required"` 44 BaseFee *math.HexOrDecimal256 `json:"currentBaseFee" gencodec:"optional"` 45 } 46 var dec stEnv 47 if err := json.Unmarshal(input, &dec); err != nil { 48 return err 49 } 50 if dec.Coinbase == nil { 51 return errors.New("missing required field 'currentCoinbase' for stEnv") 52 } 53 s.Coinbase = common.Address(*dec.Coinbase) 54 if dec.Difficulty == nil { 55 return errors.New("missing required field 'currentDifficulty' for stEnv") 56 } 57 s.Difficulty = (*big.Int)(dec.Difficulty) 58 if dec.GasLimit == nil { 59 return errors.New("missing required field 'currentGasLimit' for stEnv") 60 } 61 s.GasLimit = uint64(*dec.GasLimit) 62 if dec.Number == nil { 63 return errors.New("missing required field 'currentNumber' for stEnv") 64 } 65 s.Number = uint64(*dec.Number) 66 if dec.Timestamp == nil { 67 return errors.New("missing required field 'currentTimestamp' for stEnv") 68 } 69 s.Timestamp = uint64(*dec.Timestamp) 70 if dec.BaseFee != nil { 71 s.BaseFee = (*big.Int)(dec.BaseFee) 72 } 73 return nil 74 }