gen_stenv.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
  2. package t8ntool
  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"`
  16. Random *math.HexOrDecimal256 `json:"currentRandom"`
  17. ParentDifficulty *math.HexOrDecimal256 `json:"parentDifficulty"`
  18. GasLimit math.HexOrDecimal64 `json:"currentGasLimit" gencodec:"required"`
  19. Number math.HexOrDecimal64 `json:"currentNumber" gencodec:"required"`
  20. Timestamp math.HexOrDecimal64 `json:"currentTimestamp" gencodec:"required"`
  21. ParentTimestamp math.HexOrDecimal64 `json:"parentTimestamp,omitempty"`
  22. BlockHashes map[math.HexOrDecimal64]common.Hash `json:"blockHashes,omitempty"`
  23. Ommers []ommer `json:"ommers,omitempty"`
  24. BaseFee *math.HexOrDecimal256 `json:"currentBaseFee,omitempty"`
  25. ParentUncleHash common.Hash `json:"parentUncleHash"`
  26. }
  27. var enc stEnv
  28. enc.Coinbase = common.UnprefixedAddress(s.Coinbase)
  29. enc.Difficulty = (*math.HexOrDecimal256)(s.Difficulty)
  30. enc.Random = (*math.HexOrDecimal256)(s.Random)
  31. enc.ParentDifficulty = (*math.HexOrDecimal256)(s.ParentDifficulty)
  32. enc.GasLimit = math.HexOrDecimal64(s.GasLimit)
  33. enc.Number = math.HexOrDecimal64(s.Number)
  34. enc.Timestamp = math.HexOrDecimal64(s.Timestamp)
  35. enc.ParentTimestamp = math.HexOrDecimal64(s.ParentTimestamp)
  36. enc.BlockHashes = s.BlockHashes
  37. enc.Ommers = s.Ommers
  38. enc.BaseFee = (*math.HexOrDecimal256)(s.BaseFee)
  39. enc.ParentUncleHash = s.ParentUncleHash
  40. return json.Marshal(&enc)
  41. }
  42. // UnmarshalJSON unmarshals from JSON.
  43. func (s *stEnv) UnmarshalJSON(input []byte) error {
  44. type stEnv struct {
  45. Coinbase *common.UnprefixedAddress `json:"currentCoinbase" gencodec:"required"`
  46. Difficulty *math.HexOrDecimal256 `json:"currentDifficulty"`
  47. Random *math.HexOrDecimal256 `json:"currentRandom"`
  48. ParentDifficulty *math.HexOrDecimal256 `json:"parentDifficulty"`
  49. GasLimit *math.HexOrDecimal64 `json:"currentGasLimit" gencodec:"required"`
  50. Number *math.HexOrDecimal64 `json:"currentNumber" gencodec:"required"`
  51. Timestamp *math.HexOrDecimal64 `json:"currentTimestamp" gencodec:"required"`
  52. ParentTimestamp *math.HexOrDecimal64 `json:"parentTimestamp,omitempty"`
  53. BlockHashes map[math.HexOrDecimal64]common.Hash `json:"blockHashes,omitempty"`
  54. Ommers []ommer `json:"ommers,omitempty"`
  55. BaseFee *math.HexOrDecimal256 `json:"currentBaseFee,omitempty"`
  56. ParentUncleHash *common.Hash `json:"parentUncleHash"`
  57. }
  58. var dec stEnv
  59. if err := json.Unmarshal(input, &dec); err != nil {
  60. return err
  61. }
  62. if dec.Coinbase == nil {
  63. return errors.New("missing required field 'currentCoinbase' for stEnv")
  64. }
  65. s.Coinbase = common.Address(*dec.Coinbase)
  66. if dec.Difficulty != nil {
  67. s.Difficulty = (*big.Int)(dec.Difficulty)
  68. }
  69. if dec.Random != nil {
  70. s.Random = (*big.Int)(dec.Random)
  71. }
  72. if dec.ParentDifficulty != nil {
  73. s.ParentDifficulty = (*big.Int)(dec.ParentDifficulty)
  74. }
  75. if dec.GasLimit == nil {
  76. return errors.New("missing required field 'currentGasLimit' for stEnv")
  77. }
  78. s.GasLimit = uint64(*dec.GasLimit)
  79. if dec.Number == nil {
  80. return errors.New("missing required field 'currentNumber' for stEnv")
  81. }
  82. s.Number = uint64(*dec.Number)
  83. if dec.Timestamp == nil {
  84. return errors.New("missing required field 'currentTimestamp' for stEnv")
  85. }
  86. s.Timestamp = uint64(*dec.Timestamp)
  87. if dec.ParentTimestamp != nil {
  88. s.ParentTimestamp = uint64(*dec.ParentTimestamp)
  89. }
  90. if dec.BlockHashes != nil {
  91. s.BlockHashes = dec.BlockHashes
  92. }
  93. if dec.Ommers != nil {
  94. s.Ommers = dec.Ommers
  95. }
  96. if dec.BaseFee != nil {
  97. s.BaseFee = (*big.Int)(dec.BaseFee)
  98. }
  99. if dec.ParentUncleHash != nil {
  100. s.ParentUncleHash = *dec.ParentUncleHash
  101. }
  102. return nil
  103. }