mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-16 17:27:39 +00:00
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:
parent
6ac468c55c
commit
ef96f3b76c
2 changed files with 58 additions and 32 deletions
|
@ -507,4 +507,5 @@ abstract class WalletInfoKeys {
|
|||
static const String tezosDerivationPath = "tezosDerivationPathKey";
|
||||
static const String lelantusCoinIsarRescanRequired =
|
||||
"lelantusCoinIsarRescanRequired";
|
||||
static const String enableLelantusScanning = "enableLelantusScanning";
|
||||
}
|
||||
|
|
|
@ -610,13 +610,25 @@ class FiroWallet<T extends ElectrumXCurrencyInterface> extends Bip39HDWallet<T>
|
|||
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<Map<int, dynamic>>? setDataMapFuture;
|
||||
Future<List<String>>? 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<T extends ElectrumXCurrencyInterface> extends Bip39HDWallet<T>
|
|||
updateUTXOs(),
|
||||
]);
|
||||
|
||||
final futureResults = await Future.wait([
|
||||
usedSerialNumbersFuture,
|
||||
setDataMapFuture,
|
||||
sparkAnonSetFuture,
|
||||
sparkUsedCoinTagsFuture,
|
||||
]);
|
||||
List<Future<dynamic>> 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<String>).toSet();
|
||||
final setDataMap = futureResults[1] as Map<dynamic, dynamic>;
|
||||
Set<String>? usedSerialsSet;
|
||||
Map<dynamic, dynamic>? setDataMap;
|
||||
if (enableLelantusScanning) {
|
||||
usedSerialsSet = (futureResults[2] as List<String>).toSet();
|
||||
setDataMap = futureResults[3] as Map<dynamic, dynamic>;
|
||||
}
|
||||
|
||||
// spark
|
||||
final sparkAnonymitySet = futureResults[2] as Map<String, dynamic>;
|
||||
final sparkSpentCoinTags = futureResults[3] as Set<String>;
|
||||
final sparkAnonymitySet = futureResults[0] as Map<String, dynamic>;
|
||||
final sparkSpentCoinTags = futureResults[1] as Set<String>;
|
||||
|
||||
if (Util.isDesktop) {
|
||||
await Future.wait([
|
||||
recoverLelantusWallet(
|
||||
latestSetId: latestSetId,
|
||||
usedSerialNumbers: usedSerialsSet,
|
||||
setDataMap: setDataMap,
|
||||
),
|
||||
recoverSparkWallet(
|
||||
anonymitySet: sparkAnonymitySet,
|
||||
spentCoinTags: sparkSpentCoinTags,
|
||||
),
|
||||
]);
|
||||
List<Future<dynamic>> 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,
|
||||
|
|
Loading…
Reference in a new issue