From 81f25e9a15ecb3a2c669b20467ee820ff2a411ec Mon Sep 17 00:00:00 2001 From: willclarktech Date: Thu, 26 Nov 2020 15:56:36 +0000 Subject: [PATCH] cosmwasm: Add Cw1CosmWasmClient class --- packages/cosmwasm/src/cw1cosmwasmclient.ts | 52 +++++++++++++++++++ .../cosmwasm/types/cw1cosmwasmclient.d.ts | 25 +++++++++ 2 files changed, 77 insertions(+) create mode 100644 packages/cosmwasm/src/cw1cosmwasmclient.ts create mode 100644 packages/cosmwasm/types/cw1cosmwasmclient.d.ts diff --git a/packages/cosmwasm/src/cw1cosmwasmclient.ts b/packages/cosmwasm/src/cw1cosmwasmclient.ts new file mode 100644 index 00000000..7d187133 --- /dev/null +++ b/packages/cosmwasm/src/cw1cosmwasmclient.ts @@ -0,0 +1,52 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { Account, BroadcastMode, Coin, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad"; + +import { CosmosMsg } from "./cosmosmsg"; +import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient"; + +export interface CanSendResult { + readonly can_send: boolean; +} + +export class Cw1CosmWasmClient extends SigningCosmWasmClient { + public readonly cw1ContractAddress: string; + + public constructor( + apiUrl: string, + signerAddress: string, + signer: OfflineSigner, + cw1ContractAddress: string, + gasPrice?: GasPrice, + gasLimits?: Partial>, + broadcastMode?: BroadcastMode, + ) { + super(apiUrl, signerAddress, signer, gasPrice, gasLimits, broadcastMode); + this.cw1ContractAddress = cw1ContractAddress; + } + + public getAccount(address?: string): Promise { + return super.getAccount(address || this.cw1ContractAddress); + } + + public canSend(msg: CosmosMsg, address = this.senderAddress): Promise { + return this.queryContractSmart(this.cw1ContractAddress, { + can_send: { + sender: address, + msg: msg, + }, + }); + } + + public executeSubkey( + msgs: readonly CosmosMsg[], + memo = "", + transferAmount: readonly Coin[] = [], + ): Promise { + const handleMsg = { + execute: { + msgs: msgs, + }, + }; + return this.execute(this.cw1ContractAddress, handleMsg, memo, transferAmount); + } +} diff --git a/packages/cosmwasm/types/cw1cosmwasmclient.d.ts b/packages/cosmwasm/types/cw1cosmwasmclient.d.ts new file mode 100644 index 00000000..e5f36606 --- /dev/null +++ b/packages/cosmwasm/types/cw1cosmwasmclient.d.ts @@ -0,0 +1,25 @@ +import { Account, BroadcastMode, Coin, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad"; +import { CosmosMsg } from "./cosmosmsg"; +import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient"; +export interface CanSendResult { + readonly can_send: boolean; +} +export declare class Cw1CosmWasmClient extends SigningCosmWasmClient { + readonly cw1ContractAddress: string; + constructor( + apiUrl: string, + signerAddress: string, + signer: OfflineSigner, + cw1ContractAddress: string, + gasPrice?: GasPrice, + gasLimits?: Partial>, + broadcastMode?: BroadcastMode, + ); + getAccount(address?: string): Promise; + canSend(msg: CosmosMsg, address?: string): Promise; + executeSubkey( + msgs: readonly CosmosMsg[], + memo?: string, + transferAmount?: readonly Coin[], + ): Promise; +}