github.com/luckypickle/go-ethereum-vet@v1.14.2/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/luckypickle/go-ethereum-vet/common" 11 "github.com/luckypickle/go-ethereum-vet/common/math" 12 ) 13 14 var _ = (*stEnvMarshaling)(nil) 15 16 func (s stEnv) MarshalJSON() ([]byte, error) { 17 type stEnv struct { 18 Coinbase common.UnprefixedAddress `json:"currentCoinbase" gencodec:"required"` 19 Difficulty *math.HexOrDecimal256 `json:"currentDifficulty" gencodec:"required"` 20 GasLimit math.HexOrDecimal64 `json:"currentGasLimit" gencodec:"required"` 21 Number math.HexOrDecimal64 `json:"currentNumber" gencodec:"required"` 22 Timestamp math.HexOrDecimal64 `json:"currentTimestamp" gencodec:"required"` 23 } 24 var enc stEnv 25 enc.Coinbase = common.UnprefixedAddress(s.Coinbase) 26 enc.Difficulty = (*math.HexOrDecimal256)(s.Difficulty) 27 enc.GasLimit = math.HexOrDecimal64(s.GasLimit) 28 enc.Number = math.HexOrDecimal64(s.Number) 29 enc.Timestamp = math.HexOrDecimal64(s.Timestamp) 30 return json.Marshal(&enc) 31 } 32 33 func (s *stEnv) UnmarshalJSON(input []byte) error { 34 type stEnv struct { 35 Coinbase *common.UnprefixedAddress `json:"currentCoinbase" gencodec:"required"` 36 Difficulty *math.HexOrDecimal256 `json:"currentDifficulty" gencodec:"required"` 37 GasLimit *math.HexOrDecimal64 `json:"currentGasLimit" gencodec:"required"` 38 Number *math.HexOrDecimal64 `json:"currentNumber" gencodec:"required"` 39 Timestamp *math.HexOrDecimal64 `json:"currentTimestamp" gencodec:"required"` 40 } 41 var dec stEnv 42 if err := json.Unmarshal(input, &dec); err != nil { 43 return err 44 } 45 if dec.Coinbase == nil { 46 return errors.New("missing required field 'currentCoinbase' for stEnv") 47 } 48 s.Coinbase = common.Address(*dec.Coinbase) 49 if dec.Difficulty == nil { 50 return errors.New("missing required field 'currentDifficulty' for stEnv") 51 } 52 s.Difficulty = (*big.Int)(dec.Difficulty) 53 if dec.GasLimit == nil { 54 return errors.New("missing required field 'currentGasLimit' for stEnv") 55 } 56 s.GasLimit = uint64(*dec.GasLimit) 57 if dec.Number == nil { 58 return errors.New("missing required field 'currentNumber' for stEnv") 59 } 60 s.Number = uint64(*dec.Number) 61 if dec.Timestamp == nil { 62 return errors.New("missing required field 'currentTimestamp' for stEnv") 63 } 64 s.Timestamp = uint64(*dec.Timestamp) 65 return nil 66 }