Sp fixes (#1487)
* feat: missing desktop setting menu * fix: sp utxo pending * fix: change to electrs only scanning, initial migration, and btc-electrum as null ssl
Rafael committed
Jun 10, 2024 at 04:22 UTC
1dd2c7da56f8e63958188d4b59b5018bf05a1346
6 files changed
+67
-30
cw_bitcoin/lib/electrum.dart
+1
-1
@@ -64,7 +64,7 @@ class ElectrumClient {
64
await socket?.close();
65
} catch (_) {}
66
67
- if (useSSL == false) {
67
+ if (useSSL == false || (useSSL == null && uri.toString().contains("btc-electrum"))) {
68
socket = await Socket.connect(host, port, timeout: connectionTimeout);
69
} else {
70
socket = await SecureSocket.connect(host, port,
cw_bitcoin/lib/electrum_wallet.dart
+25
-8
@@ -197,7 +197,7 @@ abstract class ElectrumWalletBase
197
bool silentPaymentsScanningActive = false;
198
199
@action
200
- Future<void> setSilentPaymentsScanning(bool active) async {
200
+ Future<void> setSilentPaymentsScanning(bool active, bool usingElectrs) async {
201
silentPaymentsScanningActive = active;
202
203
if (active) {
@@ -210,7 +210,11 @@ abstract class ElectrumWalletBase
210
}
211
212
if (tip > walletInfo.restoreHeight) {
213
- _setListeners(walletInfo.restoreHeight, chainTipParam: _currentChainTip);
213
+ _setListeners(
214
+ walletInfo.restoreHeight,
215
+ chainTipParam: _currentChainTip,
216
+ usingElectrs: usingElectrs,
217
+ );
218
}
219
} else {
220
alwaysScan = false;
@@ -277,7 +281,12 @@ abstract class ElectrumWalletBase
281
}
282
283
@action
280
- Future<void> _setListeners(int height, {int? chainTipParam, bool? doSingleScan}) async {
284
+ Future<void> _setListeners(
285
+ int height, {
286
+ int? chainTipParam,
287
+ bool? doSingleScan,
288
+ bool? usingElectrs,
289
+ }) async {
290
final chainTip = chainTipParam ?? await getUpdatedChainTip();
291
292
if (chainTip == height) {
@@ -303,7 +312,7 @@ abstract class ElectrumWalletBase
312
chainTip: chainTip,
313
electrumClient: ElectrumClient(),
314
transactionHistoryIds: transactionHistory.transactions.keys.toList(),
306
- node: ScanNode(node!.uri, node!.useSSL),
315
+ node: usingElectrs == true ? ScanNode(node!.uri, node!.useSSL) : null,
316
labels: walletAddresses.labels,
317
labelIndexes: walletAddresses.silentAddresses
318
.where((addr) => addr.type == SilentPaymentsAddresType.p2sp && addr.index >= 1)
@@ -1122,8 +1131,13 @@ abstract class ElectrumWalletBase
1131
1132
@action
1133
@override
1125
- Future<void> rescan(
1126
- {required int height, int? chainTip, ScanData? scanData, bool? doSingleScan}) async {
1134
+ Future<void> rescan({
1135
+ required int height,
1136
+ int? chainTip,
1137
+ ScanData? scanData,
1138
+ bool? doSingleScan,
1139
+ bool? usingElectrs,
1140
+ }) async {
1141
silentPaymentsScanningActive = true;
1142
_setListeners(height, doSingleScan: doSingleScan);
1143
}
@@ -1820,7 +1834,7 @@ class ScanData {
1834
final SendPort sendPort;
1835
final SilentPaymentOwner silentAddress;
1836
final int height;
1823
- final ScanNode node;
1837
+ final ScanNode? node;
1838
final BasedUtxoNetwork network;
1839
final int chainTip;
1840
final ElectrumClient electrumClient;
@@ -1881,7 +1895,10 @@ Future<void> startRefresh(ScanData scanData) async {
1895
scanData.sendPort.send(SyncResponse(syncHeight, syncingStatus));
1896
1897
final electrumClient = scanData.electrumClient;
1884
- await electrumClient.connectToUri(scanData.node.uri, useSSL: scanData.node.useSSL);
1898
+ await electrumClient.connectToUri(
1899
+ scanData.node?.uri ?? Uri.parse("tcp://electrs.cakewallet.com:50001"),
1900
+ useSSL: scanData.node?.useSSL ?? false,
1901
+ );
1902
1903
if (tweaksSubscription == null) {
1904
final count = scanData.isSingleScan ? 1 : TWEAKS_COUNT;
cw_core/lib/get_height_by_date.dart
+1
@@ -245,6 +245,7 @@ Future<int> getHavenCurrentHeight() async {
245
246
// Data taken from https://timechaincalendar.com/
247
const bitcoinDates = {
248
+ "2024-06": 846005,
249
"2024-05": 841590,
250
"2024-04": 837182,
251
"2024-03": 832623,
lib/bitcoin/cw_bitcoin.dart
+4
-20
@@ -514,18 +514,10 @@ class CWBitcoin extends Bitcoin {
514
@override
515
Future<void> setScanningActive(Object wallet, bool active) async {
516
final bitcoinWallet = wallet as ElectrumWallet;
517
-
518
- if (active && !(await getNodeIsElectrsSPEnabled(wallet))) {
519
- final node = Node(
520
- useSSL: false,
521
- uri: 'electrs.cakewallet.com:${(wallet.network == BitcoinNetwork.testnet ? 50002 : 50001)}',
522
- );
523
- node.type = WalletType.bitcoin;
524
-
525
- await bitcoinWallet.connectToNode(node: node);
526
- }
527
-
528
- bitcoinWallet.setSilentPaymentsScanning(active);
517
+ bitcoinWallet.setSilentPaymentsScanning(
518
+ active,
519
+ active && (await getNodeIsElectrsSPEnabled(wallet)),
520
+ );
521
}
522
523
@override
@@ -540,14 +532,6 @@ class CWBitcoin extends Bitcoin {
532
@override
533
Future<void> rescan(Object wallet, {required int height, bool? doSingleScan}) async {
534
final bitcoinWallet = wallet as ElectrumWallet;
543
- if (!(await getNodeIsElectrsSPEnabled(wallet))) {
544
- final node = Node(
545
- useSSL: false,
546
- uri: 'electrs.cakewallet.com:${(wallet.network == BitcoinNetwork.testnet ? 50002 : 50001)}',
547
- );
548
- node.type = WalletType.bitcoin;
549
- await bitcoinWallet.connectToNode(node: node);
550
- }
535
bitcoinWallet.rescan(height: height, doSingleScan: doSingleScan);
536
}
537
lib/entities/default_settings_migration.dart
+35
@@ -227,6 +227,8 @@ Future<void> defaultSettingsMigration(
227
break;
228
case 34:
229
await _addElectRsNode(nodes, sharedPreferences);
230
+ case 35:
231
+ await _switchElectRsNode(nodes, sharedPreferences);
232
break;
233
default:
234
break;
@@ -825,6 +827,39 @@ Future<void> _addElectRsNode(Box<Node> nodeSource, SharedPreferences sharedPrefe
827
}
828
}
829
830
+Future<void> _switchElectRsNode(Box<Node> nodeSource, SharedPreferences sharedPreferences) async {
831
+ final currentBitcoinNodeId =
832
+ sharedPreferences.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
833
+ final currentBitcoinNode =
834
+ nodeSource.values.firstWhere((node) => node.key == currentBitcoinNodeId);
835
+ final needToReplaceCurrentBitcoinNode =
836
+ currentBitcoinNode.uri.toString().contains('electrs.cakewallet.com');
837
+
838
+ if (!needToReplaceCurrentBitcoinNode) return;
839
+
840
+ final btcElectrumNode = nodeSource.values.firstWhereOrNull(
841
+ (node) => node.uri.toString().contains('btc-electrum.cakewallet.com'),
842
+ );
843
+
844
+ if (btcElectrumNode == null) {
845
+ final newBtcElectrumBitcoinNode = Node(
846
+ uri: newCakeWalletBitcoinUri,
847
+ type: WalletType.bitcoin,
848
+ useSSL: false,
849
+ );
850
+ await nodeSource.add(newBtcElectrumBitcoinNode);
851
+ await sharedPreferences.setInt(
852
+ PreferencesKey.currentBitcoinElectrumSererIdKey,
853
+ newBtcElectrumBitcoinNode.key as int,
854
+ );
855
+ } else {
856
+ await sharedPreferences.setInt(
857
+ PreferencesKey.currentBitcoinElectrumSererIdKey,
858
+ btcElectrumNode.key as int,
859
+ );
860
+ }
861
+}
862
+
863
Future<void> checkCurrentNodes(
864
Box<Node> nodeSource, Box<Node> powNodeSource, SharedPreferences sharedPreferences) async {
865
final currentMoneroNodeId = sharedPreferences.getInt(PreferencesKey.currentNodeIdKey);
lib/main.dart
+1
-1
@@ -202,7 +202,7 @@ Future<void> initializeAppConfigs() async {
202
transactionDescriptions: transactionDescriptions,
203
secureStorage: secureStorage,
204
anonpayInvoiceInfo: anonpayInvoiceInfo,
205
- initialMigrationVersion: 34,
205
+ initialMigrationVersion: 35,
206
);
207
}
208