2015-01-11 18:21:17 -08:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2015-01-14 20:34:53 -08:00
|
|
|
sm "github.com/tendermint/tendermint/state"
|
2015-01-11 18:21:17 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func ListValidatorsHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var blockHeight uint
|
2015-01-14 20:34:53 -08:00
|
|
|
var bondedValidators []*sm.Validator
|
|
|
|
var unbondingValidators []*sm.Validator
|
2015-01-11 18:21:17 -08:00
|
|
|
|
|
|
|
state := consensusState.GetState()
|
|
|
|
blockHeight = state.LastBlockHeight
|
2015-01-14 20:34:53 -08:00
|
|
|
state.BondedValidators.Iterate(func(index uint, val *sm.Validator) bool {
|
2015-01-11 18:21:17 -08:00
|
|
|
bondedValidators = append(bondedValidators, val)
|
|
|
|
return false
|
|
|
|
})
|
2015-01-14 20:34:53 -08:00
|
|
|
state.UnbondingValidators.Iterate(func(index uint, val *sm.Validator) bool {
|
2015-01-11 18:21:17 -08:00
|
|
|
unbondingValidators = append(unbondingValidators, val)
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
|
|
|
WriteAPIResponse(w, API_OK, struct {
|
|
|
|
BlockHeight uint
|
2015-01-14 20:34:53 -08:00
|
|
|
BondedValidators []*sm.Validator
|
|
|
|
UnbondingValidators []*sm.Validator
|
2015-01-11 18:21:17 -08:00
|
|
|
}{blockHeight, bondedValidators, unbondingValidators})
|
|
|
|
}
|