1
1
import {
2
+ ComputeBudgetProgram ,
2
3
Connection ,
3
4
Keypair ,
4
5
SendOptions ,
@@ -26,6 +27,7 @@ export class SolanaSendSigner<
26
27
private _keypair : Keypair ,
27
28
private _debug : boolean = false ,
28
29
private _sendOpts ?: SendOptions ,
30
+ private _priotifyFeeAmount ?: bigint ,
29
31
) {
30
32
this . _sendOpts = this . _sendOpts ?? {
31
33
preflightCommitment : this . _rpc . commitment ,
@@ -42,6 +44,7 @@ export class SolanaSendSigner<
42
44
43
45
// Handles retrying a Transaction if the error is deemed to be
44
46
// recoverable. Currently handles:
47
+ // - Transaction expired
45
48
// - Blockhash not found
46
49
// - Not enough bytes (storage account not seen yet)
47
50
private retryable ( e : any ) : boolean {
@@ -75,7 +78,6 @@ export class SolanaSendSigner<
75
78
async signAndSend ( tx : UnsignedTransaction [ ] ) : Promise < any [ ] > {
76
79
let { blockhash, lastValidBlockHeight } = await SolanaPlatform . latestBlock (
77
80
this . _rpc ,
78
- 'finalized' ,
79
81
) ;
80
82
81
83
const txids : string [ ] = [ ] ;
@@ -86,6 +88,13 @@ export class SolanaSendSigner<
86
88
} = txn as SolanaUnsignedTransaction < N , C > ;
87
89
console . log ( `Signing: ${ description } for ${ this . address ( ) } ` ) ;
88
90
91
+ if ( this . _priotifyFeeAmount )
92
+ transaction . add (
93
+ ComputeBudgetProgram . setComputeUnitPrice ( {
94
+ microLamports : this . _priotifyFeeAmount ,
95
+ } ) ,
96
+ ) ;
97
+
89
98
if ( this . _debug ) logTxDetails ( transaction ) ;
90
99
91
100
// Try to send the transaction up to 5 times
@@ -103,9 +112,12 @@ export class SolanaSendSigner<
103
112
} catch ( e ) {
104
113
if ( ! this . retryable ( e ) ) throw e ;
105
114
115
+ // TODO: check that the previous one is expired before
116
+ // re-signing
117
+
106
118
// If it is retryable, we should grab a new block hash
107
119
( { blockhash, lastValidBlockHeight } =
108
- await SolanaPlatform . latestBlock ( this . _rpc , 'finalized' ) ) ;
120
+ await SolanaPlatform . latestBlock ( this . _rpc ) ) ;
109
121
}
110
122
}
111
123
}
0 commit comments