From ef96f3b76c3fc1e7a42b835879142e7dde4a0f2f Mon Sep 17 00:00:00 2001 From: sneurlax Date: Wed, 29 May 2024 17:45:42 -0500 Subject: [PATCH] Add enableLelantusScanning bool and restore/rescan logic Squashed commit msgs: add (currently unused) bool enableLelantusScanning to WalletInfo only do Lelantus things if Lelantus is enabled 6ac468 --- lib/wallets/isar/models/wallet_info.dart | 1 + lib/wallets/wallet/impl/firo_wallet.dart | 89 +++++++++++++++--------- 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/lib/wallets/isar/models/wallet_info.dart b/lib/wallets/isar/models/wallet_info.dart index a84fe4348..351229c29 100644 --- a/lib/wallets/isar/models/wallet_info.dart +++ b/lib/wallets/isar/models/wallet_info.dart @@ -507,4 +507,5 @@ abstract class WalletInfoKeys { static const String tezosDerivationPath = "tezosDerivationPathKey"; static const String lelantusCoinIsarRescanRequired = "lelantusCoinIsarRescanRequired"; + static const String enableLelantusScanning = "enableLelantusScanning"; } diff --git a/lib/wallets/wallet/impl/firo_wallet.dart b/lib/wallets/wallet/impl/firo_wallet.dart index dce8cd9fa..510d08cfb 100644 --- a/lib/wallets/wallet/impl/firo_wallet.dart +++ b/lib/wallets/wallet/impl/firo_wallet.dart @@ -610,13 +610,25 @@ class FiroWallet extends Bip39HDWallet await mainDB.deleteWalletBlockchainData(walletId); } + // Parse otherDataJsonString to get the enableLelantusScanning value. + bool? enableLelantusScanning = false; + if (info.otherDataJsonString != null) { + final otherDataJson = json.decode(info.otherDataJsonString!); + enableLelantusScanning = + otherDataJson["enableLelantusScanning"] as bool? ?? false; + } + // lelantus - final latestSetId = await electrumXClient.getLelantusLatestCoinId(); - final setDataMapFuture = getSetDataMap(latestSetId); - final usedSerialNumbersFuture = - electrumXCachedClient.getUsedCoinSerials( - cryptoCurrency: info.coin, - ); + int? latestSetId; + Future>? setDataMapFuture; + Future>? usedSerialNumbersFuture; + if (enableLelantusScanning) { + latestSetId = await electrumXClient.getLelantusLatestCoinId(); + setDataMapFuture = getSetDataMap(latestSetId); + usedSerialNumbersFuture = electrumXCachedClient.getUsedCoinSerials( + cryptoCurrency: info.coin, + ); + } // spark final latestSparkCoinId = await electrumXClient.getSparkLatestCoinId(); @@ -736,39 +748,52 @@ class FiroWallet extends Bip39HDWallet updateUTXOs(), ]); - final futureResults = await Future.wait([ - usedSerialNumbersFuture, - setDataMapFuture, - sparkAnonSetFuture, - sparkUsedCoinTagsFuture, - ]); + List> futures = []; + + futures.add(sparkAnonSetFuture); + futures.add(sparkUsedCoinTagsFuture); + if (enableLelantusScanning) { + futures.add(usedSerialNumbersFuture!); + futures.add(setDataMapFuture!); + } + + final futureResults = await Future.wait(futures); // lelantus - final usedSerialsSet = (futureResults[0] as List).toSet(); - final setDataMap = futureResults[1] as Map; + Set? usedSerialsSet; + Map? setDataMap; + if (enableLelantusScanning) { + usedSerialsSet = (futureResults[2] as List).toSet(); + setDataMap = futureResults[3] as Map; + } // spark - final sparkAnonymitySet = futureResults[2] as Map; - final sparkSpentCoinTags = futureResults[3] as Set; + final sparkAnonymitySet = futureResults[0] as Map; + final sparkSpentCoinTags = futureResults[1] as Set; if (Util.isDesktop) { - await Future.wait([ - recoverLelantusWallet( - latestSetId: latestSetId, - usedSerialNumbers: usedSerialsSet, - setDataMap: setDataMap, - ), - recoverSparkWallet( - anonymitySet: sparkAnonymitySet, - spentCoinTags: sparkSpentCoinTags, - ), - ]); + List> futures = []; + if (enableLelantusScanning) { + futures.add(recoverLelantusWallet( + latestSetId: latestSetId!, + usedSerialNumbers: usedSerialsSet!, + setDataMap: setDataMap!, + )); + } + futures.add(recoverSparkWallet( + anonymitySet: sparkAnonymitySet, + spentCoinTags: sparkSpentCoinTags, + )); + + await Future.wait(futures); } else { - await recoverLelantusWallet( - latestSetId: latestSetId, - usedSerialNumbers: usedSerialsSet, - setDataMap: setDataMap, - ); + if (enableLelantusScanning) { + await recoverLelantusWallet( + latestSetId: latestSetId!, + usedSerialNumbers: usedSerialsSet!, + setDataMap: setDataMap!, + ); + } await recoverSparkWallet( anonymitySet: sparkAnonymitySet, spentCoinTags: sparkSpentCoinTags,