cosmwasm: Add Cw3CosmWasmClient class

This commit is contained in:
willclarktech 2020-11-17 13:51:31 +01:00
parent bd762847b8
commit 794d87a265
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
2 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,76 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { BroadcastMode, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad";
import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient";
export type Expiration =
| {
readonly at_height: number;
}
| {
readonly at_time: number;
};
export enum Vote {
Yes = "yes",
No = "no",
Abstain = "abstain",
Veto = "veto",
}
export class Cw3CosmWasmClient extends SigningCosmWasmClient {
private readonly cw3ContractAddress: string;
public constructor(
apiUrl: string,
senderAddress: string,
signer: OfflineSigner,
cw3ContractAddress: string,
gasPrice?: GasPrice,
gasLimits?: Partial<GasLimits<CosmWasmFeeTable>>,
broadcastMode?: BroadcastMode,
) {
super(apiUrl, senderAddress, signer, gasPrice, gasLimits, broadcastMode);
this.cw3ContractAddress = cw3ContractAddress;
}
public createMultisigProposal(
title: string,
description: string,
msgs: ReadonlyArray<Record<string, unknown>>,
earliest?: Expiration,
latest?: Expiration,
memo = "",
): Promise<ExecuteResult> {
const handleMsg = {
propose: {
title: title,
description: description,
msgs: msgs,
earliest: earliest,
latest: latest,
},
};
return this.execute(this.cw3ContractAddress, handleMsg, memo);
}
public voteMultisigProposal(proposalId: number, vote: Vote, memo = ""): Promise<ExecuteResult> {
const handleMsg = {
vote: {
proposal_id: proposalId,
vote: vote,
},
};
return this.execute(this.cw3ContractAddress, handleMsg, memo);
}
public executeMultisigProposal(proposalId: number, memo = ""): Promise<ExecuteResult> {
const handleMsg = { execute: { proposal_id: proposalId } };
return this.execute(this.cw3ContractAddress, handleMsg, memo);
}
public closeMultisigProposal(proposalId: number, memo = ""): Promise<ExecuteResult> {
const handleMsg = { close: { proposal_id: proposalId } };
return this.execute(this.cw3ContractAddress, handleMsg, memo);
}
}

View File

@ -0,0 +1,38 @@
import { BroadcastMode, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad";
import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient";
export declare type Expiration =
| {
readonly at_height: number;
}
| {
readonly at_time: number;
};
export declare enum Vote {
Yes = "yes",
No = "no",
Abstain = "abstain",
Veto = "veto",
}
export declare class Cw3CosmWasmClient extends SigningCosmWasmClient {
private readonly cw3ContractAddress;
constructor(
apiUrl: string,
senderAddress: string,
signer: OfflineSigner,
cw3ContractAddress: string,
gasPrice?: GasPrice,
gasLimits?: Partial<GasLimits<CosmWasmFeeTable>>,
broadcastMode?: BroadcastMode,
);
createMultisigProposal(
title: string,
description: string,
msgs: ReadonlyArray<Record<string, unknown>>,
earliest?: Expiration,
latest?: Expiration,
memo?: string,
): Promise<ExecuteResult>;
voteMultisigProposal(proposalId: number, vote: Vote, memo?: string): Promise<ExecuteResult>;
executeMultisigProposal(proposalId: number, memo?: string): Promise<ExecuteResult>;
closeMultisigProposal(proposalId: number, memo?: string): Promise<ExecuteResult>;
}