gen_genesis.go 4.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 15

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"
	"github.com/ethereum/go-ethereum/params"
)

16 17
var _ = (*genesisSpecMarshaling)(nil)

18
func (g Genesis) MarshalJSON() ([]byte, error) {
19 20 21 22 23 24 25 26 27 28
	type Genesis struct {
		Config     *params.ChainConfig                         `json:"config"`
		Nonce      math.HexOrDecimal64                         `json:"nonce"`
		Timestamp  math.HexOrDecimal64                         `json:"timestamp"`
		ExtraData  hexutil.Bytes                               `json:"extraData"`
		GasLimit   math.HexOrDecimal64                         `json:"gasLimit"   gencodec:"required"`
		Difficulty *math.HexOrDecimal256                       `json:"difficulty" gencodec:"required"`
		Mixhash    common.Hash                                 `json:"mixHash"`
		Coinbase   common.Address                              `json:"coinbase"`
		Alloc      map[common.UnprefixedAddress]GenesisAccount `json:"alloc"      gencodec:"required"`
29
		Number     math.HexOrDecimal64                         `json:"number"`
30 31
		GasUsed    math.HexOrDecimal64                         `json:"gasUsed"`
		ParentHash common.Hash                                 `json:"parentHash"`
32
	}
33
	var enc Genesis
34 35 36 37 38
	enc.Config = g.Config
	enc.Nonce = math.HexOrDecimal64(g.Nonce)
	enc.Timestamp = math.HexOrDecimal64(g.Timestamp)
	enc.ExtraData = g.ExtraData
	enc.GasLimit = math.HexOrDecimal64(g.GasLimit)
39
	enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty)
40 41
	enc.Mixhash = g.Mixhash
	enc.Coinbase = g.Coinbase
42 43 44 45 46 47
	if g.Alloc != nil {
		enc.Alloc = make(map[common.UnprefixedAddress]GenesisAccount, len(g.Alloc))
		for k, v := range g.Alloc {
			enc.Alloc[common.UnprefixedAddress(k)] = v
		}
	}
48
	enc.Number = math.HexOrDecimal64(g.Number)
49 50
	enc.GasUsed = math.HexOrDecimal64(g.GasUsed)
	enc.ParentHash = g.ParentHash
51 52 53 54
	return json.Marshal(&enc)
}

func (g *Genesis) UnmarshalJSON(input []byte) error {
55 56 57 58
	type Genesis struct {
		Config     *params.ChainConfig                         `json:"config"`
		Nonce      *math.HexOrDecimal64                        `json:"nonce"`
		Timestamp  *math.HexOrDecimal64                        `json:"timestamp"`
59
		ExtraData  *hexutil.Bytes                              `json:"extraData"`
60 61 62 63 64
		GasLimit   *math.HexOrDecimal64                        `json:"gasLimit"   gencodec:"required"`
		Difficulty *math.HexOrDecimal256                       `json:"difficulty" gencodec:"required"`
		Mixhash    *common.Hash                                `json:"mixHash"`
		Coinbase   *common.Address                             `json:"coinbase"`
		Alloc      map[common.UnprefixedAddress]GenesisAccount `json:"alloc"      gencodec:"required"`
65
		Number     *math.HexOrDecimal64                        `json:"number"`
66 67
		GasUsed    *math.HexOrDecimal64                        `json:"gasUsed"`
		ParentHash *common.Hash                                `json:"parentHash"`
68
	}
69
	var dec Genesis
70 71 72
	if err := json.Unmarshal(input, &dec); err != nil {
		return err
	}
73
	if dec.Config != nil {
74
		g.Config = dec.Config
75 76
	}
	if dec.Nonce != nil {
77
		g.Nonce = uint64(*dec.Nonce)
78 79
	}
	if dec.Timestamp != nil {
80
		g.Timestamp = uint64(*dec.Timestamp)
81 82
	}
	if dec.ExtraData != nil {
83
		g.ExtraData = *dec.ExtraData
84 85 86 87
	}
	if dec.GasLimit == nil {
		return errors.New("missing required field 'gasLimit' for Genesis")
	}
88
	g.GasLimit = uint64(*dec.GasLimit)
89 90 91
	if dec.Difficulty == nil {
		return errors.New("missing required field 'difficulty' for Genesis")
	}
92
	g.Difficulty = (*big.Int)(dec.Difficulty)
93
	if dec.Mixhash != nil {
94
		g.Mixhash = *dec.Mixhash
95 96
	}
	if dec.Coinbase != nil {
97
		g.Coinbase = *dec.Coinbase
98 99 100 101
	}
	if dec.Alloc == nil {
		return errors.New("missing required field 'alloc' for Genesis")
	}
102
	g.Alloc = make(GenesisAlloc, len(dec.Alloc))
103
	for k, v := range dec.Alloc {
104
		g.Alloc[common.Address(k)] = v
105
	}
106
	if dec.Number != nil {
107
		g.Number = uint64(*dec.Number)
108 109 110 111 112 113 114
	}
	if dec.GasUsed != nil {
		g.GasUsed = uint64(*dec.GasUsed)
	}
	if dec.ParentHash != nil {
		g.ParentHash = *dec.ParentHash
	}
115 116
	return nil
}