Add /staking/validators query
This commit is contained in:
parent
6baaa270c9
commit
c464d875df
@ -219,8 +219,8 @@ export class LcdClient {
|
||||
this.broadcastMode = broadcastMode;
|
||||
}
|
||||
|
||||
public async get(path: string): Promise<any> {
|
||||
const { data } = await this.client.get(path).catch(parseAxiosError);
|
||||
public async get(path: string, params?: Record<string, any>): Promise<any> {
|
||||
const { data } = await this.client.get(path, { params }).catch(parseAxiosError);
|
||||
if (data === null) {
|
||||
throw new Error("Received null response from server");
|
||||
}
|
||||
|
||||
@ -8,6 +8,56 @@ function makeStakingClient(apiUrl: string): LcdClient & StakingExtension {
|
||||
}
|
||||
|
||||
describe("StakingExtension", () => {
|
||||
describe("validators", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeStakingClient(wasmd.endpoint);
|
||||
const response = await client.staking.validators();
|
||||
expect(response).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: [
|
||||
{
|
||||
operator_address: "cosmosvaloper1gjvanqxc774u6ed9thj4gpn9gj5zus5u32enqn",
|
||||
consensus_pubkey:
|
||||
"cosmosvalconspub1zcjduepqau36ht2r742jh230pxlu4wjmwcmkwpeqava80acphsu87vt5xlpqx6g7qh",
|
||||
jailed: false,
|
||||
status: 2,
|
||||
tokens: "250000000",
|
||||
delegator_shares: "250000000.000000000000000000",
|
||||
description: {
|
||||
moniker: "testing",
|
||||
identity: "",
|
||||
website: "",
|
||||
security_contact: "",
|
||||
details: "",
|
||||
},
|
||||
unbonding_height: "0",
|
||||
unbonding_time: "1970-01-01T00:00:00Z",
|
||||
commission: {
|
||||
commission_rates: {
|
||||
rate: "0.100000000000000000",
|
||||
max_rate: "0.200000000000000000",
|
||||
max_change_rate: "0.010000000000000000",
|
||||
},
|
||||
update_time: "2020-06-03T06:01:17.4747987Z",
|
||||
},
|
||||
min_self_delegation: "1",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("can filter by status", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeStakingClient(wasmd.endpoint);
|
||||
const response = await client.staking.validators({ status: "unbonded" });
|
||||
expect(response).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("pool", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
|
||||
@ -1,5 +1,49 @@
|
||||
import { LcdClient } from "./lcdclient";
|
||||
|
||||
export interface StakingValidatorsParams {
|
||||
/** @see https://github.com/cosmos/cosmos-sdk/blob/v0.38.5/types/staking.go#L43-L49 */
|
||||
readonly status?: "bonded" | "unbonded" | "unbonding";
|
||||
readonly page?: number;
|
||||
readonly limit?: number;
|
||||
}
|
||||
|
||||
interface Validator {
|
||||
readonly operator_address: string;
|
||||
readonly consensus_pubkey: string;
|
||||
readonly jailed: boolean;
|
||||
/**
|
||||
* Numeric bonding status
|
||||
*
|
||||
* @see https://github.com/cosmos/cosmos-sdk/blob/v0.38.5/types/staking.go#L43-L49
|
||||
*/
|
||||
readonly status: number;
|
||||
readonly tokens: string;
|
||||
readonly delegator_shares: string;
|
||||
readonly description: {
|
||||
readonly moniker: string;
|
||||
readonly identity: string;
|
||||
readonly website: string;
|
||||
readonly security_contact: string;
|
||||
readonly details: string;
|
||||
};
|
||||
readonly unbonding_height: string;
|
||||
readonly unbonding_time: string;
|
||||
readonly commission: {
|
||||
readonly commission_rates: {
|
||||
readonly rate: string;
|
||||
readonly max_rate: string;
|
||||
readonly max_change_rate: string;
|
||||
};
|
||||
readonly update_time: string;
|
||||
};
|
||||
readonly min_self_delegation: string;
|
||||
}
|
||||
|
||||
export interface StakingValidatorsResponse {
|
||||
readonly height: string;
|
||||
readonly result: readonly Validator[];
|
||||
}
|
||||
|
||||
export interface StakingPoolResponse {
|
||||
readonly height: string;
|
||||
readonly result: {
|
||||
@ -45,8 +89,8 @@ export interface StakingExtension {
|
||||
// Query redelegations (filters in query params)
|
||||
// /staking/redelegations
|
||||
|
||||
// Get all validators
|
||||
// /staking/validators
|
||||
/** Get all validators */
|
||||
readonly validators: (options?: StakingValidatorsParams) => Promise<StakingValidatorsResponse>;
|
||||
|
||||
// Get a single validator info
|
||||
// /staking/validators/{validatorAddr}
|
||||
@ -70,6 +114,7 @@ export interface StakingExtension {
|
||||
export function setupStakingExtension(base: LcdClient): StakingExtension {
|
||||
return {
|
||||
staking: {
|
||||
validators: async (params?: StakingValidatorsParams) => base.get(`/staking/validators`, params),
|
||||
pool: async () => base.get(`/staking/pool`),
|
||||
parameters: async () => base.get(`/staking/parameters`),
|
||||
},
|
||||
|
||||
2
packages/sdk38/types/lcdapi/lcdclient.d.ts
vendored
2
packages/sdk38/types/lcdapi/lcdclient.d.ts
vendored
@ -143,7 +143,7 @@ export declare class LcdClient {
|
||||
* @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns
|
||||
*/
|
||||
constructor(apiUrl: string, broadcastMode?: BroadcastMode);
|
||||
get(path: string): Promise<any>;
|
||||
get(path: string, params?: Record<string, any>): Promise<any>;
|
||||
post(path: string, params: any): Promise<any>;
|
||||
blocksLatest(): Promise<BlockResponse>;
|
||||
blocks(height: number): Promise<BlockResponse>;
|
||||
|
||||
44
packages/sdk38/types/lcdapi/staking.d.ts
vendored
44
packages/sdk38/types/lcdapi/staking.d.ts
vendored
@ -1,4 +1,45 @@
|
||||
import { LcdClient } from "./lcdclient";
|
||||
export interface StakingValidatorsParams {
|
||||
/** @see https://github.com/cosmos/cosmos-sdk/blob/v0.38.5/types/staking.go#L43-L49 */
|
||||
readonly status?: "bonded" | "unbonded" | "unbonding";
|
||||
readonly page?: number;
|
||||
readonly limit?: number;
|
||||
}
|
||||
interface Validator {
|
||||
readonly operator_address: string;
|
||||
readonly consensus_pubkey: string;
|
||||
readonly jailed: boolean;
|
||||
/**
|
||||
* Numeric bonding status
|
||||
*
|
||||
* @see https://github.com/cosmos/cosmos-sdk/blob/v0.38.5/types/staking.go#L43-L49
|
||||
*/
|
||||
readonly status: number;
|
||||
readonly tokens: string;
|
||||
readonly delegator_shares: string;
|
||||
readonly description: {
|
||||
readonly moniker: string;
|
||||
readonly identity: string;
|
||||
readonly website: string;
|
||||
readonly security_contact: string;
|
||||
readonly details: string;
|
||||
};
|
||||
readonly unbonding_height: string;
|
||||
readonly unbonding_time: string;
|
||||
readonly commission: {
|
||||
readonly commission_rates: {
|
||||
readonly rate: string;
|
||||
readonly max_rate: string;
|
||||
readonly max_change_rate: string;
|
||||
};
|
||||
readonly update_time: string;
|
||||
};
|
||||
readonly min_self_delegation: string;
|
||||
}
|
||||
export interface StakingValidatorsResponse {
|
||||
readonly height: string;
|
||||
readonly result: readonly Validator[];
|
||||
}
|
||||
export interface StakingPoolResponse {
|
||||
readonly height: string;
|
||||
readonly result: {
|
||||
@ -18,6 +59,8 @@ export interface StakingParametersResponse {
|
||||
}
|
||||
export interface StakingExtension {
|
||||
readonly staking: {
|
||||
/** Get all validators */
|
||||
readonly validators: (options?: StakingValidatorsParams) => Promise<StakingValidatorsResponse>;
|
||||
/** Get the current state of the staking pool */
|
||||
readonly pool: () => Promise<StakingPoolResponse>;
|
||||
/** Get the current staking parameter values */
|
||||
@ -25,3 +68,4 @@ export interface StakingExtension {
|
||||
};
|
||||
}
|
||||
export declare function setupStakingExtension(base: LcdClient): StakingExtension;
|
||||
export {};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user