mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-19 16:11:20 +00:00
list_validators API
This commit is contained in:
30
rpc/validators.go
Normal file
30
rpc/validators.go
Normal file
@ -0,0 +1,30 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
state_ "github.com/tendermint/tendermint/state"
|
||||
)
|
||||
|
||||
func ListValidatorsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var blockHeight uint
|
||||
var bondedValidators []*state_.Validator
|
||||
var unbondingValidators []*state_.Validator
|
||||
|
||||
state := consensusState.GetState()
|
||||
blockHeight = state.LastBlockHeight
|
||||
state.BondedValidators.Iterate(func(index uint, val *state_.Validator) bool {
|
||||
bondedValidators = append(bondedValidators, val)
|
||||
return false
|
||||
})
|
||||
state.UnbondingValidators.Iterate(func(index uint, val *state_.Validator) bool {
|
||||
unbondingValidators = append(unbondingValidators, val)
|
||||
return false
|
||||
})
|
||||
|
||||
WriteAPIResponse(w, API_OK, struct {
|
||||
BlockHeight uint
|
||||
BondedValidators []*state_.Validator
|
||||
UnbondingValidators []*state_.Validator
|
||||
}{blockHeight, bondedValidators, unbondingValidators})
|
||||
}
|
Reference in New Issue
Block a user