Exemple #1
0
func init_files() {
	privValidator := types.GenPrivValidator()
	privValidator.SetFile(config.GetString("priv_validator_file"))
	privValidator.Save()

	genDoc := types.GenesisDoc{
		ChainID: Fmt("test-chain-%v", RandStr(6)),
	}
	genDoc.Validators = []types.GenesisValidator{types.GenesisValidator{
		PubKey: privValidator.PubKey,
		Amount: 10,
	}}

	genDoc.SaveAs(config.GetString("genesis_file"))

}
Exemple #2
0
func MakeGenesisState(db dbm.DB, genDoc *types.GenesisDoc) *State {
	if len(genDoc.Validators) == 0 {
		Exit(Fmt("The genesis file has no validators"))
	}

	if genDoc.GenesisTime.IsZero() {
		genDoc.GenesisTime = time.Now()
	}

	// Make validators slice
	validators := make([]*types.Validator, len(genDoc.Validators))
	for i, val := range genDoc.Validators {
		pubKey := val.PubKey
		address := pubKey.Address()

		// Make validator
		validators[i] = &types.Validator{
			Address:     address,
			PubKey:      pubKey,
			VotingPower: val.Amount,
		}
	}

	return &State{
		db:              db,
		GenesisDoc:      genDoc,
		ChainID:         genDoc.ChainID,
		LastBlockHeight: 0,
		LastBlockHash:   nil,
		LastBlockParts:  types.PartSetHeader{},
		LastBlockTime:   genDoc.GenesisTime,
		Validators:      types.NewValidatorSet(validators),
		LastValidators:  types.NewValidatorSet(nil),
		LastAppHash:     genDoc.AppHash,
	}
}