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. "github.com/tendermint/tendermint/binary"
  4. cm "github.com/tendermint/tendermint/consensus"
  5. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  6. sm "github.com/tendermint/tendermint/state"
  7. )
  8. func ListValidators() (*ctypes.ResponseListValidators, error) {
  9. var blockHeight int
  10. var bondedValidators []*sm.Validator
  11. var unbondingValidators []*sm.Validator
  12. state := consensusState.GetState()
  13. blockHeight = state.LastBlockHeight
  14. state.BondedValidators.Iterate(func(index int, val *sm.Validator) bool {
  15. bondedValidators = append(bondedValidators, val)
  16. return false
  17. })
  18. state.UnbondingValidators.Iterate(func(index int, val *sm.Validator) bool {
  19. unbondingValidators = append(unbondingValidators, val)
  20. return false
  21. })
  22. return &ctypes.ResponseListValidators{blockHeight, bondedValidators, unbondingValidators}, nil
  23. }
  24. func DumpConsensusState() (*ctypes.ResponseDumpConsensusState, 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(binary.JSONBytes(peerRoundState))
  32. peerRoundStates = append(peerRoundStates, peerRoundStateStr)
  33. }
  34. return &ctypes.ResponseDumpConsensusState{roundState.String(), peerRoundStates}, nil
  35. }