Skip to content

Commit

Permalink
Add query to get all validators (#48)
Browse files Browse the repository at this point in the history
* Add validators query

* bump
  • Loading branch information
rosepuppy authored Oct 2, 2023
1 parent bed661a commit 6cf0ded
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
13 changes: 12 additions & 1 deletion v4-client-js/__native__/__ios__/v4-native-client.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion v4-client-js/__native__/__ios__/v4-native-client.js.map

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions v4-client-js/examples/validator_get_example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,26 @@ async function test(): Promise<void> {
}

try {
const delegationsParams = await client.get.getDelegatorDelegations(DYDX_TEST_ADDRESS);
console.log('Rewards Params');
console.log(JSON.stringify(delegationsParams));
const delegations = await client.get.getDelegatorDelegations(DYDX_TEST_ADDRESS);
console.log('Delegations');
console.log(JSON.stringify(delegations));
} catch (error) {
console.log(JSON.stringify(error.message));
}

try {
const unbondingDelegationsParams = await client
const unbondingDelegations = await client
.get.getDelegatorUnbondingDelegations(DYDX_TEST_ADDRESS);
console.log('Rewards Params');
console.log(JSON.stringify(unbondingDelegationsParams));
console.log('Unbonding Delegationss');
console.log(JSON.stringify(unbondingDelegations));
} catch (error) {
console.log(JSON.stringify(error.message));
}

try {
const getAllBondedValidators = await client.get.getAllValidators('BOND_STATUS_BONDED');
console.log('All Validators');
console.log(JSON.stringify(getAllBondedValidators));
} catch (error) {
console.log(JSON.stringify(error.message));
}
Expand Down
4 changes: 2 additions & 2 deletions v4-client-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion v4-client-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dydxprotocol/v4-client-js",
"version": "0.38.3",
"version": "0.38.4",
"description": "General client library for the new dYdX system (v4 decentralized)",
"main": "build/src/index.js",
"scripts": {
Expand Down
20 changes: 20 additions & 0 deletions v4-client-js/src/clients/modules/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,26 @@ export class Get {
return BridgeModule.QueryDelayedCompleteBridgeMessagesResponse.decode(data);
}

/**
* @description Get all validators of a status.
*
* @returns all validators of a status.
*/
async getAllValidators(
status: string = '',
): Promise<StakingModule.QueryValidatorsResponse> {
const requestData = Uint8Array.from(
StakingModule.QueryValidatorsRequest
.encode({ status, pagination: PAGE_REQUEST }).finish(),
);

const data: Uint8Array = await this.sendQuery(
'/cosmos.staking.v1beta1.Query/Validators',
requestData,
);
return StakingModule.QueryValidatorsResponse.decode(data);
}

private async sendQuery(requestUrl: string, requestData: Uint8Array): Promise<Uint8Array> {
return this.stargateQueryClient.queryUnverified(requestUrl, requestData);
}
Expand Down

0 comments on commit 6cf0ded

Please sign in to comment.