mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-04-07 23:07:41 +00:00
save spark set cache scanned timestamps
This commit is contained in:
parent
b5edc3dad8
commit
1f0798619a
3 changed files with 28 additions and 11 deletions
lib/wallets
|
@ -508,4 +508,6 @@ abstract class WalletInfoKeys {
|
|||
static const String lelantusCoinIsarRescanRequired =
|
||||
"lelantusCoinIsarRescanRequired";
|
||||
static const String enableLelantusScanning = "enableLelantusScanningKey";
|
||||
static const String firoSparkCacheSetTimestampCache =
|
||||
"firoSparkCacheSetTimestampCacheKey";
|
||||
}
|
||||
|
|
|
@ -589,7 +589,12 @@ class FiroWallet<T extends ElectrumXCurrencyInterface> extends Bip39HDWallet<T>
|
|||
@override
|
||||
Future<void> recover({required bool isRescan}) async {
|
||||
// reset last checked values
|
||||
groupIdTimestampUTCMap = {};
|
||||
await info.updateOtherData(
|
||||
newEntries: {
|
||||
WalletInfoKeys.firoSparkCacheSetTimestampCache: <String, int>{},
|
||||
},
|
||||
isar: mainDB.isar,
|
||||
);
|
||||
|
||||
final start = DateTime.now();
|
||||
final root = await getRootHDNode();
|
||||
|
@ -753,7 +758,6 @@ class FiroWallet<T extends ElectrumXCurrencyInterface> extends Bip39HDWallet<T>
|
|||
updateUTXOs(),
|
||||
]);
|
||||
|
||||
|
||||
final List<Future<dynamic>> futures = [];
|
||||
if (enableLelantusScanning) {
|
||||
futures.add(lelantusFutures[0]);
|
||||
|
@ -776,10 +780,10 @@ class FiroWallet<T extends ElectrumXCurrencyInterface> extends Bip39HDWallet<T>
|
|||
await Future.wait([
|
||||
if (enableLelantusScanning)
|
||||
recoverLelantusWallet(
|
||||
latestSetId: latestSetId!,
|
||||
usedSerialNumbers: usedSerialsSet!,
|
||||
setDataMap: setDataMap!,
|
||||
),
|
||||
latestSetId: latestSetId!,
|
||||
usedSerialNumbers: usedSerialsSet!,
|
||||
setDataMap: setDataMap!,
|
||||
),
|
||||
recoverSparkWallet(
|
||||
latestSparkCoinId: latestSparkCoinId,
|
||||
),
|
||||
|
|
|
@ -21,6 +21,7 @@ import '../../../utilities/logger.dart';
|
|||
import '../../crypto_currency/crypto_currency.dart';
|
||||
import '../../crypto_currency/interfaces/electrumx_currency_interface.dart';
|
||||
import '../../isar/models/spark_coin.dart';
|
||||
import '../../isar/models/wallet_info.dart';
|
||||
import '../../models/tx_data.dart';
|
||||
import '../intermediate/bip39_hd_wallet.dart';
|
||||
import 'electrumx_interface.dart';
|
||||
|
@ -720,9 +721,6 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
|
|||
);
|
||||
}
|
||||
|
||||
// TODO: look into persistence for this?
|
||||
Map<int, int> groupIdTimestampUTCMap = {};
|
||||
|
||||
/// Should only be called within the standard wallet [recover] function due to
|
||||
/// mutex locking. Otherwise behaviour MAY be undefined.
|
||||
Future<void> recoverSparkWallet({
|
||||
|
@ -764,9 +762,15 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
|
|||
|
||||
final Map<int, List<List<String>>> rawCoinsBySetId = {};
|
||||
|
||||
final groupIdTimestampUTCMap =
|
||||
info.otherData[WalletInfoKeys.firoSparkCacheSetTimestampCache]
|
||||
as Map? ??
|
||||
{};
|
||||
|
||||
final latestSparkCoinId = await electrumXClient.getSparkLatestCoinId();
|
||||
for (int i = 1; i <= latestSparkCoinId; i++) {
|
||||
final lastCheckedTimeStampUTC = groupIdTimestampUTCMap[i] ?? 0;
|
||||
final lastCheckedTimeStampUTC =
|
||||
groupIdTimestampUTCMap[i.toString()] as int? ?? 0;
|
||||
final info = await FiroCacheCoordinator.getLatestSetInfoForGroupId(
|
||||
i,
|
||||
);
|
||||
|
@ -789,12 +793,19 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
|
|||
rawCoinsBySetId[i] = coinsRaw;
|
||||
}
|
||||
|
||||
groupIdTimestampUTCMap[i] = max(
|
||||
groupIdTimestampUTCMap[i.toString()] = max(
|
||||
lastCheckedTimeStampUTC,
|
||||
info?.timestampUTC ?? lastCheckedTimeStampUTC,
|
||||
);
|
||||
}
|
||||
|
||||
await info.updateOtherData(
|
||||
newEntries: {
|
||||
WalletInfoKeys.firoSparkCacheSetTimestampCache: groupIdTimestampUTCMap,
|
||||
},
|
||||
isar: mainDB.isar,
|
||||
);
|
||||
|
||||
final List<SparkCoin> newlyIdCoins = [];
|
||||
for (final groupId in rawCoinsBySetId.keys) {
|
||||
final myCoins = await compute(
|
||||
|
|
Loading…
Reference in a new issue