From a8e12106c4b2fa2dbb2e34332290388f1f864534 Mon Sep 17 00:00:00 2001 From: Davide Segullo Date: Fri, 6 Sep 2024 16:09:04 +0200 Subject: [PATCH] feat: :sparkles: add param explicitSignerData to signAndBroadcast method --- .../src/signingcosmwasmclient.ts | 18 ++++++++++------- .../stargate/src/signingstargateclient.ts | 20 +++++++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index 9736cc53d0..f2e7416c44 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -621,10 +621,12 @@ export class SigningCosmWasmClient extends CosmWasmClient { fee: StdFee | "auto" | number, memo = "", timeoutHeight?: bigint, + explicitSignerData?: SignerData, ): Promise { let usedFee: StdFee; - const { accountNumber, sequence } = await this.getSequence(signerAddress); + let signerData: SignerData | undefined = explicitSignerData + const { sequence, accountNumber } = explicitSignerData ? explicitSignerData : await this.getSequence(signerAddress); if (fee == "auto" || typeof fee === "number") { assertDefined(this.gasPrice, "Gas price must be set in the client options when auto gas is used."); @@ -635,13 +637,15 @@ export class SigningCosmWasmClient extends CosmWasmClient { usedFee = fee; } - const chainId = await this.getChainId(); + if (!signerData) { + const chainId = await this.getChainId(); - const signerData: SignerData = { - accountNumber: accountNumber, - sequence: sequence, - chainId: chainId, - }; + signerData = { + accountNumber: accountNumber, + sequence: sequence, + chainId: chainId, + }; + } const txRaw = await this.sign(signerAddress, messages, usedFee, memo, signerData, timeoutHeight); const txBytes = TxRaw.encode(txRaw).finish(); diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index 7bf42195a6..27e8964168 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -50,7 +50,7 @@ import { createStakingAminoConverters, createVestingAminoConverters, } from "./modules"; -import { DeliverTxResponse, StargateClient, StargateClientOptions } from "./stargateclient"; +import { DeliverTxResponse, SequenceResponse, StargateClient, StargateClientOptions } from "./stargateclient"; export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [ ["/cosmos.base.v1beta1.Coin", Coin], @@ -315,10 +315,12 @@ export class SigningStargateClient extends StargateClient { fee: StdFee | "auto" | number, memo = "", timeoutHeight?: bigint, + explicitSignerData?: SignerData, ): Promise { let usedFee: StdFee; - const { accountNumber, sequence } = await this.getSequence(signerAddress); + let signerData: SignerData | undefined = explicitSignerData + const { sequence, accountNumber } = explicitSignerData ? explicitSignerData : await this.getSequence(signerAddress); if (fee == "auto" || typeof fee === "number") { assertDefined(this.gasPrice, "Gas price must be set in the client options when auto gas is used."); @@ -329,13 +331,15 @@ export class SigningStargateClient extends StargateClient { usedFee = fee; } - const chainId = await this.getChainId(); + if (!signerData) { + const chainId = await this.getChainId(); - const signerData: SignerData = { - accountNumber: accountNumber, - sequence: sequence, - chainId: chainId, - }; + signerData = { + accountNumber: accountNumber, + sequence: sequence, + chainId: chainId, + }; + } const txRaw = await this.sign(signerAddress, messages, usedFee, memo, signerData, timeoutHeight); const txBytes = TxRaw.encode(txRaw).finish();