From 7ad6f5205af9e92b84baecf0c15818c89b27bd01 Mon Sep 17 00:00:00 2001 From: CryptoFish Date: Mon, 16 Jan 2023 17:44:21 +0100 Subject: [PATCH] use paging to retrieve account blocks --- .../dashboard/realtime_statistics_bloc.dart | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/blocs/dashboard/realtime_statistics_bloc.dart b/lib/blocs/dashboard/realtime_statistics_bloc.dart index 8b1895dd..f4a38f31 100644 --- a/lib/blocs/dashboard/realtime_statistics_bloc.dart +++ b/lib/blocs/dashboard/realtime_statistics_bloc.dart @@ -12,15 +12,35 @@ class RealtimeStatisticsBloc extends DashboardBaseBloc> { int chainHeight = (await zenon!.ledger.getFrontierMomentum()).height; int height = chainHeight - kMomentumsPerWeek > 0 ? chainHeight - kMomentumsPerWeek - : 2; - List response = (await zenon!.ledger.getAccountBlocksByHeight( + : 1; + int pageIndex = 0; + int pageSize = 10; + bool isLastPage = false; + List blockList = []; + + while (!isLastPage) { + List response = (await zenon!.ledger.getAccountBlocksByPage( Address.parse(kSelectedAddress!), - height == 0 ? 0 : height - 1, + pageIndex: pageIndex, + pageSize: pageSize, )) - .list ?? - []; - if (response.isNotEmpty) { - return response; + .list ?? + []; + + if (response.isEmpty) + break; + + blockList.addAll(response); + + if (response.last.confirmationDetail!.momentumHeight <= height) + break; + + pageIndex += 1; + isLastPage = response.length < pageSize; + } + + if (blockList.isNotEmpty) { + return blockList; } else { throw 'No available data'; }