@@ -381,43 +381,68 @@ class Client {
381
381
}
382
382
}
383
383
384
- Future <List <ITransaction >> getTransactions ({String ? assetCodeFilter}) async {
385
- Page <OperationResponse > payments = await _sdk.payments
386
- .forAccount (accountId)
387
- .order (RequestBuilderOrder .DESC )
388
- .execute ();
389
- List <ITransaction > transactionDetails = [];
390
-
391
- if (payments.records.isNotEmpty) {
392
- for (OperationResponse response in payments.records) {
393
- if (response is PaymentOperationResponse ) {
394
- final memoText = await this
395
- .getMemoText (response.links.transaction.toJson ()["href" ]);
396
- String assetCode = response.assetCode ?? 'XLM' ;
397
- if (assetCodeFilter == null || assetCode == assetCodeFilter) {
398
- final details = PaymentTransaction (
399
- hash: response.transactionHash,
400
- from: response.from,
401
- to: response.to,
402
- asset: response.assetCode.toString (),
403
- amount: response.amount,
404
- type: response.to == this .accountId
405
- ? TransactionType .Receive
406
- : TransactionType .Payment ,
407
- status: response.transactionSuccessful,
408
- date: DateTime .parse (response.createdAt).toLocal ().toString (),
409
- memo: memoText);
410
-
411
- transactionDetails.add (details);
384
+ Future <List <ITransaction >> getTransactions (
385
+ {String ? assetCodeFilter, int ? limit, int ? offset}) async {
386
+ try {
387
+ var paymentsRequest =
388
+ _sdk.payments.forAccount (accountId).order (RequestBuilderOrder .DESC );
389
+
390
+ // Add pagination
391
+ if (limit != null ) {
392
+ paymentsRequest = paymentsRequest.limit (limit);
393
+ }
394
+
395
+ // get first page
396
+ if (offset != null && offset > 0 ) {
397
+ var initialPage = await _sdk.payments
398
+ .forAccount (accountId)
399
+ .order (RequestBuilderOrder .DESC )
400
+ .limit (offset)
401
+ .execute ();
402
+
403
+ if (initialPage.records.isNotEmpty) {
404
+ // Use the last record's paging token as cursor
405
+ paymentsRequest =
406
+ paymentsRequest.cursor (initialPage.records.last.pagingToken);
407
+ }
408
+ }
409
+
410
+ Page <OperationResponse > payments = await paymentsRequest.execute ();
411
+ List <ITransaction > transactionDetails = [];
412
+
413
+ if (payments.records.isNotEmpty) {
414
+ for (OperationResponse response in payments.records) {
415
+ if (response is PaymentOperationResponse ) {
416
+ final memoText = await this
417
+ .getMemoText (response.links.transaction.toJson ()["href" ]);
418
+ String assetCode = response.assetCode ?? 'XLM' ;
419
+ if (assetCodeFilter == null || assetCode == assetCodeFilter) {
420
+ final details = PaymentTransaction (
421
+ hash: response.transactionHash,
422
+ from: response.from,
423
+ to: response.to,
424
+ asset: response.assetCode.toString (),
425
+ amount: response.amount,
426
+ type: response.to == this .accountId
427
+ ? TransactionType .Receive
428
+ : TransactionType .Payment ,
429
+ status: response.transactionSuccessful,
430
+ date: DateTime .parse (response.createdAt).toLocal ().toString (),
431
+ memo: memoText);
432
+
433
+ transactionDetails.add (details);
434
+ }
435
+ } else {
436
+ logger.i ("Unhandled operation type: ${response .runtimeType }" );
412
437
}
413
- } else {
414
- logger.i ("Unhandled operation type: ${response .runtimeType }" );
415
438
}
416
439
}
417
- } else {
418
- logger.i ("No payment records found." );
440
+
441
+ return transactionDetails;
442
+ } catch (e) {
443
+ logger.e ('Failed to get transactions: $e ' );
444
+ throw Exception ('Could not get transactions due to $e ' );
419
445
}
420
- return transactionDetails;
421
446
}
422
447
423
448
Future <List <BalanceInfo >> getBalance () async {
0 commit comments