gen_genesis_account.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. func (g GenesisAccount) MarshalJSON() ([]byte, error) {
  12. type GenesisAccountJSON struct {
  13. Code hexutil.Bytes `json:"code,omitempty" optional:"true"`
  14. Storage map[common.Hash]common.Hash `json:"storage,omitempty" optional:"true"`
  15. Balance *math.HexOrDecimal256 `json:"balance"`
  16. Nonce math.HexOrDecimal64 `json:"nonce,omitempty" optional:"true"`
  17. }
  18. var enc GenesisAccountJSON
  19. enc.Code = g.Code
  20. enc.Storage = g.Storage
  21. enc.Balance = (*math.HexOrDecimal256)(g.Balance)
  22. enc.Nonce = math.HexOrDecimal64(g.Nonce)
  23. return json.Marshal(&enc)
  24. }
  25. func (g *GenesisAccount) UnmarshalJSON(input []byte) error {
  26. type GenesisAccountJSON struct {
  27. Code hexutil.Bytes `json:"code,omitempty" optional:"true"`
  28. Storage map[common.Hash]common.Hash `json:"storage,omitempty" optional:"true"`
  29. Balance *math.HexOrDecimal256 `json:"balance"`
  30. Nonce *math.HexOrDecimal64 `json:"nonce,omitempty" optional:"true"`
  31. }
  32. var dec GenesisAccountJSON
  33. if err := json.Unmarshal(input, &dec); err != nil {
  34. return err
  35. }
  36. var x GenesisAccount
  37. if dec.Code != nil {
  38. x.Code = dec.Code
  39. }
  40. if dec.Storage != nil {
  41. x.Storage = dec.Storage
  42. }
  43. if dec.Balance == nil {
  44. return errors.New("missing required field 'balance' for GenesisAccount")
  45. }
  46. x.Balance = (*big.Int)(dec.Balance)
  47. if dec.Nonce != nil {
  48. x.Nonce = uint64(*dec.Nonce)
  49. }
  50. *g = x
  51. return nil
  52. }