gen_genesis_account.go 2.2 KB

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