From 73001d085ef3900d4e93b8ffb6dcc1bbcb1875c2 Mon Sep 17 00:00:00 2001 From: clangenb <37865735+clangenb@users.noreply.github.com> Date: Fri, 8 Dec 2023 12:36:37 +0700 Subject: [PATCH 1/3] fix getting newbie tickets after endorsing (#1597) --- app/lib/service/substrate_api/encointer/encointer_api.dart | 1 + app/lib/service/tx/lib/src/submit_tx_wrappers.dart | 4 ++-- .../community_account_store/community_account_store.dart | 7 ++++--- .../community_account_store/community_account_store.g.dart | 4 ++-- .../encointer_account_store/encointer_account_store.dart | 5 +++-- .../encointer_account_store/encointer_account_store.g.dart | 5 +++-- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/lib/service/substrate_api/encointer/encointer_api.dart b/app/lib/service/substrate_api/encointer/encointer_api.dart index 7d38356ae..7d5e3461e 100644 --- a/app/lib/service/substrate_api/encointer/encointer_api.dart +++ b/app/lib/service/substrate_api/encointer/encointer_api.dart @@ -98,6 +98,7 @@ class EncointerApi { getReputations(); getMeetupTimeOverride(); store.encointer.communityAccount?.getNumberOfNewbieTicketsForBootstrapper(); + store.encointer.account?.getNumberOfNewbieTicketsForReputable(); } /// Queries the Scheduler pallet: encointerScheduler.currentPhase(). diff --git a/app/lib/service/tx/lib/src/submit_tx_wrappers.dart b/app/lib/service/tx/lib/src/submit_tx_wrappers.dart index bdd56f0e5..566729b85 100644 --- a/app/lib/service/tx/lib/src/submit_tx_wrappers.dart +++ b/app/lib/service/tx/lib/src/submit_tx_wrappers.dart @@ -90,8 +90,8 @@ Future submitEndorseNewcomer( api, txParams, onFinish: (BuildContext txPageContext, ExtrinsicReport report) { - store.encointer.account!.getNumberOfNewbieTicketsForReputable(); - store.encointer.communityAccount!.getNumberOfNewbieTicketsForBootstrapper(); + store.encointer.account!.getNumberOfNewbieTicketsForReputable(at: report.blockHashBytes); + store.encointer.communityAccount!.getNumberOfNewbieTicketsForBootstrapper(at: report.blockHashBytes); }, ); } diff --git a/app/lib/store/encointer/sub_stores/community_store/community_account_store/community_account_store.dart b/app/lib/store/encointer/sub_stores/community_store/community_account_store/community_account_store.dart index 9a0b5ba9f..2199c9944 100644 --- a/app/lib/store/encointer/sub_stores/community_store/community_account_store/community_account_store.dart +++ b/app/lib/store/encointer/sub_stores/community_store/community_account_store/community_account_store.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:typed_data'; import 'package:encointer_wallet/service/substrate_api/api.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -171,10 +172,10 @@ abstract class _CommunityAccountStore with Store { } @action - Future getNumberOfNewbieTicketsForBootstrapper() async { - // Todo: #923 This returns 5 for non-bootstrappers as it naively calculates the amount of tickes based on + Future getNumberOfNewbieTicketsForBootstrapper({Uint8List? at}) async { + // Todo: #923 This returns 5 for non-bootstrappers as it naively calculates the amount of tickets based on // the amount of burned tickets. This is essentially wrong and leads to workarounds that we need to do on dart side. - numberOfNewbieTicketsForBootstrapper = await webApi.encointer.getNumberOfNewbieTicketsForBootstrapper(); + numberOfNewbieTicketsForBootstrapper = await webApi.encointer.getNumberOfNewbieTicketsForBootstrapper(at: at); } void initStore(Function? cacheFn) { diff --git a/app/lib/store/encointer/sub_stores/community_store/community_account_store/community_account_store.g.dart b/app/lib/store/encointer/sub_stores/community_store/community_account_store/community_account_store.g.dart index 8eee10d98..8b628c454 100644 --- a/app/lib/store/encointer/sub_stores/community_store/community_account_store/community_account_store.g.dart +++ b/app/lib/store/encointer/sub_stores/community_store/community_account_store/community_account_store.g.dart @@ -160,9 +160,9 @@ mixin _$CommunityAccountStore on _CommunityAccountStore, Store { AsyncAction('_CommunityAccountStore.getNumberOfNewbieTicketsForBootstrapper', context: context); @override - Future getNumberOfNewbieTicketsForBootstrapper() { + Future getNumberOfNewbieTicketsForBootstrapper({Uint8List? at}) { return _$getNumberOfNewbieTicketsForBootstrapperAsyncAction - .run(() => super.getNumberOfNewbieTicketsForBootstrapper()); + .run(() => super.getNumberOfNewbieTicketsForBootstrapper(at: at)); } late final _$_CommunityAccountStoreActionController = diff --git a/app/lib/store/encointer/sub_stores/encointer_account_store/encointer_account_store.dart b/app/lib/store/encointer/sub_stores/encointer_account_store/encointer_account_store.dart index 2ecd2268c..959f3b480 100644 --- a/app/lib/store/encointer/sub_stores/encointer_account_store/encointer_account_store.dart +++ b/app/lib/store/encointer/sub_stores/encointer_account_store/encointer_account_store.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:typed_data'; import 'package:json_annotation/json_annotation.dart'; import 'package:mobx/mobx.dart'; @@ -143,8 +144,8 @@ abstract class _EncointerAccountStore with Store { } @action - Future getNumberOfNewbieTicketsForReputable() async { - numberOfNewbieTicketsForReputable = await webApi.encointer.getNumberOfNewbieTicketsForReputable(); + Future getNumberOfNewbieTicketsForReputable({Uint8List? at}) async { + numberOfNewbieTicketsForReputable = await webApi.encointer.getNumberOfNewbieTicketsForReputable(at: at); } void initStore(Function? cacheFn) { diff --git a/app/lib/store/encointer/sub_stores/encointer_account_store/encointer_account_store.g.dart b/app/lib/store/encointer/sub_stores/encointer_account_store/encointer_account_store.g.dart index 5cb5b0b44..8ed164784 100644 --- a/app/lib/store/encointer/sub_stores/encointer_account_store/encointer_account_store.g.dart +++ b/app/lib/store/encointer/sub_stores/encointer_account_store/encointer_account_store.g.dart @@ -143,8 +143,9 @@ mixin _$EncointerAccountStore on _EncointerAccountStore, Store { AsyncAction('_EncointerAccountStore.getNumberOfNewbieTicketsForReputable', context: context); @override - Future getNumberOfNewbieTicketsForReputable() { - return _$getNumberOfNewbieTicketsForReputableAsyncAction.run(() => super.getNumberOfNewbieTicketsForReputable()); + Future getNumberOfNewbieTicketsForReputable({Uint8List? at}) { + return _$getNumberOfNewbieTicketsForReputableAsyncAction + .run(() => super.getNumberOfNewbieTicketsForReputable(at: at)); } late final _$_EncointerAccountStoreActionController = From a5e913add9cc16bc619132b68a444ea8d6473e29 Mon Sep 17 00:00:00 2001 From: clangenb <37865735+clangenb@users.noreply.github.com> Date: Fri, 8 Dec 2023 12:58:24 +0700 Subject: [PATCH 2/3] [encointerApi] re-introduce `pollAggregatedAccountData` (#1598) * [encointerApi] re-introduce `pollAggregatedAccountData` * fmt --- .../encointer/encointer_api.dart | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/lib/service/substrate_api/encointer/encointer_api.dart b/app/lib/service/substrate_api/encointer/encointer_api.dart index 7d5e3461e..7858854a8 100644 --- a/app/lib/service/substrate_api/encointer/encointer_api.dart +++ b/app/lib/service/substrate_api/encointer/encointer_api.dart @@ -477,7 +477,7 @@ class EncointerApi { if (cid != null && pubKey != null && pubKey.isNotEmpty) { final address = store.account.currentAddress; - final data = await getAggregatedAccountData(cid, pubKey); + final data = await pollAggregatedAccountDataUntilNextPhase(phase, cid, pubKey); store.encointer.setAggregatedAccountData(cid, address, data); } @@ -487,6 +487,31 @@ class EncointerApi { }); } + /// Polls the aggregated account data until its ceremony phase field equals [nextPhase]. + /// + /// This is needed because because the latestHash slightly lags behind, as it involves a + /// network request based on the `bestHead` subscription. + Future pollAggregatedAccountDataUntilNextPhase( + CeremonyPhase nextPhase, + CommunityIdentifier cid, + String pubKey, + ) async { + while (true) { + final data = await getAggregatedAccountData(cid, pubKey, at: store.chain.latestHash); + final phase = data.global.ceremonyPhase; + + if (nextPhase == phase) { + Log.d('[EncointerApi] received account data valid for the new ceremony phase', 'EncointerApi'); + return data; + } else { + await Future.delayed( + const Duration(seconds: 3), + () => Log.d('[EncointerApi] polling account data until next phase is reached...', 'EncointerApi'), + ); + } + } + } + /// Subscribes to new community identifies. Future subscribeCommunityIdentifiers() async { // contrary to the JS subscriptions, we don't get the current From 28a634331a7f19fffc0bdd18387d140bb4af11ac Mon Sep 17 00:00:00 2001 From: clangenb <37865735+clangenb@users.noreply.github.com> Date: Fri, 8 Dec 2023 13:03:24 +0700 Subject: [PATCH 3/3] v1.11.6 --- app/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 5be159cfa..7b24a30cd 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -14,7 +14,7 @@ description: EncointerWallet made with Flutter. # bump version already while working on new release, bumping build number at the same time # bump build number even more, if needed to clarify what's deployed -version: 1.11.5+876 +version: 1.11.6+877 publish_to: none