|
@ -52,26 +52,48 @@ func (genDoc *GenesisDoc) ValidatorHash() []byte { |
|
|
return vset.Hash() |
|
|
return vset.Hash() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
// Make genesis state from file
|
|
|
|
|
|
|
|
|
|
|
|
// GenesisDocFromJSON unmarshalls JSON data into a GenesisDoc.
|
|
|
|
|
|
func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) { |
|
|
|
|
|
genDoc := GenesisDoc{} |
|
|
|
|
|
err := json.Unmarshal(jsonBlob, &genDoc) |
|
|
|
|
|
|
|
|
// ValidateAndComplete checks that all necessary fields are present
|
|
|
|
|
|
// and fills in defaults for optional fields left empty
|
|
|
|
|
|
func (genDoc *GenesisDoc) ValidateAndComplete() error { |
|
|
|
|
|
|
|
|
// validate genesis
|
|
|
|
|
|
if genDoc.ChainID == "" { |
|
|
if genDoc.ChainID == "" { |
|
|
return nil, errors.Errorf("Genesis doc must include non-empty chain_id") |
|
|
|
|
|
|
|
|
return errors.Errorf("Genesis doc must include non-empty chain_id") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if genDoc.ConsensusParams == nil { |
|
|
if genDoc.ConsensusParams == nil { |
|
|
genDoc.ConsensusParams = cfg.DefaultConsensusParams() |
|
|
genDoc.ConsensusParams = cfg.DefaultConsensusParams() |
|
|
} else { |
|
|
} else { |
|
|
if err := genDoc.ConsensusParams.Validate(); err != nil { |
|
|
if err := genDoc.ConsensusParams.Validate(); err != nil { |
|
|
return nil, err |
|
|
|
|
|
|
|
|
return err |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if len(genDoc.Validators) == 0 { |
|
|
|
|
|
return errors.Errorf("The genesis file must have at least one validator") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if genDoc.GenesisTime.IsZero() { |
|
|
|
|
|
genDoc.GenesisTime = time.Now() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
// Make genesis state from file
|
|
|
|
|
|
|
|
|
|
|
|
// GenesisDocFromJSON unmarshalls JSON data into a GenesisDoc.
|
|
|
|
|
|
func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) { |
|
|
|
|
|
genDoc := GenesisDoc{} |
|
|
|
|
|
err := json.Unmarshal(jsonBlob, &genDoc) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := genDoc.ValidateAndComplete(); err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return &genDoc, err |
|
|
return &genDoc, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|