gen_stenv.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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:"optional"`
  16. Random *math.HexOrDecimal256 `json:"currentRandom" gencodec:"optional"`
  17. GasLimit math.HexOrDecimal64 `json:"currentGasLimit" gencodec:"required"`
  18. Number math.HexOrDecimal64 `json:"currentNumber" gencodec:"required"`
  19. Timestamp math.HexOrDecimal64 `json:"currentTimestamp" gencodec:"required"`
  20. BaseFee *math.HexOrDecimal256 `json:"currentBaseFee" gencodec:"optional"`
  21. }
  22. var enc stEnv
  23. enc.Coinbase = common.UnprefixedAddress(s.Coinbase)
  24. enc.Difficulty = (*math.HexOrDecimal256)(s.Difficulty)
  25. enc.Random = (*math.HexOrDecimal256)(s.Random)
  26. enc.GasLimit = math.HexOrDecimal64(s.GasLimit)
  27. enc.Number = math.HexOrDecimal64(s.Number)
  28. enc.Timestamp = math.HexOrDecimal64(s.Timestamp)
  29. enc.BaseFee = (*math.HexOrDecimal256)(s.BaseFee)
  30. return json.Marshal(&enc)
  31. }
  32. // UnmarshalJSON unmarshals from JSON.
  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:"optional"`
  37. Random *math.HexOrDecimal256 `json:"currentRandom" gencodec:"optional"`
  38. GasLimit *math.HexOrDecimal64 `json:"currentGasLimit" gencodec:"required"`
  39. Number *math.HexOrDecimal64 `json:"currentNumber" gencodec:"required"`
  40. Timestamp *math.HexOrDecimal64 `json:"currentTimestamp" gencodec:"required"`
  41. BaseFee *math.HexOrDecimal256 `json:"currentBaseFee" gencodec:"optional"`
  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. s.Difficulty = (*big.Int)(dec.Difficulty)
  53. }
  54. if dec.Random != nil {
  55. s.Random = (*big.Int)(dec.Random)
  56. }
  57. if dec.GasLimit == nil {
  58. return errors.New("missing required field 'currentGasLimit' for stEnv")
  59. }
  60. s.GasLimit = uint64(*dec.GasLimit)
  61. if dec.Number == nil {
  62. return errors.New("missing required field 'currentNumber' for stEnv")
  63. }
  64. s.Number = uint64(*dec.Number)
  65. if dec.Timestamp == nil {
  66. return errors.New("missing required field 'currentTimestamp' for stEnv")
  67. }
  68. s.Timestamp = uint64(*dec.Timestamp)
  69. if dec.BaseFee != nil {
  70. s.BaseFee = (*big.Int)(dec.BaseFee)
  71. }
  72. return nil
  73. }