gen_genesis_account.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 GenesisAccount struct {
  13. Code hexutil.Bytes `json:"code,omitempty"`
  14. Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
  15. Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"`
  16. Nonce math.HexOrDecimal64 `json:"nonce,omitempty"`
  17. }
  18. var enc GenesisAccount
  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 GenesisAccount struct {
  27. Code hexutil.Bytes `json:"code,omitempty"`
  28. Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
  29. Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"`
  30. Nonce *math.HexOrDecimal64 `json:"nonce,omitempty"`
  31. }
  32. var dec GenesisAccount
  33. if err := json.Unmarshal(input, &dec); err != nil {
  34. return err
  35. }
  36. if dec.Code != nil {
  37. g.Code = dec.Code
  38. }
  39. if dec.Storage != nil {
  40. g.Storage = dec.Storage
  41. }
  42. if dec.Balance == nil {
  43. return errors.New("missing required field 'balance' for GenesisAccount")
  44. }
  45. g.Balance = (*big.Int)(dec.Balance)
  46. if dec.Nonce != nil {
  47. g.Nonce = uint64(*dec.Nonce)
  48. }
  49. return nil
  50. }