gen_genesis_account.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. )
  11. var _ = (*genesisAccountMarshaling)(nil)
  12. func (g GenesisAccount) MarshalJSON() ([]byte, error) {
  13. type GenesisAccount struct {
  14. Code hexutil.Bytes `json:"code,omitempty"`
  15. Storage map[storageJSON]storageJSON `json:"storage,omitempty"`
  16. Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"`
  17. Nonce math.HexOrDecimal64 `json:"nonce,omitempty"`
  18. PrivateKey hexutil.Bytes `json:"secretKey,omitempty"`
  19. }
  20. var enc GenesisAccount
  21. enc.Code = g.Code
  22. if g.Storage != nil {
  23. enc.Storage = make(map[storageJSON]storageJSON, len(g.Storage))
  24. for k, v := range g.Storage {
  25. enc.Storage[storageJSON(k)] = storageJSON(v)
  26. }
  27. }
  28. enc.Balance = (*math.HexOrDecimal256)(g.Balance)
  29. enc.Nonce = math.HexOrDecimal64(g.Nonce)
  30. enc.PrivateKey = g.PrivateKey
  31. return json.Marshal(&enc)
  32. }
  33. func (g *GenesisAccount) UnmarshalJSON(input []byte) error {
  34. type GenesisAccount struct {
  35. Code *hexutil.Bytes `json:"code,omitempty"`
  36. Storage map[storageJSON]storageJSON `json:"storage,omitempty"`
  37. Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"`
  38. Nonce *math.HexOrDecimal64 `json:"nonce,omitempty"`
  39. PrivateKey *hexutil.Bytes `json:"secretKey,omitempty"`
  40. }
  41. var dec GenesisAccount
  42. if err := json.Unmarshal(input, &dec); err != nil {
  43. return err
  44. }
  45. if dec.Code != nil {
  46. g.Code = *dec.Code
  47. }
  48. if dec.Storage != nil {
  49. g.Storage = make(map[common.Hash]common.Hash, len(dec.Storage))
  50. for k, v := range dec.Storage {
  51. g.Storage[common.Hash(k)] = common.Hash(v)
  52. }
  53. }
  54. if dec.Balance == nil {
  55. return errors.New("missing required field 'balance' for GenesisAccount")
  56. }
  57. g.Balance = (*big.Int)(dec.Balance)
  58. if dec.Nonce != nil {
  59. g.Nonce = uint64(*dec.Nonce)
  60. }
  61. if dec.PrivateKey != nil {
  62. g.PrivateKey = *dec.PrivateKey
  63. }
  64. return nil
  65. }