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
This commit is contained in:
sneurlax 2024-05-29 17:45:42 -05:00
parent 6ac468c55c
commit ef96f3b76c
2 changed files with 58 additions and 32 deletions

View file

@ -507,4 +507,5 @@ abstract class WalletInfoKeys {
static const String tezosDerivationPath = "tezosDerivationPathKey"; static const String tezosDerivationPath = "tezosDerivationPathKey";
static const String lelantusCoinIsarRescanRequired = static const String lelantusCoinIsarRescanRequired =
"lelantusCoinIsarRescanRequired"; "lelantusCoinIsarRescanRequired";
static const String enableLelantusScanning = "enableLelantusScanning";
} }

View file

@ -610,13 +610,25 @@ class FiroWallet<T extends ElectrumXCurrencyInterface> extends Bip39HDWallet<T>
await mainDB.deleteWalletBlockchainData(walletId); 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 // lelantus
final latestSetId = await electrumXClient.getLelantusLatestCoinId(); int? latestSetId;
final setDataMapFuture = getSetDataMap(latestSetId); Future<Map<int, dynamic>>? setDataMapFuture;
final usedSerialNumbersFuture = Future<List<String>>? usedSerialNumbersFuture;
electrumXCachedClient.getUsedCoinSerials( if (enableLelantusScanning) {
cryptoCurrency: info.coin, latestSetId = await electrumXClient.getLelantusLatestCoinId();
); setDataMapFuture = getSetDataMap(latestSetId);
usedSerialNumbersFuture = electrumXCachedClient.getUsedCoinSerials(
cryptoCurrency: info.coin,
);
}
// spark // spark
final latestSparkCoinId = await electrumXClient.getSparkLatestCoinId(); final latestSparkCoinId = await electrumXClient.getSparkLatestCoinId();
@ -736,39 +748,52 @@ class FiroWallet<T extends ElectrumXCurrencyInterface> extends Bip39HDWallet<T>
updateUTXOs(), updateUTXOs(),
]); ]);
final futureResults = await Future.wait([ List<Future<dynamic>> futures = [];
usedSerialNumbersFuture,
setDataMapFuture, futures.add(sparkAnonSetFuture);
sparkAnonSetFuture, futures.add(sparkUsedCoinTagsFuture);
sparkUsedCoinTagsFuture, if (enableLelantusScanning) {
]); futures.add(usedSerialNumbersFuture!);
futures.add(setDataMapFuture!);
}
final futureResults = await Future.wait(futures);
// lelantus // lelantus
final usedSerialsSet = (futureResults[0] as List<String>).toSet(); Set<String>? usedSerialsSet;
final setDataMap = futureResults[1] as Map<dynamic, dynamic>; Map<dynamic, dynamic>? setDataMap;
if (enableLelantusScanning) {
usedSerialsSet = (futureResults[2] as List<String>).toSet();
setDataMap = futureResults[3] as Map<dynamic, dynamic>;
}
// spark // spark
final sparkAnonymitySet = futureResults[2] as Map<String, dynamic>; final sparkAnonymitySet = futureResults[0] as Map<String, dynamic>;
final sparkSpentCoinTags = futureResults[3] as Set<String>; final sparkSpentCoinTags = futureResults[1] as Set<String>;
if (Util.isDesktop) { if (Util.isDesktop) {
await Future.wait([ List<Future<dynamic>> futures = [];
recoverLelantusWallet( if (enableLelantusScanning) {
latestSetId: latestSetId, futures.add(recoverLelantusWallet(
usedSerialNumbers: usedSerialsSet, latestSetId: latestSetId!,
setDataMap: setDataMap, usedSerialNumbers: usedSerialsSet!,
), setDataMap: setDataMap!,
recoverSparkWallet( ));
anonymitySet: sparkAnonymitySet, }
spentCoinTags: sparkSpentCoinTags, futures.add(recoverSparkWallet(
), anonymitySet: sparkAnonymitySet,
]); spentCoinTags: sparkSpentCoinTags,
));
await Future.wait(futures);
} else { } else {
await recoverLelantusWallet( if (enableLelantusScanning) {
latestSetId: latestSetId, await recoverLelantusWallet(
usedSerialNumbers: usedSerialsSet, latestSetId: latestSetId!,
setDataMap: setDataMap, usedSerialNumbers: usedSerialsSet!,
); setDataMap: setDataMap!,
);
}
await recoverSparkWallet( await recoverSparkWallet(
anonymitySet: sparkAnonymitySet, anonymitySet: sparkAnonymitySet,
spentCoinTags: sparkSpentCoinTags, spentCoinTags: sparkSpentCoinTags,