gen_genesis_account.go 1.6 KB

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