gen_stenv.go 2.4 KB

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