gen_genesis_account.go 1.53 KB
Newer Older
1
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
2 3 4 5 6 7 8 9 10 11 12 13 14

package core

import (
	"encoding/json"
	"errors"
	"math/big"

	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/common/hexutil"
	"github.com/ethereum/go-ethereum/common/math"
)

15
func (g GenesisAccount) MarshalJSON() ([]byte, error) {
16 17 18 19 20
	type GenesisAccount struct {
		Code    hexutil.Bytes               `json:"code,omitempty"`
		Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
		Balance *math.HexOrDecimal256       `json:"balance" gencodec:"required"`
		Nonce   math.HexOrDecimal64         `json:"nonce,omitempty"`
21
	}
22
	var enc GenesisAccount
23 24
	enc.Code = g.Code
	enc.Storage = g.Storage
25
	enc.Balance = (*math.HexOrDecimal256)(g.Balance)
26
	enc.Nonce = math.HexOrDecimal64(g.Nonce)
27 28 29 30
	return json.Marshal(&enc)
}

func (g *GenesisAccount) UnmarshalJSON(input []byte) error {
31 32 33 34 35
	type GenesisAccount struct {
		Code    hexutil.Bytes               `json:"code,omitempty"`
		Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
		Balance *math.HexOrDecimal256       `json:"balance" gencodec:"required"`
		Nonce   *math.HexOrDecimal64        `json:"nonce,omitempty"`
36
	}
37
	var dec GenesisAccount
38 39 40 41
	if err := json.Unmarshal(input, &dec); err != nil {
		return err
	}
	if dec.Code != nil {
42
		g.Code = dec.Code
43 44
	}
	if dec.Storage != nil {
45
		g.Storage = dec.Storage
46 47 48 49
	}
	if dec.Balance == nil {
		return errors.New("missing required field 'balance' for GenesisAccount")
	}
50
	g.Balance = (*big.Int)(dec.Balance)
51
	if dec.Nonce != nil {
52
		g.Nonce = uint64(*dec.Nonce)
53 54 55
	}
	return nil
}