cosmwasm: Refactor CW3 query pagination options
This commit is contained in:
parent
75091a92ed
commit
246da8f4d7
@ -105,7 +105,7 @@ describe("Cw3CosmWasmClient", () => {
|
||||
|
||||
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
|
||||
const client = new Cw3CosmWasmClient(launchpad.endpoint, alice.address0, wallet, contractAddress);
|
||||
const result = await client.listProposals(proposalId - 1, 1);
|
||||
const result = await client.listProposals({ startAfter: proposalId - 1, limit: 1 });
|
||||
|
||||
expect(result).toEqual({
|
||||
proposals: [
|
||||
@ -127,7 +127,7 @@ describe("Cw3CosmWasmClient", () => {
|
||||
|
||||
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
|
||||
const client = new Cw3CosmWasmClient(launchpad.endpoint, alice.address0, wallet, contractAddress);
|
||||
const result = await client.reverseProposals(undefined, 1);
|
||||
const result = await client.reverseProposals({ limit: 1 });
|
||||
|
||||
expect(result).toEqual({
|
||||
proposals: [
|
||||
@ -218,7 +218,7 @@ describe("Cw3CosmWasmClient", () => {
|
||||
},
|
||||
};
|
||||
await client.createMultisigProposal("My proposal", "A proposal to propose proposing proposals", [msg]);
|
||||
const { proposals } = await client.reverseProposals(undefined, 1);
|
||||
const { proposals } = await client.reverseProposals({ limit: 1 });
|
||||
const proposalId = proposals[0].id;
|
||||
const executeResult = await client.executeMultisigProposal(proposalId);
|
||||
expect(executeResult).toBeTruthy();
|
||||
@ -255,7 +255,7 @@ describe("Cw3CosmWasmClient", () => {
|
||||
await proposer.createMultisigProposal("My proposal", "A proposal to propose proposing proposals", [
|
||||
msg,
|
||||
]);
|
||||
const { proposals } = await voter.reverseProposals(undefined, 1);
|
||||
const { proposals } = await voter.reverseProposals({ limit: 1 });
|
||||
const proposalId = proposals[0].id;
|
||||
const voteResult = await voter.voteMultisigProposal(proposalId, Vote.Yes);
|
||||
expect(voteResult).toBeTruthy();
|
||||
@ -306,7 +306,7 @@ describe("Cw3CosmWasmClient", () => {
|
||||
at_height: currentHeight + 5,
|
||||
},
|
||||
);
|
||||
const { proposals } = await voter1.reverseProposals(undefined, 1);
|
||||
const { proposals } = await voter1.reverseProposals({ limit: 1 });
|
||||
const proposalId = proposals[0].id;
|
||||
|
||||
const vote1Result = await voter1.voteMultisigProposal(proposalId, Vote.Abstain);
|
||||
|
||||
@ -55,6 +55,21 @@ export interface VotersResult {
|
||||
readonly voters: readonly VoterResult[];
|
||||
}
|
||||
|
||||
interface StartBeforeNumberPaginationOptions {
|
||||
readonly startBefore?: number;
|
||||
readonly limit?: number;
|
||||
}
|
||||
|
||||
interface StartAfterNumberPaginationOptions {
|
||||
readonly startAfter?: number;
|
||||
readonly limit?: number;
|
||||
}
|
||||
|
||||
interface StartAfterStringPaginationOptions {
|
||||
readonly startAfter?: string;
|
||||
readonly limit?: number;
|
||||
}
|
||||
|
||||
export class Cw3CosmWasmClient extends SigningCosmWasmClient {
|
||||
private readonly cw3ContractAddress: string;
|
||||
|
||||
@ -79,7 +94,9 @@ export class Cw3CosmWasmClient extends SigningCosmWasmClient {
|
||||
return this.queryContractSmart(this.cw3ContractAddress, { proposal: { proposal_id: proposalId } });
|
||||
}
|
||||
|
||||
public listProposals(startAfter?: number, limit?: number): Promise<ProposalsResult> {
|
||||
public listProposals({ startAfter, limit }: StartAfterNumberPaginationOptions = {}): Promise<
|
||||
ProposalsResult
|
||||
> {
|
||||
return this.queryContractSmart(this.cw3ContractAddress, {
|
||||
list_proposals: {
|
||||
start_after: startAfter,
|
||||
@ -88,7 +105,9 @@ export class Cw3CosmWasmClient extends SigningCosmWasmClient {
|
||||
});
|
||||
}
|
||||
|
||||
public reverseProposals(startBefore?: number, limit?: number): Promise<ProposalsResult> {
|
||||
public reverseProposals({ startBefore, limit }: StartBeforeNumberPaginationOptions = {}): Promise<
|
||||
ProposalsResult
|
||||
> {
|
||||
return this.queryContractSmart(this.cw3ContractAddress, {
|
||||
reverse_proposals: {
|
||||
start_before: startBefore,
|
||||
@ -106,7 +125,10 @@ export class Cw3CosmWasmClient extends SigningCosmWasmClient {
|
||||
});
|
||||
}
|
||||
|
||||
public listVotes(proposalId: number, startAfter?: string, limit?: number): Promise<VotesResult> {
|
||||
public listVotes(
|
||||
proposalId: number,
|
||||
{ startAfter, limit }: StartAfterStringPaginationOptions = {},
|
||||
): Promise<VotesResult> {
|
||||
return this.queryContractSmart(this.cw3ContractAddress, {
|
||||
list_votes: {
|
||||
proposal_id: proposalId,
|
||||
@ -124,7 +146,7 @@ export class Cw3CosmWasmClient extends SigningCosmWasmClient {
|
||||
});
|
||||
}
|
||||
|
||||
public listVoters(startAfter?: string, limit?: number): Promise<VotersResult> {
|
||||
public listVoters({ startAfter, limit }: StartAfterStringPaginationOptions = {}): Promise<VotersResult> {
|
||||
return this.queryContractSmart(this.cw3ContractAddress, {
|
||||
list_voters: {
|
||||
start_after: startAfter,
|
||||
|
||||
24
packages/cosmwasm/types/cw3cosmwasmclient.d.ts
vendored
24
packages/cosmwasm/types/cw3cosmwasmclient.d.ts
vendored
@ -47,6 +47,18 @@ export interface VoterResult {
|
||||
export interface VotersResult {
|
||||
readonly voters: readonly VoterResult[];
|
||||
}
|
||||
interface StartBeforeNumberPaginationOptions {
|
||||
readonly startBefore?: number;
|
||||
readonly limit?: number;
|
||||
}
|
||||
interface StartAfterNumberPaginationOptions {
|
||||
readonly startAfter?: number;
|
||||
readonly limit?: number;
|
||||
}
|
||||
interface StartAfterStringPaginationOptions {
|
||||
readonly startAfter?: string;
|
||||
readonly limit?: number;
|
||||
}
|
||||
export declare class Cw3CosmWasmClient extends SigningCosmWasmClient {
|
||||
private readonly cw3ContractAddress;
|
||||
constructor(
|
||||
@ -60,12 +72,15 @@ export declare class Cw3CosmWasmClient extends SigningCosmWasmClient {
|
||||
);
|
||||
getThreshold(): Promise<ThresholdResult>;
|
||||
getProposal(proposalId: number): Promise<ProposalResult>;
|
||||
listProposals(startAfter?: number, limit?: number): Promise<ProposalsResult>;
|
||||
reverseProposals(startBefore?: number, limit?: number): Promise<ProposalsResult>;
|
||||
listProposals({ startAfter, limit }?: StartAfterNumberPaginationOptions): Promise<ProposalsResult>;
|
||||
reverseProposals({ startBefore, limit }?: StartBeforeNumberPaginationOptions): Promise<ProposalsResult>;
|
||||
getVote(proposalId: number, voter: string): Promise<VoteResult>;
|
||||
listVotes(proposalId: number, startAfter?: string, limit?: number): Promise<VotesResult>;
|
||||
listVotes(
|
||||
proposalId: number,
|
||||
{ startAfter, limit }?: StartAfterStringPaginationOptions,
|
||||
): Promise<VotesResult>;
|
||||
getVoter(address: string): Promise<VoterResult>;
|
||||
listVoters(startAfter?: string, limit?: number): Promise<VotersResult>;
|
||||
listVoters({ startAfter, limit }?: StartAfterStringPaginationOptions): Promise<VotersResult>;
|
||||
createMultisigProposal(
|
||||
title: string,
|
||||
description: string,
|
||||
@ -78,3 +93,4 @@ export declare class Cw3CosmWasmClient extends SigningCosmWasmClient {
|
||||
executeMultisigProposal(proposalId: number, memo?: string): Promise<ExecuteResult>;
|
||||
closeMultisigProposal(proposalId: number, memo?: string): Promise<ExecuteResult>;
|
||||
}
|
||||
export {};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user