Skip to content

Commit

Permalink
feat: ✨ add param explicitSignerData to signAndBroadcast method
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideSegullo committed Sep 6, 2024
1 parent efd062d commit a8e1210
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
18 changes: 11 additions & 7 deletions packages/cosmwasm-stargate/src/signingcosmwasmclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,12 @@ export class SigningCosmWasmClient extends CosmWasmClient {
fee: StdFee | "auto" | number,
memo = "",
timeoutHeight?: bigint,
explicitSignerData?: SignerData,
): Promise<DeliverTxResponse> {
let usedFee: StdFee;

const { accountNumber, sequence } = await this.getSequence(signerAddress);
let signerData: SignerData | undefined = explicitSignerData

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (92% of all statements in
the enclosing function
have an explicit semicolon).
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.");
Expand All @@ -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();
Expand Down
20 changes: 12 additions & 8 deletions packages/stargate/src/signingstargateclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
createStakingAminoConverters,
createVestingAminoConverters,
} from "./modules";
import { DeliverTxResponse, StargateClient, StargateClientOptions } from "./stargateclient";
import { DeliverTxResponse, SequenceResponse, StargateClient, StargateClientOptions } from "./stargateclient";

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import SequenceResponse.

export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [
["/cosmos.base.v1beta1.Coin", Coin],
Expand Down Expand Up @@ -315,10 +315,12 @@ export class SigningStargateClient extends StargateClient {
fee: StdFee | "auto" | number,
memo = "",
timeoutHeight?: bigint,
explicitSignerData?: SignerData,
): Promise<DeliverTxResponse> {
let usedFee: StdFee;

const { accountNumber, sequence } = await this.getSequence(signerAddress);
let signerData: SignerData | undefined = explicitSignerData

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (92% of all statements in
the enclosing function
have an explicit semicolon).
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.");
Expand All @@ -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();
Expand Down

0 comments on commit a8e1210

Please sign in to comment.