Add SigningCosmWasmClient.executeMultiple

This commit is contained in:
Simon Warta 2022-06-23 16:42:51 +02:00
parent 7624c0bd12
commit 47f13b231a
3 changed files with 33 additions and 6 deletions

View File

@ -12,7 +12,10 @@ and this project adheres to
`makeMultisignedTx` but returns bytes ready to broadcast ([#1176]).
- @cosmjs/tendermint-rpc: Add fields `codespace` and `info` to
`AbciQueryResponse`.
- @cosmjs/cosmwasm-stargate: Add `SigningCosmWasmClient.executeMultiple`
([#1072]).
[#1072]: https://github.com/cosmos/cosmjs/issues/1072
[#1176]: https://github.com/cosmos/cosmjs/pull/1176
### Fixed

View File

@ -21,6 +21,7 @@ export {
} from "./modules";
export {
ChangeAdminResult,
ExecuteInstruction,
ExecuteResult,
InstantiateOptions,
InstantiateResult,

View File

@ -135,6 +135,12 @@ export interface MigrateResult {
readonly gasUsed: number;
}
export interface ExecuteInstruction {
contractAddress: string;
msg: Record<string, unknown>;
funds?: readonly Coin[];
}
export interface ExecuteResult {
readonly logs: readonly logs.Log[];
/** Block height in which the transaction is included */
@ -396,16 +402,33 @@ export class SigningCosmWasmClient extends CosmWasmClient {
memo = "",
funds?: readonly Coin[],
): Promise<ExecuteResult> {
const executeContractMsg: MsgExecuteContractEncodeObject = {
const instruction: ExecuteInstruction = {
contractAddress: contractAddress,
msg: msg,
funds: funds,
};
return this.executeMultiple(senderAddress, [instruction], fee, memo);
}
/**
* Like `execute` but allows executing multiple messages in one transaction.
*/
public async executeMultiple(
senderAddress: string,
instructions: readonly ExecuteInstruction[],
fee: StdFee | "auto" | number,
memo = "",
): Promise<ExecuteResult> {
const msgs: MsgExecuteContractEncodeObject[] = instructions.map((i) => ({
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
value: MsgExecuteContract.fromPartial({
sender: senderAddress,
contract: contractAddress,
msg: toUtf8(JSON.stringify(msg)),
funds: [...(funds || [])],
contract: i.contractAddress,
msg: toUtf8(JSON.stringify(i.msg)),
funds: [...(i.funds || [])],
}),
};
const result = await this.signAndBroadcast(senderAddress, [executeContractMsg], fee, memo);
}));
const result = await this.signAndBroadcast(senderAddress, msgs, fee, memo);
if (isDeliverTxFailure(result)) {
throw new Error(createDeliverTxResponseErrorMessage(result));
}