Browse Source

list_validators API

pull/39/head
Jae Kwon 10 years ago
parent
commit
33aff6b26b
3 changed files with 47 additions and 23 deletions
  1. +15
    -22
      rpc/accounts.go
  2. +2
    -1
      rpc/http_handlers.go
  3. +30
    -0
      rpc/validators.go

rpc/account.go → rpc/accounts.go View File


+ 2
- 1
rpc/http_handlers.go View File

@ -10,5 +10,6 @@ func initHandlers() {
http.HandleFunc("/broadcast_tx", BroadcastTxHandler)
http.HandleFunc("/gen_priv_account", GenPrivAccountHandler)
http.HandleFunc("/sign_send_tx", SignSendTxHandler)
http.HandleFunc("/accounts", ListAccountsHandler)
http.HandleFunc("/list_accounts", ListAccountsHandler)
http.HandleFunc("/list_validators", ListValidatorsHandler)
}

+ 30
- 0
rpc/validators.go View 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})
}

Loading…
Cancel
Save