cosmwasm: Add Cw1CosmWasmClient class
This commit is contained in:
parent
c0c73ca507
commit
81f25e9a15
52
packages/cosmwasm/src/cw1cosmwasmclient.ts
Normal file
52
packages/cosmwasm/src/cw1cosmwasmclient.ts
Normal file
@ -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<GasLimits<CosmWasmFeeTable>>,
|
||||
broadcastMode?: BroadcastMode,
|
||||
) {
|
||||
super(apiUrl, signerAddress, signer, gasPrice, gasLimits, broadcastMode);
|
||||
this.cw1ContractAddress = cw1ContractAddress;
|
||||
}
|
||||
|
||||
public getAccount(address?: string): Promise<Account | undefined> {
|
||||
return super.getAccount(address || this.cw1ContractAddress);
|
||||
}
|
||||
|
||||
public canSend(msg: CosmosMsg, address = this.senderAddress): Promise<CanSendResult> {
|
||||
return this.queryContractSmart(this.cw1ContractAddress, {
|
||||
can_send: {
|
||||
sender: address,
|
||||
msg: msg,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public executeSubkey(
|
||||
msgs: readonly CosmosMsg[],
|
||||
memo = "",
|
||||
transferAmount: readonly Coin[] = [],
|
||||
): Promise<ExecuteResult> {
|
||||
const handleMsg = {
|
||||
execute: {
|
||||
msgs: msgs,
|
||||
},
|
||||
};
|
||||
return this.execute(this.cw1ContractAddress, handleMsg, memo, transferAmount);
|
||||
}
|
||||
}
|
||||
25
packages/cosmwasm/types/cw1cosmwasmclient.d.ts
vendored
Normal file
25
packages/cosmwasm/types/cw1cosmwasmclient.d.ts
vendored
Normal file
@ -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<GasLimits<CosmWasmFeeTable>>,
|
||||
broadcastMode?: BroadcastMode,
|
||||
);
|
||||
getAccount(address?: string): Promise<Account | undefined>;
|
||||
canSend(msg: CosmosMsg, address?: string): Promise<CanSendResult>;
|
||||
executeSubkey(
|
||||
msgs: readonly CosmosMsg[],
|
||||
memo?: string,
|
||||
transferAmount?: readonly Coin[],
|
||||
): Promise<ExecuteResult>;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user