Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query to get all validators #48

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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