core: regenerate genesis marshaling with fjl/gencodec@cbfa5be5a8

This commit is contained in:
Felix Lange 2017-04-04 21:02:40 +02:00
parent c51629e954
commit 80399f57b0
3 changed files with 65 additions and 69 deletions

View file

@ -14,19 +14,19 @@ import (
) )
func (g Genesis) MarshalJSON() ([]byte, error) { func (g Genesis) MarshalJSON() ([]byte, error) {
type GenesisJSON struct { type Genesis struct {
Config *params.ChainConfig `json:"config" optional:"true"` Config *params.ChainConfig `json:"config"`
Nonce math.HexOrDecimal64 `json:"nonce" optional:"true"` Nonce math.HexOrDecimal64 `json:"nonce"`
Timestamp math.HexOrDecimal64 `json:"timestamp" optional:"true"` Timestamp math.HexOrDecimal64 `json:"timestamp"`
ParentHash common.Hash `json:"parentHash" optional:"true"` ParentHash common.Hash `json:"parentHash"`
ExtraData hexutil.Bytes `json:"extraData" optional:"true"` ExtraData hexutil.Bytes `json:"extraData"`
GasLimit math.HexOrDecimal64 `json:"gasLimit"` GasLimit math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"`
Difficulty *math.HexOrDecimal256 `json:"difficulty"` Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"`
Mixhash common.Hash `json:"mixHash" optional:"true"` Mixhash common.Hash `json:"mixHash"`
Coinbase common.Address `json:"coinbase" optional:"true"` Coinbase common.Address `json:"coinbase"`
Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc"` Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"`
} }
var enc GenesisJSON var enc Genesis
enc.Config = g.Config enc.Config = g.Config
enc.Nonce = math.HexOrDecimal64(g.Nonce) enc.Nonce = math.HexOrDecimal64(g.Nonce)
enc.Timestamp = math.HexOrDecimal64(g.Timestamp) enc.Timestamp = math.HexOrDecimal64(g.Timestamp)
@ -46,59 +46,57 @@ func (g Genesis) MarshalJSON() ([]byte, error) {
} }
func (g *Genesis) UnmarshalJSON(input []byte) error { func (g *Genesis) UnmarshalJSON(input []byte) error {
type GenesisJSON struct { type Genesis struct {
Config *params.ChainConfig `json:"config" optional:"true"` Config *params.ChainConfig `json:"config"`
Nonce *math.HexOrDecimal64 `json:"nonce" optional:"true"` Nonce *math.HexOrDecimal64 `json:"nonce"`
Timestamp *math.HexOrDecimal64 `json:"timestamp" optional:"true"` Timestamp *math.HexOrDecimal64 `json:"timestamp"`
ParentHash *common.Hash `json:"parentHash" optional:"true"` ParentHash *common.Hash `json:"parentHash"`
ExtraData hexutil.Bytes `json:"extraData" optional:"true"` ExtraData hexutil.Bytes `json:"extraData"`
GasLimit *math.HexOrDecimal64 `json:"gasLimit"` GasLimit *math.HexOrDecimal64 `json:"gasLimit" gencodec:"required"`
Difficulty *math.HexOrDecimal256 `json:"difficulty"` Difficulty *math.HexOrDecimal256 `json:"difficulty" gencodec:"required"`
Mixhash *common.Hash `json:"mixHash" optional:"true"` Mixhash *common.Hash `json:"mixHash"`
Coinbase *common.Address `json:"coinbase" optional:"true"` Coinbase *common.Address `json:"coinbase"`
Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc"` Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc" gencodec:"required"`
} }
var dec GenesisJSON var dec Genesis
if err := json.Unmarshal(input, &dec); err != nil { if err := json.Unmarshal(input, &dec); err != nil {
return err return err
} }
var x Genesis
if dec.Config != nil { if dec.Config != nil {
x.Config = dec.Config g.Config = dec.Config
} }
if dec.Nonce != nil { if dec.Nonce != nil {
x.Nonce = uint64(*dec.Nonce) g.Nonce = uint64(*dec.Nonce)
} }
if dec.Timestamp != nil { if dec.Timestamp != nil {
x.Timestamp = uint64(*dec.Timestamp) g.Timestamp = uint64(*dec.Timestamp)
} }
if dec.ParentHash != nil { if dec.ParentHash != nil {
x.ParentHash = *dec.ParentHash g.ParentHash = *dec.ParentHash
} }
if dec.ExtraData != nil { if dec.ExtraData != nil {
x.ExtraData = dec.ExtraData g.ExtraData = dec.ExtraData
} }
if dec.GasLimit == nil { if dec.GasLimit == nil {
return errors.New("missing required field 'gasLimit' for Genesis") return errors.New("missing required field 'gasLimit' for Genesis")
} }
x.GasLimit = uint64(*dec.GasLimit) g.GasLimit = uint64(*dec.GasLimit)
if dec.Difficulty == nil { if dec.Difficulty == nil {
return errors.New("missing required field 'difficulty' for Genesis") return errors.New("missing required field 'difficulty' for Genesis")
} }
x.Difficulty = (*big.Int)(dec.Difficulty) g.Difficulty = (*big.Int)(dec.Difficulty)
if dec.Mixhash != nil { if dec.Mixhash != nil {
x.Mixhash = *dec.Mixhash g.Mixhash = *dec.Mixhash
} }
if dec.Coinbase != nil { if dec.Coinbase != nil {
x.Coinbase = *dec.Coinbase g.Coinbase = *dec.Coinbase
} }
if dec.Alloc == nil { if dec.Alloc == nil {
return errors.New("missing required field 'alloc' for Genesis") return errors.New("missing required field 'alloc' for Genesis")
} }
x.Alloc = make(GenesisAlloc, len(dec.Alloc)) g.Alloc = make(GenesisAlloc, len(dec.Alloc))
for k, v := range dec.Alloc { for k, v := range dec.Alloc {
x.Alloc[common.Address(k)] = v g.Alloc[common.Address(k)] = v
} }
*g = x
return nil return nil
} }

