gen_stenv.go 2.3 KB

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