don't attempt to identify already checked used coin tags and add some more logging

This commit is contained in:
julian 2024-05-09 12:25:32 -06:00
parent 12a0e4c289
commit cccf1a7012

View file

@ -602,9 +602,6 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
} }
} }
// TODO lots of room for performance improvements here. Should be similar to
// recoverSparkWallet but only fetch and check anonymity set data that we
// have not yet parsed.
Future<void> refreshSparkData() async { Future<void> refreshSparkData() async {
final sparkAddresses = await mainDB.isar.addresses final sparkAddresses = await mainDB.isar.addresses
.where() .where()
@ -620,6 +617,7 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
final latestSparkCoinId = await electrumXClient.getSparkLatestCoinId(); final latestSparkCoinId = await electrumXClient.getSparkLatestCoinId();
final blockHash = await _getCachedSparkBlockHash(); final blockHash = await _getCachedSparkBlockHash();
final startNumber = await _getSparkCoinsStartNumber();
final anonymitySetFuture = blockHash == null final anonymitySetFuture = blockHash == null
? electrumXCachedClient.getSparkAnonymitySet( ? electrumXCachedClient.getSparkAnonymitySet(
@ -630,9 +628,10 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
coinGroupId: latestSparkCoinId.toString(), coinGroupId: latestSparkCoinId.toString(),
startBlockHash: blockHash, startBlockHash: blockHash,
); );
final spentCoinTagsFuture =
electrumXClient.getSparkUsedCoinsTags(startNumber: 0); final spentCoinTagsFuture = startNumber == null
// electrumXCachedClient.getSparkUsedCoinsTags(coin: info.coin); ? electrumXCachedClient.getSparkUsedCoinsTags(coin: info.coin)
: electrumXClient.getSparkUsedCoinsTags(startNumber: startNumber);
final futureResults = await Future.wait([ final futureResults = await Future.wait([
anonymitySetFuture, anonymitySetFuture,
@ -670,7 +669,11 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
// update blockHash in cache // update blockHash in cache
final String newBlockHash = final String newBlockHash =
base64ToReverseHex(anonymitySet["blockHash"] as String); base64ToReverseHex(anonymitySet["blockHash"] as String);
await _setCachedSparkBlockHash(newBlockHash);
await Future.wait([
_setCachedSparkBlockHash(newBlockHash),
_setSparkCoinsStartNumber(spentCoinTags.length - 1),
]);
} }
// check current coins // check current coins
@ -692,8 +695,10 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
// refresh spark balance // refresh spark balance
await refreshSparkBalance(); await refreshSparkBalance();
} catch (e, s) { } catch (e, s) {
// todo logging Logging.instance.log(
"$runtimeType $walletId ${info.name}: $e\n$s",
level: LogLevel.Error,
);
rethrow; rethrow;
} }
} }
@ -790,8 +795,10 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
// refresh spark balance // refresh spark balance
await refreshSparkBalance(); await refreshSparkBalance();
} catch (e, s) { } catch (e, s) {
// todo logging Logging.instance.log(
"$runtimeType $walletId ${info.name}: $e\n$s",
level: LogLevel.Error,
);
rethrow; rethrow;
} }
} }
@ -1154,7 +1161,6 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
generate: true, generate: true,
); );
final int i = 0;
for (int i = 0; i < recipients.length; i++) { for (int i = 0; i < recipients.length; i++) {
final recipient = recipients[i]; final recipient = recipients[i];
final out = ( final out = (
@ -1597,6 +1603,7 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
// ====================== Private ============================================ // ====================== Private ============================================
final _kSparkAnonSetCachedBlockHashKey = "SparkAnonSetCachedBlockHashKey"; final _kSparkAnonSetCachedBlockHashKey = "SparkAnonSetCachedBlockHashKey";
final _kSparkCoinsStartNumberKey = "SparkCoinsStartNumberKey";
Future<String?> _getCachedSparkBlockHash() async { Future<String?> _getCachedSparkBlockHash() async {
return info.otherData[_kSparkAnonSetCachedBlockHashKey] as String?; return info.otherData[_kSparkAnonSetCachedBlockHashKey] as String?;
@ -1609,6 +1616,17 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
); );
} }
Future<int?> _getSparkCoinsStartNumber() async {
return info.otherData[_kSparkCoinsStartNumberKey] as int?;
}
Future<void> _setSparkCoinsStartNumber(int startNumber) async {
await info.updateOtherData(
newEntries: {_kSparkCoinsStartNumberKey: startNumber},
isar: mainDB.isar,
);
}
Future<void> _addOrUpdateSparkCoins(List<SparkCoin> coins) async { Future<void> _addOrUpdateSparkCoins(List<SparkCoin> coins) async {
if (coins.isNotEmpty) { if (coins.isNotEmpty) {
await mainDB.isar.writeTxn(() async { await mainDB.isar.writeTxn(() async {