list_validators API
This commit is contained in:
parent
6ad3388097
commit
33aff6b26b
|
@ -9,25 +9,16 @@ import (
|
|||
. "github.com/tendermint/tendermint/common"
|
||||
)
|
||||
|
||||
type GenPrivAccountResponse struct {
|
||||
PrivAccount *account.PrivAccount
|
||||
}
|
||||
|
||||
func GenPrivAccountHandler(w http.ResponseWriter, r *http.Request) {
|
||||
privAccount := account.GenPrivAccount()
|
||||
|
||||
res := GenPrivAccountResponse{
|
||||
PrivAccount: privAccount,
|
||||
}
|
||||
WriteAPIResponse(w, API_OK, res)
|
||||
WriteAPIResponse(w, API_OK, struct {
|
||||
PrivAccount *account.PrivAccount
|
||||
}{privAccount})
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
type SignSendTxResponse struct {
|
||||
SendTx *block.SendTx
|
||||
}
|
||||
|
||||
func SignSendTxHandler(w http.ResponseWriter, r *http.Request) {
|
||||
sendTxStr := GetParam(r, "sendTx")
|
||||
privAccountsStr := GetParam(r, "privAccounts")
|
||||
|
@ -49,23 +40,25 @@ func SignSendTxHandler(w http.ResponseWriter, r *http.Request) {
|
|||
input.Signature = privAccounts[i].Sign(sendTx)
|
||||
}
|
||||
|
||||
res := SignSendTxResponse{
|
||||
SendTx: sendTx,
|
||||
}
|
||||
WriteAPIResponse(w, API_OK, res)
|
||||
WriteAPIResponse(w, API_OK, struct {
|
||||
SendTx *block.SendTx
|
||||
}{sendTx})
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
type ListAccountsResponse struct {
|
||||
Accounts []*account.Account
|
||||
}
|
||||
|
||||
func ListAccountsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var blockHeight uint
|
||||
var accounts []*account.Account
|
||||
state := consensusState.GetState()
|
||||
blockHeight = state.LastBlockHeight
|
||||
state.GetAccounts().Iterate(func(key interface{}, value interface{}) bool {
|
||||
log.Warn(">>", "key", key, "value", value)
|
||||
accounts = append(accounts, value.(*account.Account))
|
||||
return false
|
||||
})
|
||||
WriteAPIResponse(w, API_OK, state)
|
||||
|
||||
WriteAPIResponse(w, API_OK, struct {
|
||||
BlockHeight uint
|
||||
Accounts []*account.Account
|
||||
}{blockHeight, accounts})
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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…
Reference in New Issue