File tree 2 files changed +20
-3
lines changed
2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 6
6
ConfirmOptions ,
7
7
Connection ,
8
8
Finality ,
9
+ ParsedTransactionWithMeta ,
9
10
PublicKey ,
10
11
SYSVAR_CLOCK_PUBKEY ,
11
12
SYSVAR_EPOCH_SCHEDULE_PUBKEY ,
@@ -267,6 +268,7 @@ export class MatchingEngineProgram {
267
268
eventSlot : number ,
268
269
signature : string ,
269
270
currentSlotInfo ?: SlotInfo ,
271
+ parsedTransaction ?: ParsedTransactionWithMeta ,
270
272
) => void ,
271
273
commitment : Finality = "confirmed" ,
272
274
) : number {
@@ -279,7 +281,17 @@ export class MatchingEngineProgram {
279
281
connection . onSlotChange ( async ( slotInfo ) => {
280
282
// TODO: Make this more efficient by fetching multiple parsed transactions.
281
283
while ( ! unprocessedTxs . isEmpty ( ) ) {
282
- const { signature, eventSlot } = unprocessedTxs . head ( ) ;
284
+ const head = unprocessedTxs . head ( ) ;
285
+
286
+ // This check is superfluous. But we do it anyway to make sure the unprocessed
287
+ // transaction queue is actually empty.
288
+ //
289
+ // Once the ArrayQueue has been thoroughly tested, we can remove this check.
290
+ if ( head === null ) {
291
+ break ;
292
+ }
293
+
294
+ const { signature, eventSlot } = head ;
283
295
284
296
const parsedTx = await connection . getParsedTransaction ( signature , {
285
297
commitment,
@@ -316,6 +328,7 @@ export class MatchingEngineProgram {
316
328
eventSlot ,
317
329
signature ,
318
330
slotInfo ,
331
+ parsedTx ,
319
332
) ;
320
333
}
321
334
}
Original file line number Diff line number Diff line change @@ -20,9 +20,9 @@ export class ArrayQueue<T> {
20
20
this . _data = new Array ( capacity ?? 256 ) . fill ( null ) ;
21
21
}
22
22
23
- head ( ) : T {
23
+ head ( ) : T | null {
24
24
if ( this . isEmpty ( ) ) {
25
- throw new Error ( "queue is empty" ) ;
25
+ return null ;
26
26
}
27
27
28
28
return this . _data [ this . _index ] ! ;
@@ -42,6 +42,10 @@ export class ArrayQueue<T> {
42
42
}
43
43
44
44
dequeue ( ) : void {
45
+ if ( this . isEmpty ( ) ) {
46
+ return ;
47
+ }
48
+
45
49
const data = this . _data ;
46
50
const index = this . _index ;
47
51
You can’t perform that action at this time.
0 commit comments