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.

40 lines
1.4 KiB

  1. package core
  2. import (
  3. cm "github.com/tendermint/tendermint/consensus"
  4. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  5. "github.com/tendermint/tendermint/types"
  6. "github.com/tendermint/tendermint/wire"
  7. )
  8. func ListValidators() (*ctypes.ResultListValidators, error) {
  9. var blockHeight int
  10. var bondedValidators []*types.Validator
  11. var unbondingValidators []*types.Validator
  12. state := consensusState.GetState()
  13. blockHeight = state.LastBlockHeight
  14. state.BondedValidators.Iterate(func(index int, val *types.Validator) bool {
  15. bondedValidators = append(bondedValidators, val)
  16. return false
  17. })
  18. state.UnbondingValidators.Iterate(func(index int, val *types.Validator) bool {
  19. unbondingValidators = append(unbondingValidators, val)
  20. return false
  21. })
  22. return &ctypes.ResultListValidators{blockHeight, bondedValidators, unbondingValidators}, nil
  23. }
  24. func DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
  25. roundState := consensusState.GetRoundState()
  26. peerRoundStates := []string{}
  27. for _, peer := range p2pSwitch.Peers().List() {
  28. // TODO: clean this up?
  29. peerState := peer.Data.Get(cm.PeerStateKey).(*cm.PeerState)
  30. peerRoundState := peerState.GetRoundState()
  31. peerRoundStateStr := peer.Key + ":" + string(wire.JSONBytes(peerRoundState))
  32. peerRoundStates = append(peerRoundStates, peerRoundStateStr)
  33. }
  34. return &ctypes.ResultDumpConsensusState{roundState.String(), peerRoundStates}, nil
  35. }