gen_genesis.go 4.1 KB

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