tendermint-rpc: Add validatorsAll query
This commit is contained in:
parent
484fdc2fd0
commit
c5adeace6d
@ -148,6 +148,24 @@ function defaultTestSuite(rpcFactory: () => RpcClient, adaptor: Adaptor, expecte
|
||||
client.disconnect();
|
||||
});
|
||||
|
||||
it("can get all validators", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
const response = await client.validatorsAll({});
|
||||
|
||||
expect(response).toBeTruthy();
|
||||
expect(response.blockHeight).toBeGreaterThanOrEqual(1);
|
||||
expect(response.count).toBeGreaterThanOrEqual(1);
|
||||
expect(response.total).toBeGreaterThanOrEqual(1);
|
||||
expect(response.validators.length).toBeGreaterThanOrEqual(1);
|
||||
expect(response.validators[0].address.length).toEqual(20);
|
||||
expect(response.validators[0].pubkey).toBeDefined();
|
||||
expect(response.validators[0].votingPower).toBeGreaterThanOrEqual(0);
|
||||
expect(response.validators[0].proposerPriority).toBeGreaterThanOrEqual(0);
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
|
||||
it("can call a bunch of methods", async () => {
|
||||
pendingWithoutTendermint();
|
||||
const client = await Client.create(rpcFactory(), adaptor);
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Stream } from "xstream";
|
||||
|
||||
import { Adaptor, Decoder, Encoder, Params, Responses } from "./adaptor";
|
||||
@ -256,6 +257,35 @@ 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;
|
||||
const validators: responses.Validator[] = [];
|
||||
let done = false;
|
||||
let blockHeight = 0;
|
||||
|
||||
while (!done) {
|
||||
const resp = await this.validators({
|
||||
per_page: 50,
|
||||
...params,
|
||||
page: page,
|
||||
});
|
||||
validators.push(...resp.validators);
|
||||
blockHeight = resp.blockHeight;
|
||||
if (validators.length < resp.total) {
|
||||
page++;
|
||||
} else {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
blockHeight: blockHeight,
|
||||
count: validators.length,
|
||||
total: validators.length,
|
||||
validators: validators,
|
||||
};
|
||||
}
|
||||
|
||||
// doCall is a helper to handle the encode/call/decode logic
|
||||
private async doCall<T extends requests.Request, U extends responses.Response>(
|
||||
request: T,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user