gen_genesis.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
  2. package core
  3. import (
  4. "encoding/json"
  5. "errors"
  6. "math/big"
  7. "github.com/ethereum/go-ethereum/common"
  8. "github.com/ethereum/go-ethereum/common/hexutil"
  9. "github.com/ethereum/go-ethereum/common/math"
  10. "github.com/ethereum/go-ethereum/params"
  11. )
  12. func (g Genesis) MarshalJSON() ([]byte, error) {
  13. type Genesis struct {
  14. Config *params.ChainConfig `json:"config"`
  15. Nonce math.HexOrDecimal64 `json:"nonce"`
  16. Timestamp math.HexOrDecimal64 `json:"timestamp"`
  17. ExtraData hexutil.Bytes `json:"extraData"`
  18. GasLimit math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"`
  19. Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"`
  20. Mixhash common.Hash `json:"mixHash"`
  21. Coinbase common.Address `json:"coinbase"`
  22. Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"`
  23. Number math.HexOrDecimal64 `json:"number"`
  24. GasUsed math.HexOrDecimal64 `json:"gasUsed"`
  25. ParentHash common.Hash `json:"parentHash"`
  26. }
  27. var enc Genesis
  28. enc.Config = g.Config
  29. enc.Nonce = math.HexOrDecimal64(g.Nonce)
  30. enc.Timestamp = math.HexOrDecimal64(g.Timestamp)
  31. enc.ExtraData = g.ExtraData
  32. enc.GasLimit = math.HexOrDecimal64(g.GasLimit)
  33. enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty)
  34. enc.Mixhash = g.Mixhash
  35. enc.Coinbase = g.Coinbase
  36. if g.Alloc != nil {
  37. enc.Alloc = make(map[common.UnprefixedAddress]GenesisAccount, len(g.Alloc))
  38. for k, v := range g.Alloc {
  39. enc.Alloc[common.UnprefixedAddress(k)] = v
  40. }
  41. }
  42. enc.Number = math.HexOrDecimal64(g.Number)
  43. enc.GasUsed = math.HexOrDecimal64(g.GasUsed)
  44. enc.ParentHash = g.ParentHash
  45. return json.Marshal(&enc)
  46. }
  47. func (g *Genesis) UnmarshalJSON(input []byte) error {
  48. type Genesis struct {
  49. Config *params.ChainConfig `json:"config"`
  50. Nonce *math.HexOrDecimal64 `json:"nonce"`
  51. Timestamp *math.HexOrDecimal64 `json:"timestamp"`
  52. ExtraData hexutil.Bytes `json:"extraData"`
  53. GasLimit *math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"`
  54. Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"`
  55. Mixhash *common.Hash `json:"mixHash"`
  56. Coinbase *common.Address `json:"coinbase"`
  57. Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"`
  58. Number *math.HexOrDecimal64 `json:"number"`
  59. GasUsed *math.HexOrDecimal64 `json:"gasUsed"`
  60. ParentHash *common.Hash `json:"parentHash"`
  61. }
  62. var dec Genesis
  63. if err := json.Unmarshal(input, &dec); err != nil {
  64. return err
  65. }
  66. if dec.Config != nil {
  67. g.Config = dec.Config
  68. }
  69. if dec.Nonce != nil {
  70. g.Nonce = uint64(*dec.Nonce)
  71. }
  72. if dec.Timestamp != nil {
  73. g.Timestamp = uint64(*dec.Timestamp)
  74. }
  75. if dec.ExtraData != nil {
  76. g.ExtraData = dec.ExtraData
  77. }
  78. if dec.GasLimit == nil {
  79. return errors.New("missing required field 'gasLimit' for Genesis")
  80. }
  81. g.GasLimit = uint64(*dec.GasLimit)
  82. if dec.Difficulty == nil {
  83. return errors.New("missing required field 'difficulty' for Genesis")
  84. }
  85. g.Difficulty = (*big.Int)(dec.Difficulty)
  86. if dec.Mixhash != nil {
  87. g.Mixhash = *dec.Mixhash
  88. }
  89. if dec.Coinbase != nil {
  90. g.Coinbase = *dec.Coinbase
  91. }
  92. if dec.Alloc == nil {
  93. return errors.New("missing required field 'alloc' for Genesis")
  94. }
  95. g.Alloc = make(GenesisAlloc, len(dec.Alloc))
  96. for k, v := range dec.Alloc {
  97. g.Alloc[common.Address(k)] = v
  98. }
  99. if dec.Number != nil {
  100. g.Number = uint64(*dec.Number)
  101. }
  102. if dec.GasUsed != nil {
  103. g.GasUsed = uint64(*dec.GasUsed)
  104. }
  105. if dec.ParentHash != nil {
  106. g.ParentHash = *dec.ParentHash
  107. }
  108. return nil
  109. }