1// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
2
3package core
4
5import (
6	"encoding/json"
7	"errors"
8	"math/big"
9
10	"github.com/ethereum/go-ethereum/common"
11	"github.com/ethereum/go-ethereum/common/hexutil"
12	"github.com/ethereum/go-ethereum/common/math"
13	"github.com/ethereum/go-ethereum/params"
14)
15
16var _ = (*genesisSpecMarshaling)(nil)
17
18// MarshalJSON marshals as JSON.
19func (g Genesis) MarshalJSON() ([]byte, error) {
20	type Genesis struct {
21		Config     *params.ChainConfig                         `json:"config"`
22		Nonce      math.HexOrDecimal64                         `json:"nonce"`
23		Timestamp  math.HexOrDecimal64                         `json:"timestamp"`
24		ExtraData  hexutil.Bytes                               `json:"extraData"`
25		GasLimit   math.HexOrDecimal64                         `json:"gasLimit"   gencodec:"required"`
26		Difficulty *math.HexOrDecimal256                       `json:"difficulty" gencodec:"required"`
27		Mixhash    common.Hash                                 `json:"mixHash"`
28		Coinbase   common.Address                              `json:"coinbase"`
29		Alloc      map[common.UnprefixedAddress]GenesisAccount `json:"alloc"      gencodec:"required"`
30		Number     math.HexOrDecimal64                         `json:"number"`
31		GasUsed    math.HexOrDecimal64                         `json:"gasUsed"`
32		ParentHash common.Hash                                 `json:"parentHash"`
33		BaseFee    *math.HexOrDecimal256                       `json:"baseFeePerGas"`
34	}
35	var enc Genesis
36	enc.Config = g.Config
37	enc.Nonce = math.HexOrDecimal64(g.Nonce)
38	enc.Timestamp = math.HexOrDecimal64(g.Timestamp)
39	enc.ExtraData = g.ExtraData
40	enc.GasLimit = math.HexOrDecimal64(g.GasLimit)
41	enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty)
42	enc.Mixhash = g.Mixhash
43	enc.Coinbase = g.Coinbase
44	if g.Alloc != nil {
45		enc.Alloc = make(map[common.UnprefixedAddress]GenesisAccount, len(g.Alloc))
46		for k, v := range g.Alloc {
47			enc.Alloc[common.UnprefixedAddress(k)] = v
48		}
49	}
50	enc.Number = math.HexOrDecimal64(g.Number)
51	enc.GasUsed = math.HexOrDecimal64(g.GasUsed)
52	enc.ParentHash = g.ParentHash
53	enc.BaseFee = (*math.HexOrDecimal256)(g.BaseFee)
54	return json.Marshal(&enc)
55}
56
57// UnmarshalJSON unmarshals from JSON.
58func (g *Genesis) UnmarshalJSON(input []byte) error {
59	type Genesis struct {
60		Config     *params.ChainConfig                         `json:"config"`
61		Nonce      *math.HexOrDecimal64                        `json:"nonce"`
62		Timestamp  *math.HexOrDecimal64                        `json:"timestamp"`
63		ExtraData  *hexutil.Bytes                              `json:"extraData"`
64		GasLimit   *math.HexOrDecimal64                        `json:"gasLimit"   gencodec:"required"`
65		Difficulty *math.HexOrDecimal256                       `json:"difficulty" gencodec:"required"`
66		Mixhash    *common.Hash                                `json:"mixHash"`
67		Coinbase   *common.Address                             `json:"coinbase"`
68		Alloc      map[common.UnprefixedAddress]GenesisAccount `json:"alloc"      gencodec:"required"`
69		Number     *math.HexOrDecimal64                        `json:"number"`
70		GasUsed    *math.HexOrDecimal64                        `json:"gasUsed"`
71		ParentHash *common.Hash                                `json:"parentHash"`
72		BaseFee    *math.HexOrDecimal256                       `json:"baseFeePerGas"`
73	}
74	var dec Genesis
75	if err := json.Unmarshal(input, &dec); err != nil {
76		return err
77	}
78	if dec.Config != nil {
79		g.Config = dec.Config
80	}
81	if dec.Nonce != nil {
82		g.Nonce = uint64(*dec.Nonce)
83	}
84	if dec.Timestamp != nil {
85		g.Timestamp = uint64(*dec.Timestamp)
86	}
87	if dec.ExtraData != nil {
88		g.ExtraData = *dec.ExtraData
89	}
90	if dec.GasLimit == nil {
91		return errors.New("missing required field 'gasLimit' for Genesis")
92	}
93	g.GasLimit = uint64(*dec.GasLimit)
94	if dec.Difficulty == nil {
95		return errors.New("missing required field 'difficulty' for Genesis")
96	}
97	g.Difficulty = (*big.Int)(dec.Difficulty)
98	if dec.Mixhash != nil {
99		g.Mixhash = *dec.Mixhash
100	}
101	if dec.Coinbase != nil {
102		g.Coinbase = *dec.Coinbase
103	}
104	if dec.Alloc == nil {
105		return errors.New("missing required field 'alloc' for Genesis")
106	}
107	g.Alloc = make(GenesisAlloc, len(dec.Alloc))
108	for k, v := range dec.Alloc {
109		g.Alloc[common.Address(k)] = v
110	}
111	if dec.Number != nil {
112		g.Number = uint64(*dec.Number)
113	}
114	if dec.GasUsed != nil {
115		g.GasUsed = uint64(*dec.GasUsed)
116	}
117	if dec.ParentHash != nil {
118		g.ParentHash = *dec.ParentHash
119	}
120	if dec.BaseFee != nil {
121		g.BaseFee = (*big.Int)(dec.BaseFee)
122	}
123	return nil
124}
125