Skip to content

Commit

Permalink
sdk: add option to throw on tx send errors (drift-labs#1370)
Browse files Browse the repository at this point in the history
  • Loading branch information
wphan authored Dec 10, 2024
1 parent 4bf852e commit eaa7aeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions sdk/src/tx/baseTxSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export abstract class BaseTxSender implements TxSender {
txHandler: TxHandler;
trackTxLandRate?: boolean;
throwOnTimeoutError: boolean;
throwOnTransactionError: boolean;

// For landing rate calcs
lookbackWindowMinutes: number;
Expand All @@ -65,6 +66,7 @@ export abstract class BaseTxSender implements TxSender {
txLandRateLookbackWindowMinutes = DEFAULT_TX_LAND_RATE_LOOKBACK_WINDOW_MINUTES,
landRateToFeeFunc,
throwOnTimeoutError = true,
throwOnTransactionError = true,
}: {
connection: Connection;
wallet: IWallet;
Expand All @@ -78,6 +80,7 @@ export abstract class BaseTxSender implements TxSender {
txLandRateLookbackWindowMinutes?: number;
landRateToFeeFunc?: (landRate: number) => number;
throwOnTimeoutError?: boolean;
throwOnTransactionError?: boolean;
}) {
this.connection = connection;
this.wallet = wallet;
Expand All @@ -104,6 +107,7 @@ export abstract class BaseTxSender implements TxSender {
this.landRateToFeeFunc =
landRateToFeeFunc ?? this.defaultLandRateToFeeFunc.bind(this);
this.throwOnTimeoutError = throwOnTimeoutError;
this.throwOnTransactionError = throwOnTransactionError;
}

async send(
Expand Down
5 changes: 4 additions & 1 deletion sdk/src/tx/whileValidTxSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class WhileValidTxSender extends BaseTxSender {
txLandRateLookbackWindowMinutes,
landRateToFeeFunc,
throwOnTimeoutError = true,
throwOnTransactionError = true,
}: {
connection: Connection;
wallet: IWallet;
Expand All @@ -82,6 +83,7 @@ export class WhileValidTxSender extends BaseTxSender {
txLandRateLookbackWindowMinutes?: number;
landRateToFeeFunc?: (landRate: number) => number;
throwOnTimeoutError?: boolean;
throwOnTransactionError?: boolean;
}) {
super({
connection,
Expand All @@ -95,6 +97,7 @@ export class WhileValidTxSender extends BaseTxSender {
confirmationStrategy,
landRateToFeeFunc,
throwOnTimeoutError,
throwOnTransactionError,
});
this.retrySleep = retrySleep;

Expand Down Expand Up @@ -240,7 +243,7 @@ export class WhileValidTxSender extends BaseTxSender {

await this.checkConfirmationResultForError(txid, result?.value);

if (result?.value?.err) {
if (result?.value?.err && this.throwOnTransactionError) {
// Fallback error handling if there's a problem reporting the error in checkConfirmationResultForError
throw new SendTransactionError({
action: 'send',
Expand Down

0 comments on commit eaa7aeb

Please sign in to comment.