You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

  1. package v0
  2. import (
  3. "sort"
  4. cfg "github.com/tendermint/tendermint/config"
  5. sm "github.com/tendermint/tendermint/state"
  6. "github.com/tendermint/tendermint/types"
  7. tmtime "github.com/tendermint/tendermint/types/time"
  8. )
  9. func randGenesisDoc(
  10. config *cfg.Config,
  11. numValidators int,
  12. randPower bool,
  13. minPower int64,
  14. ) (*types.GenesisDoc, []types.PrivValidator) {
  15. validators := make([]types.GenesisValidator, numValidators)
  16. privValidators := make([]types.PrivValidator, numValidators)
  17. for i := 0; i < numValidators; i++ {
  18. val, privVal := types.RandValidator(randPower, minPower)
  19. validators[i] = types.GenesisValidator{
  20. PubKey: val.PubKey,
  21. Power: val.VotingPower,
  22. }
  23. privValidators[i] = privVal
  24. }
  25. sort.Sort(types.PrivValidatorsByAddress(privValidators))
  26. return &types.GenesisDoc{
  27. GenesisTime: tmtime.Now(),
  28. ChainID: config.ChainID(),
  29. Validators: validators,
  30. }, privValidators
  31. }
  32. func makeTxs(height int64) (txs []types.Tx) {
  33. for i := 0; i < 10; i++ {
  34. txs = append(txs, types.Tx([]byte{byte(height), byte(i)}))
  35. }
  36. return txs
  37. }
  38. func makeBlock(height int64, state sm.State, lastCommit *types.Commit) *types.Block {
  39. block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, state.Validators.GetProposer().Address)
  40. return block
  41. }