@@ -401,65 +401,65 @@ class Client {
401
401
}
402
402
}
403
403
404
- Future < List < ITransaction > > getTransactions ({
404
+ Stream < ITransaction > getTransactions ({
405
405
String ? assetCodeFilter,
406
406
int limit = 10 ,
407
407
String ? pagingToken,
408
- }) async {
409
- try {
410
- List <ITransaction > transactionDetails = [];
411
- String ? currentCursor = pagingToken;
408
+ }) async * {
409
+ String ? currentCursor = pagingToken;
410
+ int count = 0 ;
412
411
413
- while (transactionDetails.length < limit) {
414
- var request = _sdk.payments
412
+ try {
413
+ while (count < limit) {
414
+ final request = _sdk.payments
415
415
.forAccount (accountId)
416
416
.order (RequestBuilderOrder .DESC )
417
- .limit (limit);
417
+ .limit (limit)
418
+ .cursor (currentCursor ?? '' );
418
419
419
- if (currentCursor != null ) {
420
- request = request.cursor (currentCursor);
421
- }
420
+ final page = await request.execute ();
421
+ if (page.records.isEmpty) break ;
422
422
423
- final Page < OperationResponse > page = await request. execute () ;
423
+ final tempList = < _TempTx > [] ;
424
424
425
- if (page.records.isEmpty) {
426
- break ;
425
+ for (final response in page.records) {
426
+ if (response is PaymentOperationResponse &&
427
+ (assetCodeFilter == null ||
428
+ response.assetCode == assetCodeFilter)) {
429
+ tempList.add (_TempTx (
430
+ response.links.transaction.toJson ()["href" ],
431
+ response,
432
+ ));
433
+ if (++ count >= limit) break ;
434
+ }
427
435
}
428
436
429
- for (final response in page.records) {
430
- currentCursor = response.pagingToken;
437
+ if (tempList.isEmpty) break ;
431
438
432
- if ( response is ! PaymentOperationResponse ) continue ;
439
+ currentCursor = tempList.last. response.pagingToken ;
433
440
434
- final assetCode = response.assetCode ?? 'XLM' ;
435
- if (assetCodeFilter != null && assetCode != assetCodeFilter) {
436
- continue ;
437
- }
441
+ final memoList = await Future .wait (
442
+ tempList.map ((tx) => getMemoText (tx.href)),
443
+ );
438
444
439
- final memo =
440
- await getMemoText (response.links.transaction.toJson ()["href" ]);
441
-
442
- transactionDetails.add (PaymentTransaction (
443
- pagingToken: response.pagingToken,
444
- hash: response.transactionHash,
445
- from: response.from,
446
- to: response.to,
447
- asset: assetCode,
448
- amount: response.amount,
449
- type: response.to == accountId
445
+ for (var i = 0 ; i < tempList.length; i++ ) {
446
+ final tx = tempList[i].response;
447
+ yield PaymentTransaction (
448
+ pagingToken: tx.pagingToken,
449
+ hash: tx.transactionHash,
450
+ from: tx.from,
451
+ to: tx.to,
452
+ asset: tx.assetCode ?? 'XLM' ,
453
+ amount: tx.amount,
454
+ type: tx.to == accountId
450
455
? TransactionType .Receive
451
456
: TransactionType .Payment ,
452
- status: response.transactionSuccessful,
453
- date: DateTime .parse (response.createdAt).toLocal ().toString (),
454
- memo: memo,
455
- ));
456
-
457
- if (transactionDetails.length >= limit) break ;
457
+ status: tx.transactionSuccessful,
458
+ date: DateTime .parse (tx.createdAt).toLocal ().toString (),
459
+ memo: memoList[i],
460
+ );
458
461
}
459
462
}
460
-
461
- logger.i ('Fetched ${transactionDetails .length } transactions' );
462
- return transactionDetails;
463
463
} catch (e) {
464
464
logger.e ('Failed to get transactions: $e ' );
465
465
throw Exception ('Failed to get transactions' );
0 commit comments