Skip to content

Commit

Permalink
Add validators query
Browse files Browse the repository at this point in the history
  • Loading branch information
rosepuppy committed Sep 29, 2023
1 parent 7b14917 commit a8bbb78
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 28 deletions.
130 changes: 112 additions & 18 deletions 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 getAllValidators = await client.get.getAllValidators('BOND_STATUS_BONDED');
console.log('All Validators');
console.log(JSON.stringify(getAllValidators));
} 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.37.3",
"version": "0.37.4",
"description": "General client library for the new dYdX system (v4 decentralized)",
"main": "build/src/index.js",
"scripts": {
Expand Down
21 changes: 21 additions & 0 deletions v4-client-js/src/clients/modules/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,27 @@ export class Get {
return StakingModule.QueryDelegatorUnbondingDelegationsResponse.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 a8bbb78

Please sign in to comment.