From bb8f2d856fde974ec86d401e9410fa06f72e77ce Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 18 Nov 2020 13:33:59 +0100 Subject: [PATCH] cosmwasm: Add query methods to Cw3CosmWasmClient --- packages/cosmwasm/src/cw3cosmwasmclient.ts | 99 +++++++++++++++++++ .../cosmwasm/types/cw3cosmwasmclient.d.ts | 42 ++++++++ 2 files changed, 141 insertions(+) diff --git a/packages/cosmwasm/src/cw3cosmwasmclient.ts b/packages/cosmwasm/src/cw3cosmwasmclient.ts index 5252ed50..f2344a3e 100644 --- a/packages/cosmwasm/src/cw3cosmwasmclient.ts +++ b/packages/cosmwasm/src/cw3cosmwasmclient.ts @@ -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>; + 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 { + return this.queryContractSmart(this.cw3ContractAddress, { threshold: {} }); + } + + public getProposal(proposalId: number): Promise { + return this.queryContractSmart(this.cw3ContractAddress, { proposal: { proposal_id: proposalId } }); + } + + public listProposals(startAfter?: number, limit?: number): Promise { + return this.queryContractSmart(this.cw3ContractAddress, { + list_proposals: { + start_after: startAfter, + limit: limit, + }, + }); + } + + public reverseProposals(startBefore?: number, limit?: number): Promise { + return this.queryContractSmart(this.cw3ContractAddress, { + reverse_proposals: { + start_before: startBefore, + limit: limit, + }, + }); + } + + public getVote(proposalId: number, voter: string): Promise { + return this.queryContractSmart(this.cw3ContractAddress, { + vote: { + proposal_id: proposalId, + voter: voter, + }, + }); + } + + public listVotes(proposalId: number, startAfter?: string, limit?: number): Promise { + return this.queryContractSmart(this.cw3ContractAddress, { + list_votes: { + proposal_id: proposalId, + start_after: startAfter, + limit: limit, + }, + }); + } + + public getVoter(address: string): Promise { + return this.queryContractSmart(this.cw3ContractAddress, { + voter: { + address: address, + }, + }); + } + + public listVoters(startAfter?: string, limit?: number): Promise { + return this.queryContractSmart(this.cw3ContractAddress, { + list_voters: { + start_after: startAfter, + limit: limit, + }, + }); + } + public createMultisigProposal( title: string, description: string, diff --git a/packages/cosmwasm/types/cw3cosmwasmclient.d.ts b/packages/cosmwasm/types/cw3cosmwasmclient.d.ts index c30b639b..72171efe 100644 --- a/packages/cosmwasm/types/cw3cosmwasmclient.d.ts +++ b/packages/cosmwasm/types/cw3cosmwasmclient.d.ts @@ -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>; + 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>, broadcastMode?: BroadcastMode, ); + getThreshold(): Promise; + getProposal(proposalId: number): Promise; + listProposals(startAfter?: number, limit?: number): Promise; + reverseProposals(startBefore?: number, limit?: number): Promise; + getVote(proposalId: number, voter: string): Promise; + listVotes(proposalId: number, startAfter?: string, limit?: number): Promise; + getVoter(address: string): Promise; + listVoters(startAfter?: string, limit?: number): Promise; createMultisigProposal( title: string, description: string,