gen_stenv.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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" 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. BlockHashes map[math.HexOrDecimal64]common.Hash `json:"blockHashes,omitempty"`
  20. Ommers []ommer `json:"ommers,omitempty"`
  21. }
  22. var enc stEnv
  23. enc.Coinbase = common.UnprefixedAddress(s.Coinbase)
  24. enc.Difficulty = (*math.HexOrDecimal256)(s.Difficulty)
  25. enc.GasLimit = math.HexOrDecimal64(s.GasLimit)
  26. enc.Number = math.HexOrDecimal64(s.Number)
  27. enc.Timestamp = math.HexOrDecimal64(s.Timestamp)
  28. enc.BlockHashes = s.BlockHashes
  29. enc.Ommers = s.Ommers
  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:"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. BlockHashes map[math.HexOrDecimal64]common.Hash `json:"blockHashes,omitempty"`
  41. Ommers []ommer `json:"ommers,omitempty"`
  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.GasLimit == nil {
  56. return errors.New("missing required field 'currentGasLimit' for stEnv")
  57. }
  58. s.GasLimit = uint64(*dec.GasLimit)
  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. if dec.BlockHashes != nil {
  68. s.BlockHashes = dec.BlockHashes
  69. }
  70. if dec.Ommers != nil {
  71. s.Ommers = dec.Ommers
  72. }
  73. return nil
  74. }