Skip to content

Commit 70acbe6

Browse files
committed
reset private balance changes
1 parent 63874c6 commit 70acbe6

4 files changed

Lines changed: 14 additions & 76 deletions

File tree

lib/db/sqlite/firo_cache_coordinator.dart

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,38 +109,22 @@ abstract class FiroCacheCoordinator {
109109
return;
110110
}
111111

112-
final int effectivePrevSize;
113-
if (prevSize > meta.size) {
114-
Logging.instance.w(
115-
"Spark cache size mismatch for groupId=$groupId: "
116-
"prevSize=$prevSize > meta.size=${meta.size}. "
117-
"Falling back to full refetch for this set.",
118-
);
119-
effectivePrevSize = 0;
120-
} else {
121-
effectivePrevSize = prevSize;
122-
}
123-
124-
final numberOfCoinsToFetch = meta.size - effectivePrevSize;
125-
if (numberOfCoinsToFetch <= 0) {
126-
// Already up to date for this block hash/set hash.
127-
return;
128-
}
112+
final numberOfCoinsToFetch = meta.size - prevSize;
129113

130114
final fullSectorCount = numberOfCoinsToFetch ~/ sectorSize;
131115
final remainder = numberOfCoinsToFetch % sectorSize;
132116

133117
final List<dynamic> coins = [];
134118

