[types] add Address to GenesisValidator (#2418)

Refs #1714
This commit is contained in:
Anton Kaliaev
2018-09-18 11:59:52 +04:00
committed by GitHub
parent 4fe9906361
commit 38bced2440
6 changed files with 31 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
package types
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
@@ -21,9 +22,10 @@ const (
// GenesisValidator is an initial validator.
type GenesisValidator struct {
PubKey crypto.PubKey `json:"pub_key"`
Power int64 `json:"power"`
Name string `json:"name"`
Address Address `json:"address"`
PubKey crypto.PubKey `json:"pub_key"`
Power int64 `json:"power"`
Name string `json:"name"`
}
// GenesisDoc defines the initial conditions for a tendermint blockchain, in particular its validator set.
@@ -62,7 +64,7 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
return cmn.NewError("Genesis doc must include non-empty chain_id")
}
if len(genDoc.ChainID) > MaxChainIDLen {
return cmn.NewError(fmt.Sprintf("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen))
return cmn.NewError("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen)
}
if genDoc.ConsensusParams == nil {
@@ -73,10 +75,16 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
}
}
for _, v := range genDoc.Validators {
for i, v := range genDoc.Validators {
if v.Power == 0 {
return cmn.NewError("The genesis file cannot contain validators with no voting power: %v", v)
}
if len(v.Address) > 0 && !bytes.Equal(v.PubKey.Address(), v.Address) {
return cmn.NewError("Incorrect address for validator %v in the genesis file, should be %v", v, v.PubKey.Address())
}
if len(v.Address) == 0 {
genDoc.Validators[i].Address = v.PubKey.Address()
}
}
if genDoc.GenesisTime.IsZero() {