View file

@ -13,13 +13,13 @@ import (
) )
func (g GenesisAccount) MarshalJSON() ([]byte, error) { func (g GenesisAccount) MarshalJSON() ([]byte, error) {
type GenesisAccountJSON struct { type GenesisAccount struct {
Code hexutil.Bytes `json:"code,omitempty" optional:"true"` Code hexutil.Bytes `json:"code,omitempty"`
Storage map[common.Hash]common.Hash `json:"storage,omitempty" optional:"true"` Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
Balance *math.HexOrDecimal256 `json:"balance"` Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"`
Nonce math.HexOrDecimal64 `json:"nonce,omitempty" optional:"true"` Nonce math.HexOrDecimal64 `json:"nonce,omitempty"`
} }
var enc GenesisAccountJSON var enc GenesisAccount
enc.Code = g.Code enc.Code = g.Code
enc.Storage = g.Storage enc.Storage = g.Storage
enc.Balance = (*math.HexOrDecimal256)(g.Balance) enc.Balance = (*math.HexOrDecimal256)(g.Balance)
@ -28,30 +28,28 @@ func (g GenesisAccount) MarshalJSON() ([]byte, error) {
} }
func (g *GenesisAccount) UnmarshalJSON(input []byte) error { func (g *GenesisAccount) UnmarshalJSON(input []byte) error {
type GenesisAccountJSON struct { type GenesisAccount struct {
Code hexutil.Bytes `json:"code,omitempty" optional:"true"` Code hexutil.Bytes `json:"code,omitempty"`
Storage map[common.Hash]common.Hash `json:"storage,omitempty" optional:"true"` Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
Balance *math.HexOrDecimal256 `json:"balance"` Balance *math.HexOrDecimal256 `json:"balance" gencodec:"required"`
Nonce *math.HexOrDecimal64 `json:"nonce,omitempty" optional:"true"` Nonce *math.HexOrDecimal64 `json:"nonce,omitempty"`
} }
var dec GenesisAccountJSON var dec GenesisAccount
if err := json.Unmarshal(input, &dec); err != nil { if err := json.Unmarshal(input, &dec); err != nil {
return err return err
} }
var x GenesisAccount
if dec.Code != nil { if dec.Code != nil {
x.Code = dec.Code g.Code = dec.Code
} }
if dec.Storage != nil { if dec.Storage != nil {
x.Storage = dec.Storage g.Storage = dec.Storage
} }
if dec.Balance == nil { if dec.Balance == nil {
return errors.New("missing required field 'balance' for GenesisAccount") return errors.New("missing required field 'balance' for GenesisAccount")
} }
x.Balance = (*big.Int)(dec.Balance) g.Balance = (*big.Int)(dec.Balance)
if dec.Nonce != nil { if dec.Nonce != nil {
x.Nonce = uint64(*dec.Nonce) g.Nonce = uint64(*dec.Nonce)
} }
*g = x
return nil return nil
} }

View file

@ -41,16 +41,16 @@ var errGenesisNoConfig = errors.New("genesis has no chain configuration")
// Genesis specifies the header fields, state of a genesis block. It also defines hard // Genesis specifies the header fields, state of a genesis block. It also defines hard
// fork switch-over blocks through the chain configuration. // fork switch-over blocks through the chain configuration.
type Genesis struct { type Genesis struct {
Config *params.ChainConfig `json:"config" optional:"true"` Config *params.ChainConfig `json:"config"`
Nonce uint64 `json:"nonce" optional:"true"` Nonce uint64 `json:"nonce"`
Timestamp uint64 `json:"timestamp" optional:"true"` Timestamp uint64 `json:"timestamp"`
ParentHash common.Hash `json:"parentHash" optional:"true"` ParentHash common.Hash `json:"parentHash"`
ExtraData []byte `json:"extraData" optional:"true"` ExtraData []byte `json:"extraData"`
GasLimit uint64 `json:"gasLimit"` GasLimit uint64 `json:"gasLimit" gencodec:"required"`
Difficulty *big.Int `json:"difficulty"` Difficulty *big.Int `json:"difficulty" gencodec:"required"`
Mixhash common.Hash `json:"mixHash" optional:"true"` Mixhash common.Hash `json:"mixHash"`
Coinbase common.Address `json:"coinbase" optional:"true"` Coinbase common.Address `json:"coinbase"`
Alloc GenesisAlloc `json:"alloc"` Alloc GenesisAlloc `json:"alloc" gencodec:"required"`
} }
// GenesisAlloc specifies the initial state that is part of the genesis block. // GenesisAlloc specifies the initial state that is part of the genesis block.
@ -58,10 +58,10 @@ type GenesisAlloc map[common.Address]GenesisAccount
// GenesisAccount is an account in the state of the genesis block. // GenesisAccount is an account in the state of the genesis block.
type GenesisAccount struct { type GenesisAccount struct {
Code []byte `json:"code,omitempty" optional:"true"` Code []byte `json:"code,omitempty"`
Storage map[common.Hash]common.Hash `json:"storage,omitempty" optional:"true"` Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
Balance *big.Int `json:"balance"` Balance *big.Int `json:"balance" gencodec:"required"`
Nonce uint64 `json:"nonce,omitempty" optional:"true"` Nonce uint64 `json:"nonce,omitempty"`
} }
// field type overrides for gencodec // field type overrides for gencodec