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
|
|
|
)
|
|
|
|
|
2015-03-25 18:06:57 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Request: {}
|
|
|
|
|
|
|
|
type ResponseListValidators struct {
|
|
|
|
BlockHeight uint
|
|
|
|
BondedValidators []*sm.Validator
|
|
|
|
UnbondingValidators []*sm.Validator
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
2015-03-25 18:06:57 -07:00
|
|
|
WriteAPIResponse(w, API_OK, ResponseListValidators{blockHeight, bondedValidators, unbondingValidators})
|
2015-01-11 18:21:17 -08:00
|
|
|
}
|