gen_genesis.go 3.6 KB

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