MakeGenesisState creates state from types.GenesisDoc.
(genDoc *types.GenesisDoc)
| 314 | |
| 315 | // MakeGenesisState creates state from types.GenesisDoc. |
| 316 | func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) { |
| 317 | err := genDoc.ValidateAndComplete() |
| 318 | if err != nil { |
| 319 | return State{}, fmt.Errorf("error in genesis file: %v", err) |
| 320 | } |
| 321 | |
| 322 | var validatorSet, nextValidatorSet *types.ValidatorSet |
| 323 | if genDoc.Validators == nil { |
| 324 | validatorSet = types.NewValidatorSet(nil) |
| 325 | nextValidatorSet = types.NewValidatorSet(nil) |
| 326 | } else { |
| 327 | validators := make([]*types.Validator, len(genDoc.Validators)) |
| 328 | for i, val := range genDoc.Validators { |
| 329 | validators[i] = types.NewValidator(val.PubKey, val.Power) |
| 330 | } |
| 331 | validatorSet = types.NewValidatorSet(validators) |
| 332 | nextValidatorSet = types.NewValidatorSet(validators).CopyIncrementProposerPriority(1) |
| 333 | } |
| 334 | |
| 335 | return State{ |
| 336 | Version: InitStateVersion, |
| 337 | ChainID: genDoc.ChainID, |
| 338 | InitialHeight: genDoc.InitialHeight, |
| 339 | |
| 340 | LastBlockHeight: 0, |
| 341 | LastBlockID: types.BlockID{}, |
| 342 | LastBlockTime: genDoc.GenesisTime, |
| 343 | |
| 344 | NextValidators: nextValidatorSet, |
| 345 | Validators: validatorSet, |
| 346 | LastValidators: types.NewValidatorSet(nil), |
| 347 | LastHeightValidatorsChanged: genDoc.InitialHeight, |
| 348 | |
| 349 | ConsensusParams: *genDoc.ConsensusParams, |
| 350 | LastHeightConsensusParamsChanged: genDoc.InitialHeight, |
| 351 | |
| 352 | AppHash: genDoc.AppHash, |
| 353 | }, nil |
| 354 | } |
no test coverage detected