mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
stargate: Add distribution queries
This commit is contained in:
parent
4aa248ec63
commit
486e6aa8c4
@ -4,10 +4,12 @@ export { parseRawLog } from "./logs";
|
||||
export {
|
||||
AuthExtension,
|
||||
BankExtension,
|
||||
DistributionExtension,
|
||||
IbcExtension,
|
||||
QueryClient,
|
||||
setupAuthExtension,
|
||||
setupBankExtension,
|
||||
setupDistributionExtension,
|
||||
setupIbcExtension,
|
||||
setupStakingExtension,
|
||||
StakingExtension,
|
||||
|
122
packages/stargate/src/queries/distribution.ts
Normal file
122
packages/stargate/src/queries/distribution.ts
Normal file
@ -0,0 +1,122 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import Long from "long";
|
||||
|
||||
import { cosmos } from "../codec";
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { toObject } from "./utils";
|
||||
|
||||
type IQueryCommunityPoolResponse = cosmos.distribution.v1beta1.IQueryCommunityPoolResponse;
|
||||
type IQueryDelegationRewardsResponse = cosmos.distribution.v1beta1.IQueryDelegationRewardsResponse;
|
||||
type IQueryDelegationTotalRewardsResponse = cosmos.distribution.v1beta1.IQueryDelegationTotalRewardsResponse;
|
||||
type IQueryDelegatorValidatorsResponse = cosmos.distribution.v1beta1.IQueryDelegatorValidatorsResponse;
|
||||
type IQueryDelegatorWithdrawAddressResponse = cosmos.distribution.v1beta1.IQueryDelegatorWithdrawAddressResponse;
|
||||
type IQueryParamsResponse = cosmos.distribution.v1beta1.IQueryParamsResponse;
|
||||
type IQueryValidatorCommissionResponse = cosmos.distribution.v1beta1.IQueryValidatorCommissionResponse;
|
||||
type IQueryValidatorOutstandingRewardsResponse = cosmos.distribution.v1beta1.IQueryValidatorOutstandingRewardsResponse;
|
||||
type IQueryValidatorSlashesResponse = cosmos.distribution.v1beta1.IQueryValidatorSlashesResponse;
|
||||
|
||||
const { Query } = cosmos.distribution.v1beta1;
|
||||
|
||||
export interface DistributionExtension {
|
||||
readonly distribution: {
|
||||
unverified: {
|
||||
communityPool: () => Promise<IQueryCommunityPoolResponse>;
|
||||
delegationRewards: (
|
||||
delegatorAddress: string,
|
||||
validatorAddress: string,
|
||||
) => Promise<IQueryDelegationRewardsResponse>;
|
||||
delegationTotalRewards: (delegatorAddress: string) => Promise<IQueryDelegationTotalRewardsResponse>;
|
||||
delegatorValidators: (delegatorAddress: string) => Promise<IQueryDelegatorValidatorsResponse>;
|
||||
delegatorWithdrawAddress: (delegatorAddress: string) => Promise<IQueryDelegatorWithdrawAddressResponse>;
|
||||
params: () => Promise<IQueryParamsResponse>;
|
||||
validatorCommission: (validatorAddress: string) => Promise<IQueryValidatorCommissionResponse>;
|
||||
validatorOutstandingRewards: (
|
||||
validatorAddress: string,
|
||||
) => Promise<IQueryValidatorOutstandingRewardsResponse>;
|
||||
validatorSlashes: (
|
||||
validatorAddress: string,
|
||||
startingHeight: number,
|
||||
endingHeight: number,
|
||||
paginationKey?: Uint8Array,
|
||||
) => Promise<IQueryValidatorSlashesResponse>;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function setupDistributionExtension(base: QueryClient): DistributionExtension {
|
||||
// Use this service to get easy typed access to query methods
|
||||
// This cannot be used to for proof verification
|
||||
const queryService = Query.create((method: any, requestData, callback) => {
|
||||
// Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229
|
||||
const path = `/cosmos.distribution.v1beta1.Query/${method.name}`;
|
||||
base
|
||||
.queryUnverified(path, requestData)
|
||||
.then((response) => callback(null, response))
|
||||
.catch((error) => callback(error));
|
||||
});
|
||||
return {
|
||||
distribution: {
|
||||
unverified: {
|
||||
communityPool: async () => {
|
||||
const response = await queryService.communityPool({});
|
||||
return toObject(response);
|
||||
},
|
||||
delegationRewards: async (delegatorAddress: string, validatorAddress: string) => {
|
||||
const response = await queryService.delegationRewards({
|
||||
delegatorAddress: delegatorAddress,
|
||||
validatorAddress: validatorAddress,
|
||||
});
|
||||
return toObject(response);
|
||||
},
|
||||
delegationTotalRewards: async (delegatorAddress: string) => {
|
||||
const response = await queryService.delegationTotalRewards({
|
||||
delegatorAddress: delegatorAddress,
|
||||
});
|
||||
return toObject(response);
|
||||
},
|
||||
delegatorValidators: async (delegatorAddress: string) => {
|
||||
const response = await queryService.delegatorValidators({
|
||||
delegatorAddress: delegatorAddress,
|
||||
});
|
||||
return toObject(response);
|
||||
},
|
||||
delegatorWithdrawAddress: async (delegatorAddress: string) => {
|
||||
const response = await queryService.delegatorWithdrawAddress({
|
||||
delegatorAddress: delegatorAddress,
|
||||
});
|
||||
return toObject(response);
|
||||
},
|
||||
params: async () => {
|
||||
const response = await queryService.params({});
|
||||
return toObject(response);
|
||||
},
|
||||
validatorCommission: async (validatorAddress: string) => {
|
||||
const response = await queryService.validatorCommission({
|
||||
validatorAddress: validatorAddress,
|
||||
});
|
||||
return toObject(response);
|
||||
},
|
||||
validatorOutstandingRewards: async (validatorAddress: string) => {
|
||||
const response = await queryService.validatorOutstandingRewards({
|
||||
validatorAddress: validatorAddress,
|
||||
});
|
||||
return toObject(response);
|
||||
},
|
||||
validatorSlashes: async (
|
||||
validatorAddress: string,
|
||||
startingHeight: number,
|
||||
endingHeight: number,
|
||||
paginationKey?: Uint8Array,
|
||||
) => {
|
||||
const response = await queryService.validatorSlashes({
|
||||
validatorAddress: validatorAddress,
|
||||
startingHeight: Long.fromNumber(startingHeight),
|
||||
endingHeight: Long.fromNumber(endingHeight),
|
||||
pagination: paginationKey ? { key: paginationKey } : undefined,
|
||||
});
|
||||
return toObject(response);
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
@ -6,5 +6,6 @@ export { QueryClient } from "./queryclient";
|
||||
|
||||
export { AuthExtension, setupAuthExtension } from "./auth";
|
||||
export { BankExtension, setupBankExtension } from "./bank";
|
||||
export { DistributionExtension, setupDistributionExtension } from "./distribution";
|
||||
export { IbcExtension, setupIbcExtension } from "./ibc";
|
||||
export { setupStakingExtension, StakingExtension } from "./staking";
|
||||
|
2
packages/stargate/types/index.d.ts
vendored
2
packages/stargate/types/index.d.ts
vendored
@ -4,10 +4,12 @@ export { parseRawLog } from "./logs";
|
||||
export {
|
||||
AuthExtension,
|
||||
BankExtension,
|
||||
DistributionExtension,
|
||||
IbcExtension,
|
||||
QueryClient,
|
||||
setupAuthExtension,
|
||||
setupBankExtension,
|
||||
setupDistributionExtension,
|
||||
setupIbcExtension,
|
||||
setupStakingExtension,
|
||||
StakingExtension,
|
||||
|
38
packages/stargate/types/queries/distribution.d.ts
vendored
Normal file
38
packages/stargate/types/queries/distribution.d.ts
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
import { cosmos } from "../codec";
|
||||
import { QueryClient } from "./queryclient";
|
||||
declare type IQueryCommunityPoolResponse = cosmos.distribution.v1beta1.IQueryCommunityPoolResponse;
|
||||
declare type IQueryDelegationRewardsResponse = cosmos.distribution.v1beta1.IQueryDelegationRewardsResponse;
|
||||
declare type IQueryDelegationTotalRewardsResponse = cosmos.distribution.v1beta1.IQueryDelegationTotalRewardsResponse;
|
||||
declare type IQueryDelegatorValidatorsResponse = cosmos.distribution.v1beta1.IQueryDelegatorValidatorsResponse;
|
||||
declare type IQueryDelegatorWithdrawAddressResponse = cosmos.distribution.v1beta1.IQueryDelegatorWithdrawAddressResponse;
|
||||
declare type IQueryParamsResponse = cosmos.distribution.v1beta1.IQueryParamsResponse;
|
||||
declare type IQueryValidatorCommissionResponse = cosmos.distribution.v1beta1.IQueryValidatorCommissionResponse;
|
||||
declare type IQueryValidatorOutstandingRewardsResponse = cosmos.distribution.v1beta1.IQueryValidatorOutstandingRewardsResponse;
|
||||
declare type IQueryValidatorSlashesResponse = cosmos.distribution.v1beta1.IQueryValidatorSlashesResponse;
|
||||
export interface DistributionExtension {
|
||||
readonly distribution: {
|
||||
unverified: {
|
||||
communityPool: () => Promise<IQueryCommunityPoolResponse>;
|
||||
delegationRewards: (
|
||||
delegatorAddress: string,
|
||||
validatorAddress: string,
|
||||
) => Promise<IQueryDelegationRewardsResponse>;
|
||||
delegationTotalRewards: (delegatorAddress: string) => Promise<IQueryDelegationTotalRewardsResponse>;
|
||||
delegatorValidators: (delegatorAddress: string) => Promise<IQueryDelegatorValidatorsResponse>;
|
||||
delegatorWithdrawAddress: (delegatorAddress: string) => Promise<IQueryDelegatorWithdrawAddressResponse>;
|
||||
params: () => Promise<IQueryParamsResponse>;
|
||||
validatorCommission: (validatorAddress: string) => Promise<IQueryValidatorCommissionResponse>;
|
||||
validatorOutstandingRewards: (
|
||||
validatorAddress: string,
|
||||
) => Promise<IQueryValidatorOutstandingRewardsResponse>;
|
||||
validatorSlashes: (
|
||||
validatorAddress: string,
|
||||
startingHeight: number,
|
||||
endingHeight: number,
|
||||
paginationKey?: Uint8Array,
|
||||
) => Promise<IQueryValidatorSlashesResponse>;
|
||||
};
|
||||
};
|
||||
}
|
||||
export declare function setupDistributionExtension(base: QueryClient): DistributionExtension;
|
||||
export {};
|
1
packages/stargate/types/queries/index.d.ts
vendored
1
packages/stargate/types/queries/index.d.ts
vendored
@ -1,5 +1,6 @@
|
||||
export { QueryClient } from "./queryclient";
|
||||
export { AuthExtension, setupAuthExtension } from "./auth";
|
||||
export { BankExtension, setupBankExtension } from "./bank";
|
||||
export { DistributionExtension, setupDistributionExtension } from "./distribution";
|
||||
export { IbcExtension, setupIbcExtension } from "./ibc";
|
||||
export { setupStakingExtension, StakingExtension } from "./staking";
|
||||
|
Loading…
x
Reference in New Issue
Block a user