Skip to content

Commit

Permalink
sdk: add option to skip confirmation for FastTxSender (#795)
Browse files Browse the repository at this point in the history
* sdk: add option to skip confirmation for FastTxSender

* default to false
  • Loading branch information
crispheaney authored Dec 27, 2023
1 parent 08efd1e commit bf4928c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions sdk/src/tx/fastSingleTxSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class FastSingleTxSender extends BaseTxSender {
additionalConnections: Connection[];
timoutCount = 0;
blockhashQueue: string[] = [];
skipConfirmation: boolean;

public constructor({
connection,
Expand All @@ -35,13 +36,15 @@ export class FastSingleTxSender extends BaseTxSender {
timeout = DEFAULT_TIMEOUT,
blockhashRefreshInterval = DEFAULT_BLOCKHASH_REFRESH,
additionalConnections = new Array<Connection>(),
skipConfirmation = false,
}: {
connection: Connection;
wallet: IWallet;
opts?: ConfirmOptions;
timeout?: number;
blockhashRefreshInterval?: number;
additionalConnections?;
skipConfirmation?: boolean;
}) {
super({ connection, wallet, opts, timeout, additionalConnections });
this.connection = connection;
Expand All @@ -50,6 +53,7 @@ export class FastSingleTxSender extends BaseTxSender {
this.timeout = timeout;
this.blockhashRefreshInterval = blockhashRefreshInterval;
this.additionalConnections = additionalConnections;
this.skipConfirmation = skipConfirmation;
this.startBlockhashRefreshLoop();
}

Expand Down Expand Up @@ -144,12 +148,14 @@ export class FastSingleTxSender extends BaseTxSender {
this.sendToAdditionalConnections(rawTransaction, opts);

let slot: number;
try {
const result = await this.confirmTransaction(txid, opts.commitment);
slot = result.context.slot;
} catch (e) {
console.error(e);
throw e;
if (!this.skipConfirmation) {
try {
const result = await this.confirmTransaction(txid, opts.commitment);
slot = result.context.slot;
} catch (e) {
console.error(e);
throw e;
}
}

return { txSig: txid, slot };
Expand Down

0 comments on commit bf4928c

Please sign in to comment.