Browse Source

add swagger params, default returns all

pull/3993/head
Marko Baricevic 5 years ago
parent
commit
dd6ba71934
No known key found for this signature in database GPG Key ID: 1C1A5B44A0E4674D
6 changed files with 35 additions and 5 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +14
    -0
      docs/spec/rpc/swagger.yaml
  3. +2
    -2
      rpc/client/mock/client.go
  4. +1
    -1
      rpc/client/rpc_test.go
  5. +16
    -1
      rpc/core/consensus.go
  6. +1
    -1
      rpc/core/routes.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -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:


+ 14
- 0
docs/spec/rpc/swagger.yaml View File

@ -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: |


+ 2
- 2
rpc/client/mock/client.go View File

@ -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) {


+ 1
- 1
rpc/client/rpc_test.go View File

@ -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]


+ 16
- 1
rpc/core/consensus.go View File

@ -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,


+ 1
- 1
rpc/core/routes.go View File

@ -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"),


Loading…
Cancel
Save