gen_difficultytest.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
  2. package tests
  3. import (
  4. "encoding/json"
  5. "math/big"
  6. "github.com/ethereum/go-ethereum/common"
  7. "github.com/ethereum/go-ethereum/common/math"
  8. )
  9. var _ = (*difficultyTestMarshaling)(nil)
  10. // MarshalJSON marshals as JSON.
  11. func (d DifficultyTest) MarshalJSON() ([]byte, error) {
  12. type DifficultyTest struct {
  13. ParentTimestamp math.HexOrDecimal64 `json:"parentTimestamp"`
  14. ParentDifficulty *math.HexOrDecimal256 `json:"parentDifficulty"`
  15. UncleHash common.Hash `json:"parentUncles"`
  16. CurrentTimestamp math.HexOrDecimal64 `json:"currentTimestamp"`
  17. CurrentBlockNumber math.HexOrDecimal64 `json:"currentBlockNumber"`
  18. CurrentDifficulty *math.HexOrDecimal256 `json:"currentDifficulty"`
  19. }
  20. var enc DifficultyTest
  21. enc.ParentTimestamp = math.HexOrDecimal64(d.ParentTimestamp)
  22. enc.ParentDifficulty = (*math.HexOrDecimal256)(d.ParentDifficulty)
  23. enc.UncleHash = d.UncleHash
  24. enc.CurrentTimestamp = math.HexOrDecimal64(d.CurrentTimestamp)
  25. enc.CurrentBlockNumber = math.HexOrDecimal64(d.CurrentBlockNumber)
  26. enc.CurrentDifficulty = (*math.HexOrDecimal256)(d.CurrentDifficulty)
  27. return json.Marshal(&enc)
  28. }
  29. // UnmarshalJSON unmarshals from JSON.
  30. func (d *DifficultyTest) UnmarshalJSON(input []byte) error {
  31. type DifficultyTest struct {
  32. ParentTimestamp *math.HexOrDecimal64 `json:"parentTimestamp"`
  33. ParentDifficulty *math.HexOrDecimal256 `json:"parentDifficulty"`
  34. UncleHash *common.Hash `json:"parentUncles"`
  35. CurrentTimestamp *math.HexOrDecimal64 `json:"currentTimestamp"`
  36. CurrentBlockNumber *math.HexOrDecimal64 `json:"currentBlockNumber"`
  37. CurrentDifficulty *math.HexOrDecimal256 `json:"currentDifficulty"`
  38. }
  39. var dec DifficultyTest
  40. if err := json.Unmarshal(input, &dec); err != nil {
  41. return err
  42. }
  43. if dec.ParentTimestamp != nil {
  44. d.ParentTimestamp = uint64(*dec.ParentTimestamp)
  45. }
  46. if dec.ParentDifficulty != nil {
  47. d.ParentDifficulty = (*big.Int)(dec.ParentDifficulty)
  48. }
  49. if dec.UncleHash != nil {
  50. d.UncleHash = *dec.UncleHash
  51. }
  52. if dec.CurrentTimestamp != nil {
  53. d.CurrentTimestamp = uint64(*dec.CurrentTimestamp)
  54. }
  55. if dec.CurrentBlockNumber != nil {
  56. d.CurrentBlockNumber = uint64(*dec.CurrentBlockNumber)
  57. }
  58. if dec.CurrentDifficulty != nil {
  59. d.CurrentDifficulty = (*big.Int)(dec.CurrentDifficulty)
  60. }
  61. return nil
  62. }