From 80399f57b097cdc629a6b0baa3991214dc1a2a05 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 4 Apr 2017 21:02:40 +0200 Subject: [PATCH] core: regenerate genesis marshaling with fjl/gencodec@cbfa5be5a8a8 --- core/gen_genesis.go | 72 ++++++++++++++++++------------------- core/gen_genesis_account.go | 34 +++++++++--------- core/genesis.go | 28 +++++++-------- 3 files changed, 65 insertions(+), 69 deletions(-) diff --git a/core/gen_genesis.go b/core/gen_genesis.go index eb86567b7b..3f83905c9e 100644 --- a/core/gen_genesis.go +++ b/core/gen_genesis.go @@ -14,19 +14,19 @@ import ( ) func (g Genesis) MarshalJSON() ([]byte, error) { - type GenesisJSON struct { - Config *params.ChainConfig `json:"config" optional:"true"` - Nonce math.HexOrDecimal64 `json:"nonce" optional:"true"` - Timestamp math.HexOrDecimal64 `json:"timestamp" optional:"true"` - ParentHash common.Hash `json:"parentHash" optional:"true"` - ExtraData hexutil.Bytes `json:"extraData" optional:"true"` - GasLimit math.HexOrDecimal64 `json:"gasLimit"` - Difficulty *math.HexOrDecimal256 `json:"difficulty"` - Mixhash common.Hash `json:"mixHash" optional:"true"` - Coinbase common.Address `json:"coinbase" optional:"true"` - Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc"` + type Genesis struct { + Config *params.ChainConfig `json:"config"` + Nonce math.HexOrDecimal64 `json:"nonce"` + Timestamp math.HexOrDecimal64 `json:"timestamp"` + ParentHash common.Hash `json:"parentHash"` + 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"` } - var enc GenesisJSON + var enc Genesis enc.Config = g.Config enc.Nonce = math.HexOrDecimal64(g.Nonce) enc.Timestamp = math.HexOrDecimal64(g.Timestamp) @@ -46,59 +46,57 @@ func (g Genesis) MarshalJSON() ([]byte, error) { } func (g *Genesis) UnmarshalJSON(input []byte) error { - type GenesisJSON struct { - Config *params.ChainConfig `json:"config" optional:"true"` - Nonce *math.HexOrDecimal64 `json:"nonce" optional:"true"` - Timestamp *math.HexOrDecimal64 `json:"timestamp" optional:"true"` - ParentHash *common.Hash `json:"parentHash" optional:"true"` - ExtraData hexutil.Bytes `json:"extraData" optional:"true"` - GasLimit *math.HexOrDecimal64 `json:"gasLimit"` - Difficulty *math.HexOrDecimal256 `json:"difficulty"` - Mixhash *common.Hash `json:"mixHash" optional:"true"` - Coinbase *common.Address `json:"coinbase" optional:"true"` - Alloc map[common.UnprefixedAddress]GenesisAccount `json:"alloc"` + type Genesis struct { + Config *params.ChainConfig `json:"config"` + Nonce *math.HexOrDecimal64 `json:"nonce"` + Timestamp *math.HexOrDecimal64 `json:"timestamp"` + ParentHash *common.Hash `json:"parentHash"` + 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"` } - var dec GenesisJSON + var dec Genesis if err := json.Unmarshal(input, &dec); err != nil { return err } - var x Genesis if dec.Config != nil { - x.Config = dec.Config + g.Config = dec.Config } if dec.Nonce != nil { - x.Nonce = uint64(*dec.Nonce) + g.Nonce = uint64(*dec.Nonce) } if dec.Timestamp != nil { - x.Timestamp = uint64(*dec.Timestamp) + g.Timestamp = uint64(*dec.Timestamp) } if dec.ParentHash != nil { - x.ParentHash = *dec.ParentHash + g.ParentHash = *dec.ParentHash } if dec.ExtraData != nil { - x.ExtraData = dec.ExtraData + g.ExtraData = dec.ExtraData } if dec.GasLimit == nil { return errors.New("missing required field 'gasLimit' for Genesis") } - x.GasLimit = uint64(*dec.GasLimit) + g.GasLimit = uint64(*dec.GasLimit) if dec.Difficulty == nil { 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 { - x.Mixhash = *dec.Mixhash + g.Mixhash = *dec.Mixhash } if dec.Coinbase != nil { - x.Coinbase = *dec.Coinbase + g.Coinbase = *dec.Coinbase } if dec.Alloc == nil { 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 { - x.Alloc[common.Address(k)] = v + g.Alloc[common.Address(k)] = v } - *g = x return nil } diff --git a/core/gen_genesis_account.go b/core/gen_genesis_account.go index 8885603aa8..bc5fc936b9 100644 --- a/core/gen_genesis_account.go +++ b/core/gen_genesis_account.go @@ -13,13 +13,13 @@ import ( ) func (g GenesisAccount) MarshalJSON() ([]byte, error) { - type GenesisAccountJSON struct { - Code hexutil.Bytes `json:"code,omitempty" optional:"true"` - Storage map[common.Hash]common.Hash `json:"storage,omitempty" optional:"true"` - Balance *math.HexOrDecimal256 `json:"balance"` - Nonce math.HexOrDecimal64 `json:"nonce,omitempty" optional:"true"` + 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"` } - var enc GenesisAccountJSON + var enc GenesisAccount enc.Code = g.Code enc.Storage = g.Storage enc.Balance = (*math.HexOrDecimal256)(g.Balance) @@ -28,30 +28,28 @@ func (g GenesisAccount) MarshalJSON() ([]byte, error) { } func (g *GenesisAccount) UnmarshalJSON(input []byte) error { - type GenesisAccountJSON struct { - Code hexutil.Bytes `json:"code,omitempty" optional:"true"` - Storage map[common.Hash]common.Hash `json:"storage,omitempty" optional:"true"` - Balance *math.HexOrDecimal256 `json:"balance"` - Nonce *math.HexOrDecimal64 `json:"nonce,omitempty" optional:"true"` + 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"` } - var dec GenesisAccountJSON + var dec GenesisAccount if err := json.Unmarshal(input, &dec); err != nil { return err } - var x GenesisAccount if dec.Code != nil { - x.Code = dec.Code + g.Code = dec.Code } if dec.Storage != nil { - x.Storage = dec.Storage + g.Storage = dec.Storage } if dec.Balance == nil { 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 { - x.Nonce = uint64(*dec.Nonce) + g.Nonce = uint64(*dec.Nonce) } - *g = x return nil } diff --git a/core/genesis.go b/core/genesis.go index 34725241ec..883cea2fd4 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -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 // fork switch-over blocks through the chain configuration. type Genesis struct { - Config *params.ChainConfig `json:"config" optional:"true"` - Nonce uint64 `json:"nonce" optional:"true"` - Timestamp uint64 `json:"timestamp" optional:"true"` - ParentHash common.Hash `json:"parentHash" optional:"true"` - ExtraData []byte `json:"extraData" optional:"true"` - GasLimit uint64 `json:"gasLimit"` - Difficulty *big.Int `json:"difficulty"` - Mixhash common.Hash `json:"mixHash" optional:"true"` - Coinbase common.Address `json:"coinbase" optional:"true"` - Alloc GenesisAlloc `json:"alloc"` + Config *params.ChainConfig `json:"config"` + Nonce uint64 `json:"nonce"` + Timestamp uint64 `json:"timestamp"` + ParentHash common.Hash `json:"parentHash"` + ExtraData []byte `json:"extraData"` + GasLimit uint64 `json:"gasLimit" gencodec:"required"` + Difficulty *big.Int `json:"difficulty" gencodec:"required"` + Mixhash common.Hash `json:"mixHash"` + Coinbase common.Address `json:"coinbase"` + Alloc GenesisAlloc `json:"alloc" gencodec:"required"` } // 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. type GenesisAccount struct { - Code []byte `json:"code,omitempty" optional:"true"` - Storage map[common.Hash]common.Hash `json:"storage,omitempty" optional:"true"` - Balance *big.Int `json:"balance"` - Nonce uint64 `json:"nonce,omitempty" optional:"true"` + Code []byte `json:"code,omitempty"` + Storage map[common.Hash]common.Hash `json:"storage,omitempty"` + Balance *big.Int `json:"balance" gencodec:"required"` + Nonce uint64 `json:"nonce,omitempty"` } // field type overrides for gencodec