tendermint-rpc: Update validatorsAll for review

This commit is contained in:
willclarktech 2021-02-18 10:43:03 +00:00
parent 397d17d4c5
commit 3e41b9ce04
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
2 changed files with 12 additions and 15 deletions

View File

@ -151,7 +151,7 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
it("can get all validators", async () => {
pendingWithoutTendermint();
const client = await Client.create(rpcFactory(), adaptor);
const response = await client.validatorsAll({});
const response = await client.validatorsAll();
expect(response).toBeTruthy();
expect(response.blockHeight).toBeGreaterThanOrEqual(1);

View File

@ -257,25 +257,21 @@ export class Client {
return this.doCall(query, this.p.encodeValidators, this.r.decodeValidators);
}
public async validatorsAll(params: requests.ValidatorsParams): Promise<responses.ValidatorsResponse> {
let page = params.page || 1;
public async validatorsAll(height?: number): Promise<responses.ValidatorsResponse> {
const validators: responses.Validator[] = [];
const baseParams = {
per_page: 50,
height: params.height ?? (await this.status()).syncInfo.latestBlockHeight,
...params,
};
let page = 1;
let done = false;
let blockHeight = 0;
let blockHeight = height;
while (!done) {
const resp = await this.validators({
...baseParams,
const response = await this.validators({
per_page: 50,
height: blockHeight,
page: page,
});
validators.push(...resp.validators);
blockHeight = resp.blockHeight;
if (validators.length < resp.total) {
validators.push(...response.validators);
blockHeight = blockHeight || response.blockHeight;
if (validators.length < response.total) {
page++;
} else {
done = true;
@ -283,7 +279,8 @@ export class Client {
}
return {
blockHeight: blockHeight,
// NOTE: Default value is for type safety but this should always be set
blockHeight: blockHeight ?? 0,
count: validators.length,
total: validators.length,
validators: validators,