135119
for (int i = 0; i < fullSectorCount; i++) {
136-
final start = effectivePrevSize + (i * sectorSize);
120+
final start = (i * sectorSize);
137121
final data = await client.getSparkAnonymitySetBySector(
138122
coinGroupId: groupId,
139123
latestBlock: meta.blockHash,
140124
startIndex: start,
141125
endIndex: start + sectorSize,
142126
);
143-
progressUpdated?.call(((i + 1) * sectorSize), numberOfCoinsToFetch);
127+
progressUpdated?.call(start + sectorSize, numberOfCoinsToFetch);
144128

145129
coins.addAll(data);
146130
}
@@ -149,8 +133,8 @@ abstract class FiroCacheCoordinator {
149133
final data = await client.getSparkAnonymitySetBySector(
150134
coinGroupId: groupId,
151135
latestBlock: meta.blockHash,
152-
startIndex: effectivePrevSize + numberOfCoinsToFetch - remainder,
153-
endIndex: effectivePrevSize + numberOfCoinsToFetch,
136+
startIndex: numberOfCoinsToFetch - remainder,
137+
endIndex: numberOfCoinsToFetch,
154138
);
155139
progressUpdated?.call(numberOfCoinsToFetch, numberOfCoinsToFetch);
156140

lib/db/sqlite/firo_cache_writer.dart

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -90,46 +90,21 @@ FCResult _updateSparkAnonSetCoinsWith(
9090
for (final coin in coins) {
9191
db.execute(
9292
"""
93-
INSERT OR IGNORE INTO SparkCoin (serialized, txHash, context, groupId)
93+
INSERT INTO SparkCoin (serialized, txHash, context, groupId)
9494
VALUES (?, ?, ?, ?);
9595
""",
9696
[coin.serialized, coin.txHash, coin.context, coin.groupId],
9797
);
98-
final coinIdResult = db.select(
99-
"""
100-
SELECT id
101-
FROM SparkCoin
102-
WHERE serialized = ? AND txHash = ? AND context = ? AND groupId = ?
103-
LIMIT 1;
104-
""",
105-
[coin.serialized, coin.txHash, coin.context, coin.groupId],
106-
);
107-
if (coinIdResult.isEmpty) {
108-
throw Exception(
109-
"Failed to resolve SparkCoin id after insert/ignore operation",
110-
);
111-
}
112-
final coinId = coinIdResult.first["id"] as int;
98+
final coinId = db.lastInsertRowId;
11399

114100
// finally add the row id to the newly added set
115-
final hasSetCoin = db.select(
101+
db.execute(
116102
"""
117-
SELECT 1
118-
FROM SparkSetCoins
119-
WHERE setId = ? AND coinId = ?
120-
LIMIT 1;
103+
INSERT INTO SparkSetCoins (setId, coinId)
104+
VALUES (?, ?);
121105
""",
122106
[setId, coinId],
123107
);
124-
if (hasSetCoin.isEmpty) {
125-
db.execute(
126-
"""
127-
INSERT INTO SparkSetCoins (setId, coinId)
128-
VALUES (?, ?);
129-
""",
130-
[setId, coinId],
131-
);
132-
}
133108
}
134109

135110
db.execute("COMMIT;");

lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/more_features/more_features_dialog.dart

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import '../../../../../utilities/assets.dart';
2323
import '../../../../../utilities/text_styles.dart';
2424
import '../../../../../wallets/crypto_currency/crypto_currency.dart';
2525
import '../../../../../wallets/isar/models/wallet_info.dart';
26-
import '../../../../../wallets/isar/providers/all_wallets_info_provider.dart';
2726
import '../../../../../wallets/isar/providers/wallet_info_provider.dart';
2827
import '../../../../../wallets/wallet/wallet_mixin_interfaces/mweb_interface.dart';
2928
import '../../../../../widgets/custom_buttons/draggable_switch_button.dart';
@@ -379,7 +378,6 @@ class _MoreFeaturesDialogState extends ConsumerState<MoreFeaturesDialog> {
379378

380379
case WalletFeature.clearSparkCache:
381380
return _MoreFeaturesClearSparkCacheItem(
382-
walletId: widget.walletId,
383381
cryptoCurrency: wallet.cryptoCurrency,
384382
);
385383

@@ -656,23 +654,21 @@ class _MoreFeaturesItemBase extends StatelessWidget {
656654
}
657655
}
658656

659-
class _MoreFeaturesClearSparkCacheItem extends ConsumerStatefulWidget {
657+
class _MoreFeaturesClearSparkCacheItem extends StatefulWidget {
660658
const _MoreFeaturesClearSparkCacheItem({
661659
super.key,
662-
required this.walletId,
663660
required this.cryptoCurrency,
664661
});
665662

666-
final String walletId;
667663
final CryptoCurrency cryptoCurrency;
668664

669665
@override
670-
ConsumerState<_MoreFeaturesClearSparkCacheItem> createState() =>
666+
State<_MoreFeaturesClearSparkCacheItem> createState() =>
671667
_MoreFeaturesClearSparkCacheItemState();
672668
}
673669

674670
class _MoreFeaturesClearSparkCacheItemState
675-
extends ConsumerState<_MoreFeaturesClearSparkCacheItem> {
671+
extends State<_MoreFeaturesClearSparkCacheItem> {
676672
bool _onPressedLock = false;
677673

678674
static const label = "Reset Spark electrumx cache";
@@ -689,23 +685,6 @@ class _MoreFeaturesClearSparkCacheItemState
689685
await FiroCacheCoordinator.clearSharedCache(
690686
widget.cryptoCurrency.network,
691687
);
692-
final isar = ref.read(mainDBProvider).isar;
693-
final sparkWalletInfos = ref
694-
.read(pAllWalletsInfo)
695-
.where(
696-
(info) =>
697-
info.coin.identifier == widget.cryptoCurrency.identifier,
698-
)
699-
.toList();
700-
for (final info in sparkWalletInfos) {
701-
await info.updateOtherData(
702-
newEntries: {
703-
WalletInfoKeys.firoSparkCacheSetBlockHashCache:
704-
<String, String>{},
705-
},
706-
isar: isar,
707-
);
708-
}
709688
setState(() {
710689
// trigger rebuild for cache size display
711690
});

lib/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ mixin SparkInterface<T extends ElectrumXCurrencyInterface>
394394

395395
Future<Address> generateNextSparkAddress({required bool saveToDB}) async {
396396
final currentDiversifier =
397-
(await getCurrentReceivingSparkAddress())?.derivationIndex;
397+
(await getCurrentReceivingAddress())?.derivationIndex;
398398
// if current is null, start at index 1
399399
int diversifier = (currentDiversifier ?? 0) + 1;
400400
if (diversifier == libSpark.sparkChange) {

0 commit comments

Comments
 (0)