5
5
Connection ,
6
6
PACKET_DATA_SIZE ,
7
7
PublicKey ,
8
+ SignatureResult ,
8
9
Signer ,
9
10
Transaction ,
10
11
TransactionInstruction ,
@@ -425,7 +426,7 @@ export async function sendTransactions(
425
426
// In the following section, we wait and constantly check for the transaction to be confirmed
426
427
// and resend the transaction if it is not confirmed within a certain time interval
427
428
// thus handling tx retries on the client side rather than relying on the RPC
428
- let confirmedTx = null ;
429
+ let confirmedTx : SignatureResult | null = null ;
429
430
let retryCount = 0 ;
430
431
431
432
// Get the signature of the transaction with different logic for versioned transactions
@@ -435,57 +436,64 @@ export async function sendTransactions(
435
436
: tx . signature ?? new Uint8Array ( )
436
437
) ;
437
438
438
- try {
439
- const confirmTransactionPromise = connection . confirmTransaction (
440
- {
441
- signature : txSignature ,
442
- blockhash : blockhashResult . value . blockhash ,
443
- lastValidBlockHeight : blockhashResult . value . lastValidBlockHeight ,
444
- } ,
445
- "confirmed"
446
- ) ;
439
+ const confirmTransactionPromise = connection . confirmTransaction (
440
+ {
441
+ signature : txSignature ,
442
+ blockhash : blockhashResult . value . blockhash ,
443
+ lastValidBlockHeight : blockhashResult . value . lastValidBlockHeight ,
444
+ } ,
445
+ "confirmed"
446
+ ) ;
447
447
448
- confirmedTx = null ;
449
- while ( ! confirmedTx ) {
450
- confirmedTx = await Promise . race ( [
451
- confirmTransactionPromise ,
452
- new Promise ( ( resolve ) =>
453
- setTimeout ( ( ) => {
454
- resolve ( null ) ;
455
- } , TX_RETRY_INTERVAL )
456
- ) ,
457
- ] ) ;
458
- if ( confirmedTx ) {
459
- break ;
460
- }
461
- if ( maxRetries && maxRetries < retryCount ) {
462
- break ;
463
- }
464
- console . log (
465
- "Retrying transaction " ,
466
- index ,
467
- " of " ,
468
- transactions . length - 1 ,
469
- " with signature: " ,
470
- txSignature ,
471
- " Retry count: " ,
472
- retryCount
473
- ) ;
474
- retryCount ++ ;
475
-
476
- await connection . sendRawTransaction ( tx . serialize ( ) , {
477
- // Skipping preflight i.e. tx simulation by RPC as we simulated the tx above
478
- // This allows Triton RPCs to send the transaction through multiple pathways for the fastest delivery
479
- skipPreflight : true ,
480
- // Setting max retries to 0 as we are handling retries manually
481
- // Set this manually so that the default is skipped
482
- maxRetries : 0 ,
483
- preflightCommitment : "confirmed" ,
484
- minContextSlot : blockhashResult . context . slot ,
485
- } ) ;
448
+ confirmedTx = null ;
449
+ while ( ! confirmedTx ) {
450
+ confirmedTx = await Promise . race ( [
451
+ new Promise < SignatureResult > ( ( resolve ) => {
452
+ confirmTransactionPromise . then ( ( result ) => {
453
+ resolve ( result . value ) ;
454
+ } ) ;
455
+ } ) ,
456
+ new Promise < null > ( ( resolve ) =>
457
+ setTimeout ( ( ) => {
458
+ resolve ( null ) ;
459
+ } , TX_RETRY_INTERVAL )
460
+ ) ,
461
+ ] ) ;
462
+ if ( confirmedTx ) {
463
+ break ;
486
464
}
487
- } catch ( error ) {
488
- console . error ( error ) ;
465
+ if ( maxRetries && maxRetries < retryCount ) {
466
+ break ;
467
+ }
468
+ console . log (
469
+ "Retrying transaction " ,
470
+ index ,
471
+ " of " ,
472
+ transactions . length - 1 ,
473
+ " with signature: " ,
474
+ txSignature ,
475
+ " Retry count: " ,
476
+ retryCount
477
+ ) ;
478
+ retryCount ++ ;
479
+
480
+ await connection . sendRawTransaction ( tx . serialize ( ) , {
481
+ // Skipping preflight i.e. tx simulation by RPC as we simulated the tx above
482
+ // This allows Triton RPCs to send the transaction through multiple pathways for the fastest delivery
483
+ skipPreflight : true ,
484
+ // Setting max retries to 0 as we are handling retries manually
485
+ // Set this manually so that the default is skipped
486
+ maxRetries : 0 ,
487
+ preflightCommitment : "confirmed" ,
488
+ minContextSlot : blockhashResult . context . slot ,
489
+ } ) ;
490
+ }
491
+ if ( confirmedTx ?. err ) {
492
+ throw new Error (
493
+ `Transaction ${ txSignature } has failed with error: ${ JSON . stringify (
494
+ confirmedTx . err
495
+ ) } `
496
+ ) ;
489
497
}
490
498
491
499
if ( ! confirmedTx ) {
0 commit comments