gen_genesis.go 4.4 KB

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