mirror of
https://github.com/tendermint/tendermint.git
synced 2026-04-28 19:36:57 +00:00
add swagger params, default returns all
This commit is contained in:
@@ -21,6 +21,7 @@ program](https://hackerone.com/tendermint).
|
||||
|
||||
- [rpc] \#2010 Add NewHTTPWithClient and NewJSONRPCClientWithHTTPClient (note these and NewHTTP, NewJSONRPCClient functions panic if remote is invalid) (@gracenoah)
|
||||
- [rpc] \#3984 Add `MempoolClient` interface to `Client` interface
|
||||
- [rpc] \#3471 Paginate `/validator` response, default returns all validators with no limit
|
||||
|
||||
### BUG FIXES:
|
||||
|
||||
|
||||
@@ -528,6 +528,20 @@ paths:
|
||||
description: height to return. If no height is provided, it will fetch validato set at the latest block. 0 means latest
|
||||
default: 0
|
||||
x-example: 1
|
||||
- in: query
|
||||
name: page
|
||||
type: number
|
||||
description: "Page number (1-based)"
|
||||
required: false
|
||||
x-example: 1
|
||||
default: 0
|
||||
- in: query
|
||||
name: per_page
|
||||
type: number
|
||||
description: "Number of entries per page (max: 100)"
|
||||
required: false
|
||||
x-example: 30
|
||||
default: 0
|
||||
tags:
|
||||
- Info
|
||||
description: |
|
||||
|
||||
@@ -146,8 +146,8 @@ func (c Client) Commit(height *int64) (*ctypes.ResultCommit, error) {
|
||||
return core.Commit(&rpctypes.Context{}, height)
|
||||
}
|
||||
|
||||
func (c Client) Validators(height *int64) (*ctypes.ResultValidators, error) {
|
||||
return core.Validators(&rpctypes.Context{}, height)
|
||||
func (c Client) Validators(height *int64, page, perPage int) (*ctypes.ResultValidators, error) {
|
||||
return core.Validators(&rpctypes.Context{}, height, page, perPage)
|
||||
}
|
||||
|
||||
func (c Client) BroadcastEvidence(ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) {
|
||||
|
||||
@@ -151,7 +151,7 @@ func TestGenesisAndValidators(t *testing.T) {
|
||||
gval := gen.Genesis.Validators[0]
|
||||
|
||||
// get the current validators
|
||||
vals, err := c.Validators(nil)
|
||||
vals, err := c.Validators(nil, 0, 0)
|
||||
require.Nil(t, err, "%d: %+v", i, err)
|
||||
require.Equal(t, 1, len(vals.Validators))
|
||||
val := vals.Validators[0]
|
||||
|
||||
@@ -51,6 +51,12 @@ import (
|
||||
// "jsonrpc": "2.0"
|
||||
// }
|
||||
// ```
|
||||
// | Parameter | Type | Default | Required | Description |
|
||||
// |-----------+--------+---------+----------+------------------------------------------------|
|
||||
// | height | int64 | 0 | false | Height (0 means latest) |
|
||||
// | page | int | 0 | false | Page number (1-based) |
|
||||
// | per_page | int | 0 | false | Number of entries per page (max: 100) |
|
||||
|
||||
func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ctypes.ResultValidators, error) {
|
||||
// The latest validator that we know is the
|
||||
// NextValidator of the last block.
|
||||
@@ -64,6 +70,14 @@ func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ct
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// page & perPage === 0 then all validators are returned, no pagination
|
||||
if page == 0 && perPage == 0 {
|
||||
return &ctypes.ResultValidators{
|
||||
BlockHeight: height,
|
||||
Validators: validators.Validators,
|
||||
}, nil
|
||||
}
|
||||
|
||||
totalCount := len(validators.Validators)
|
||||
perPage = validatePerPage(perPage)
|
||||
page, err = validatePage(page, perPage, totalCount)
|
||||
@@ -74,7 +88,8 @@ func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ct
|
||||
apiResults := make([]*types.Validator, cmn.MinInt(perPage, totalCount-skipCount))
|
||||
|
||||
for i := 0; i < len(apiResults); i++ {
|
||||
v := validators.Validators[skipCount+1]
|
||||
v := validators.Validators[skipCount+i]
|
||||
|
||||
apiResults[i] = &types.Validator{
|
||||
Address: v.Address,
|
||||
PubKey: v.PubKey,
|
||||
|
||||
@@ -23,7 +23,7 @@ var Routes = map[string]*rpc.RPCFunc{
|
||||
"commit": rpc.NewRPCFunc(Commit, "height"),
|
||||
"tx": rpc.NewRPCFunc(Tx, "hash,prove"),
|
||||
"tx_search": rpc.NewRPCFunc(TxSearch, "query,prove,page,per_page"),
|
||||
"validators": rpc.NewRPCFunc(Validators, "height"),
|
||||
"validators": rpc.NewRPCFunc(Validators, "height,page,per_page"),
|
||||
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusState, ""),
|
||||
"consensus_state": rpc.NewRPCFunc(ConsensusState, ""),
|
||||
"consensus_params": rpc.NewRPCFunc(ConsensusParams, "height"),
|
||||
|
||||
Reference in New Issue
Block a user