github.com/core-coin/go-core/v2@v2.1.9/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 "github.com/core-coin/go-core/v2/common" 11 "github.com/core-coin/go-core/v2/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 EnergyLimit math.HexOrDecimal64 `json:"currentEnergyLimit" gencodec:"required"` 22 Number math.HexOrDecimal64 `json:"currentNumber" gencodec:"required"` 23 Timestamp math.HexOrDecimal64 `json:"currentTimestamp" gencodec:"required"` 24 } 25 var enc stEnv 26 enc.Coinbase = common.UnprefixedAddress(s.Coinbase) 27 enc.Difficulty = (*math.HexOrDecimal256)(s.Difficulty) 28 enc.EnergyLimit = math.HexOrDecimal64(s.EnergyLimit) 29 enc.Number = math.HexOrDecimal64(s.Number) 30 enc.Timestamp = math.HexOrDecimal64(s.Timestamp) 31 return json.Marshal(&enc) 32 } 33 34 // UnmarshalJSON unmarshals from JSON. 35 func (s *stEnv) UnmarshalJSON(input []byte) error { 36 type stEnv struct { 37 Coinbase *common.UnprefixedAddress `json:"currentCoinbase" gencodec:"required"` 38 Difficulty *math.HexOrDecimal256 `json:"currentDifficulty" gencodec:"required"` 39 EnergyLimit *math.HexOrDecimal64 `json:"currentEnergyLimit" gencodec:"required"` 40 Number *math.HexOrDecimal64 `json:"currentNumber" gencodec:"required"` 41 Timestamp *math.HexOrDecimal64 `json:"currentTimestamp" gencodec:"required"` 42 } 43 var dec stEnv 44 if err := json.Unmarshal(input, &dec); err != nil { 45 return err 46 } 47 if dec.Coinbase == nil { 48 return errors.New("missing required field 'currentCoinbase' for stEnv") 49 } 50 s.Coinbase = common.Address(*dec.Coinbase) 51 if dec.Difficulty == nil { 52 return errors.New("missing required field 'currentDifficulty' for stEnv") 53 } 54 s.Difficulty = (*big.Int)(dec.Difficulty) 55 if dec.EnergyLimit == nil { 56 return errors.New("missing required field 'currentEnergyLimit' for stEnv") 57 } 58 s.EnergyLimit = uint64(*dec.EnergyLimit) 59 if dec.Number == nil { 60 return errors.New("missing required field 'currentNumber' for stEnv") 61 } 62 s.Number = uint64(*dec.Number) 63 if dec.Timestamp == nil { 64 return errors.New("missing required field 'currentTimestamp' for stEnv") 65 } 66 s.Timestamp = uint64(*dec.Timestamp) 67 return nil 68 }