gen_genesis.go 3.8 KB

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