diff --git a/CHANGELOG.md b/CHANGELOG.md index 8feb57d..591c5f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.11 +### Updates +[ADD] Add pagination property for transaction + ## 0.0.10 ### Bug fix [ADD] Fix transaction type in transaction query parameter diff --git a/README.md b/README.md index c1767a9..99a9c1f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Add this to your package's pubspec.yaml file: ```dart dependencies: - xpx_chain_sdk: 0.0.10 + xpx_chain_sdk: 0.0.11 ``` **2. Install it** diff --git a/lib/src/api/api_account_routes.dart b/lib/src/api/api_account_routes.dart index 0526536..6d72dcd 100644 --- a/lib/src/api/api_account_routes.dart +++ b/lib/src/api/api_account_routes.dart @@ -122,7 +122,7 @@ class AccountRoutesApi { /// param: pageSize The number of transactions to return for each request. /// param: id The transaction id up to which transactions are returned. /// param: ordering The ordering criteria: * -id - Descending order by id. * id - Ascending order by id. - Future> transactions(PublicAccount account, + Future transactions(PublicAccount account, [TransactionQueryParams? txnQueryParams]) async { // query params final List queryParams = []; @@ -137,8 +137,8 @@ class AccountRoutesApi { if (txnQueryParams != null && !txnQueryParams.firstLevel) { firstLevel = false; } - return internalGetTransactions( - _apiClient, _transactionsRoute, queryParams, null, + return internalGetTransactionsWithPagination( + _apiClient, _transactionsRoute, queryParams, firstLevel: firstLevel); } diff --git a/lib/src/model/transaction.dart b/lib/src/model/transaction.dart index 88be2e6..dcd98aa 100644 --- a/lib/src/model/transaction.dart +++ b/lib/src/model/transaction.dart @@ -21,6 +21,7 @@ import '../api/dto.dart'; import 'transaction/buffer/buffer.dart' as $buffer; import 'transaction/buffer/transactions_buffer.dart' as $txn_buffer; +part 'transaction/transaction_with_pagination.dart'; part 'transaction/fee_calculation_strategy.dart'; part 'transaction/abstract_transaction.dart'; part 'transaction/asset_id.dart'; diff --git a/lib/src/model/transaction/transaction_internal.dart b/lib/src/model/transaction/transaction_internal.dart index beae715..36057e1 100644 --- a/lib/src/model/transaction/transaction_internal.dart +++ b/lib/src/model/transaction/transaction_internal.dart @@ -519,3 +519,26 @@ Future> internalGetTransactions(ApiClient client, String path, return []; } } + +Future internalGetTransactionsWithPagination( + ApiClient client, String path, List queryParams, + {bool firstLevel = true}) async { + final response = await client.get(path, null, queryParams); + + if (response.statusCode! >= 299) { + throw ApiException(response.statusCode!, response.data); + } else if (response.data != null) { + final List resp = client.deserialize(response.data, 'List'); + final allTransaction = + resp.map(deserializeDTO).toList().cast(); + + if (firstLevel) { + return TransactionWithPagination.fromDto( + allTransaction, response.data['pagination']); + } else + return TransactionWithPagination.fromDto( + fixAggregate(allTransaction), response.data['pagination']); + } else { + return TransactionWithPagination([], null); + } +} diff --git a/lib/src/model/transaction/transaction_with_pagination.dart b/lib/src/model/transaction/transaction_with_pagination.dart new file mode 100644 index 0000000..e0a901e --- /dev/null +++ b/lib/src/model/transaction/transaction_with_pagination.dart @@ -0,0 +1,31 @@ +part of xpx_chain_sdk.model.transaction; + +class TransactionWithPagination { + final List transactions; + final Pagination? pagination; + + TransactionWithPagination(this.transactions, this.pagination); + + factory TransactionWithPagination.fromDto( + List transactions, Map? json) => + TransactionWithPagination( + transactions, + json == null ? null : Pagination.fromJson(json), + ); +} + +class Pagination { + final int totalEntries; + final int pageNumber; + final int pageSize; + final int totalPages; + + Pagination( + this.totalEntries, this.pageNumber, this.pageSize, this.totalPages); + + factory Pagination.fromJson(Map json) => Pagination( + json['totalEntries'], + json['pageNumber'], + json['pageSize'], + json['totalPages']); +} diff --git a/pubspec.yaml b/pubspec.yaml index a2b2589..6ffe64e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: xpx_chain_sdk -version: 0.0.10 +version: 0.0.11 #author: 'Eleazar Garrido , ProximaX Devops ' description: 'The ProximaX Sirius Chain Dart SDK works as a async lightweight Dart library for interacting with the Sirius Blockchain.' homepage: https://github.com/proximax-storage