cosmwasm: Add query methods to Cw3CosmWasmClient

This commit is contained in:
willclarktech 2020-11-18 13:33:59 +01:00
parent 09c5968437
commit bb8f2d856f
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
2 changed files with 141 additions and 0 deletions

View File

@ -18,6 +18,43 @@ export enum Vote {
Veto = "veto",
}
export interface ThresholdResult {
readonly absolute_count: {
readonly weight_needed: number;
readonly total_weight: number;
};
}
export interface ProposalResult {
readonly id: number;
readonly title: string;
readonly description: string;
readonly msgs: ReadonlyArray<Record<string, unknown>>;
readonly expires: Expiration;
readonly status: string;
}
export interface ProposalsResult {
readonly proposals: readonly ProposalResult[];
}
export interface VoteResult {
readonly vote: Vote;
}
export interface VotesResult {
readonly votes: ReadonlyArray<{ readonly vote: Vote; readonly voter: string; readonly weight: number }>;
}
export interface VoterResult {
readonly addr: string;
readonly weight: number;
}
export interface VotersResult {
readonly voters: readonly VoterResult[];
}
export class Cw3CosmWasmClient extends SigningCosmWasmClient {
private readonly cw3ContractAddress: string;
@ -34,6 +71,68 @@ export class Cw3CosmWasmClient extends SigningCosmWasmClient {
this.cw3ContractAddress = cw3ContractAddress;
}
public getThreshold(): Promise<ThresholdResult> {
return this.queryContractSmart(this.cw3ContractAddress, { threshold: {} });
}
public getProposal(proposalId: number): Promise<ProposalResult> {
return this.queryContractSmart(this.cw3ContractAddress, { proposal: { proposal_id: proposalId } });
}
public listProposals(startAfter?: number, limit?: number): Promise<ProposalsResult> {
return this.queryContractSmart(this.cw3ContractAddress, {
list_proposals: {
start_after: startAfter,
limit: limit,
},
});
}
public reverseProposals(startBefore?: number, limit?: number): Promise<ProposalsResult> {
return this.queryContractSmart(this.cw3ContractAddress, {
reverse_proposals: {
start_before: startBefore,
limit: limit,
},
});
}
public getVote(proposalId: number, voter: string): Promise<VoteResult> {
return this.queryContractSmart(this.cw3ContractAddress, {
vote: {
proposal_id: proposalId,
voter: voter,
},
});
}
public listVotes(proposalId: number, startAfter?: string, limit?: number): Promise<VotesResult> {
return this.queryContractSmart(this.cw3ContractAddress, {
list_votes: {
proposal_id: proposalId,
start_after: startAfter,
limit: limit,
},
});
}
public getVoter(address: string): Promise<VoterResult> {
return this.queryContractSmart(this.cw3ContractAddress, {
voter: {
address: address,
},
});
}
public listVoters(startAfter?: string, limit?: number): Promise<VotersResult> {
return this.queryContractSmart(this.cw3ContractAddress, {
list_voters: {
start_after: startAfter,
limit: limit,
},
});
}
public createMultisigProposal(
title: string,
description: string,

View File

@ -13,6 +13,40 @@ export declare enum Vote {
Abstain = "abstain",
Veto = "veto",
}
export interface ThresholdResult {
readonly absolute_count: {
readonly weight_needed: number;
readonly total_weight: number;
};
}
export interface ProposalResult {
readonly id: number;
readonly title: string;
readonly description: string;
readonly msgs: ReadonlyArray<Record<string, unknown>>;
readonly expires: Expiration;
readonly status: string;
}
export interface ProposalsResult {
readonly proposals: readonly ProposalResult[];
}
export interface VoteResult {
readonly vote: Vote;
}
export interface VotesResult {
readonly votes: ReadonlyArray<{
readonly vote: Vote;
readonly voter: string;
readonly weight: number;
}>;
}
export interface VoterResult {
readonly addr: string;
readonly weight: number;
}
export interface VotersResult {
readonly voters: readonly VoterResult[];
}
export declare class Cw3CosmWasmClient extends SigningCosmWasmClient {
private readonly cw3ContractAddress;
constructor(
@ -24,6 +58,14 @@ export declare class Cw3CosmWasmClient extends SigningCosmWasmClient {
gasLimits?: Partial<GasLimits<CosmWasmFeeTable>>,
broadcastMode?: BroadcastMode,
);
getThreshold(): Promise<ThresholdResult>;
getProposal(proposalId: number): Promise<ProposalResult>;
listProposals(startAfter?: number, limit?: number): Promise<ProposalsResult>;
reverseProposals(startBefore?: number, limit?: number): Promise<ProposalsResult>;
getVote(proposalId: number, voter: string): Promise<VoteResult>;
listVotes(proposalId: number, startAfter?: string, limit?: number): Promise<VotesResult>;
getVoter(address: string): Promise<VoterResult>;
listVoters(startAfter?: string, limit?: number): Promise<VotersResult>;
createMultisigProposal(
title: string,
description: string,