gen_genesis_account.go 2.1 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 16
var _ = (*genesisAccountMarshaling)(nil)

17
func (g GenesisAccount) MarshalJSON() ([]byte, error) {
18
	type GenesisAccount struct {
19 20 21 22 23
		Code       hexutil.Bytes               `json:"code,omitempty"`
		Storage    map[storageJSON]storageJSON `json:"storage,omitempty"`
		Balance    *math.HexOrDecimal256       `json:"balance" gencodec:"required"`
		Nonce      math.HexOrDecimal64         `json:"nonce,omitempty"`
		PrivateKey hexutil.Bytes               `json:"secretKey,omitempty"`
24
	}
25
	var enc GenesisAccount
26
	enc.Code = g.Code
27 28 29 30 31 32
	if g.Storage != nil {
		enc.Storage = make(map[storageJSON]storageJSON, len(g.Storage))
		for k, v := range g.Storage {
			enc.Storage[storageJSON(k)] = storageJSON(v)
		}
	}
33
	enc.Balance = (*math.HexOrDecimal256)(g.Balance)
34
	enc.Nonce = math.HexOrDecimal64(g.Nonce)
35
	enc.PrivateKey = g.PrivateKey
36 37 38 39
	return json.Marshal(&enc)
}

func (g *GenesisAccount) UnmarshalJSON(input []byte) error {
40
	type GenesisAccount struct {
41
		Code       *hexutil.Bytes              `json:"code,omitempty"`
42 43 44
		Storage    map[storageJSON]storageJSON `json:"storage,omitempty"`
		Balance    *math.HexOrDecimal256       `json:"balance" gencodec:"required"`
		Nonce      *math.HexOrDecimal64        `json:"nonce,omitempty"`
45
		PrivateKey *hexutil.Bytes              `json:"secretKey,omitempty"`
46
	}
47
	var dec GenesisAccount
48 49 50 51
	if err := json.Unmarshal(input, &dec); err != nil {
		return err
	}
	if dec.Code != nil {
52
		g.Code = *dec.Code
53 54
	}
	if dec.Storage != nil {
55 56 57 58
		g.Storage = make(map[common.Hash]common.Hash, len(dec.Storage))
		for k, v := range dec.Storage {
			g.Storage[common.Hash(k)] = common.Hash(v)
		}
59 60 61 62
	}
	if dec.Balance == nil {
		return errors.New("missing required field 'balance' for GenesisAccount")
	}
63
	g.Balance = (*big.Int)(dec.Balance)
64
	if dec.Nonce != nil {
65
		g.Nonce = uint64(*dec.Nonce)
66
	}
67
	if dec.PrivateKey != nil {
68
		g.PrivateKey = *dec.PrivateKey
69
	}
70 71
	return nil
}