* feat: missing desktop setting menu

* fix: sp utxo pending

* fix: change to electrs only scanning, initial migration, and btc-electrum as null ssl
This commit is contained in:
Rafael 2024-06-10 04:22:57 -03:00 committed by GitHub
parent 30dc8f9238
commit 1dd2c7da56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 67 additions and 30 deletions

View file

@ -64,7 +64,7 @@ class ElectrumClient {
await socket?.close();
} catch (_) {}
if (useSSL == false) {
if (useSSL == false || (useSSL == null && uri.toString().contains("btc-electrum"))) {
socket = await Socket.connect(host, port, timeout: connectionTimeout);
} else {
socket = await SecureSocket.connect(host, port,

View file

@ -197,7 +197,7 @@ abstract class ElectrumWalletBase
bool silentPaymentsScanningActive = false;
@action
Future<void> setSilentPaymentsScanning(bool active) async {
Future<void> setSilentPaymentsScanning(bool active, bool usingElectrs) async {
silentPaymentsScanningActive = active;
if (active) {
@ -210,7 +210,11 @@ abstract class ElectrumWalletBase
}
if (tip > walletInfo.restoreHeight) {
_setListeners(walletInfo.restoreHeight, chainTipParam: _currentChainTip);
_setListeners(
walletInfo.restoreHeight,
chainTipParam: _currentChainTip,
usingElectrs: usingElectrs,
);
}
} else {
alwaysScan = false;
@ -277,7 +281,12 @@ abstract class ElectrumWalletBase
}
@action
Future<void> _setListeners(int height, {int? chainTipParam, bool? doSingleScan}) async {
Future<void> _setListeners(
int height, {
int? chainTipParam,
bool? doSingleScan,
bool? usingElectrs,
}) async {
final chainTip = chainTipParam ?? await getUpdatedChainTip();
if (chainTip == height) {
@ -303,7 +312,7 @@ abstract class ElectrumWalletBase
chainTip: chainTip,
electrumClient: ElectrumClient(),
transactionHistoryIds: transactionHistory.transactions.keys.toList(),
node: ScanNode(node!.uri, node!.useSSL),
node: usingElectrs == true ? ScanNode(node!.uri, node!.useSSL) : null,
labels: walletAddresses.labels,
labelIndexes: walletAddresses.silentAddresses
.where((addr) => addr.type == SilentPaymentsAddresType.p2sp && addr.index >= 1)
@ -1122,8 +1131,13 @@ abstract class ElectrumWalletBase
@action
@override
Future<void> rescan(
{required int height, int? chainTip, ScanData? scanData, bool? doSingleScan}) async {
Future<void> rescan({
required int height,
int? chainTip,
ScanData? scanData,
bool? doSingleScan,
bool? usingElectrs,
}) async {
silentPaymentsScanningActive = true;
_setListeners(height, doSingleScan: doSingleScan);
}
@ -1820,7 +1834,7 @@ class ScanData {
final SendPort sendPort;
final SilentPaymentOwner silentAddress;
final int height;
final ScanNode node;
final ScanNode? node;
final BasedUtxoNetwork network;
final int chainTip;
final ElectrumClient electrumClient;
@ -1881,7 +1895,10 @@ Future<void> startRefresh(ScanData scanData) async {
scanData.sendPort.send(SyncResponse(syncHeight, syncingStatus));
final electrumClient = scanData.electrumClient;
await electrumClient.connectToUri(scanData.node.uri, useSSL: scanData.node.useSSL);
await electrumClient.connectToUri(
scanData.node?.uri ?? Uri.parse("tcp://electrs.cakewallet.com:50001"),
useSSL: scanData.node?.useSSL ?? false,
);
if (tweaksSubscription == null) {
final count = scanData.isSingleScan ? 1 : TWEAKS_COUNT;

View file

@ -245,6 +245,7 @@ Future<int> getHavenCurrentHeight() async {
// Data taken from https://timechaincalendar.com/
const bitcoinDates = {
"2024-06": 846005,
"2024-05": 841590,
"2024-04": 837182,
"2024-03": 832623,

View file

@ -514,18 +514,10 @@ class CWBitcoin extends Bitcoin {
@override
Future<void> setScanningActive(Object wallet, bool active) async {
final bitcoinWallet = wallet as ElectrumWallet;
if (active && !(await getNodeIsElectrsSPEnabled(wallet))) {
final node = Node(
useSSL: false,
uri: 'electrs.cakewallet.com:${(wallet.network == BitcoinNetwork.testnet ? 50002 : 50001)}',
bitcoinWallet.setSilentPaymentsScanning(
active,
active && (await getNodeIsElectrsSPEnabled(wallet)),
);
node.type = WalletType.bitcoin;
await bitcoinWallet.connectToNode(node: node);
}
bitcoinWallet.setSilentPaymentsScanning(active);
}
@override
@ -540,14 +532,6 @@ class CWBitcoin extends Bitcoin {
@override
Future<void> rescan(Object wallet, {required int height, bool? doSingleScan}) async {
final bitcoinWallet = wallet as ElectrumWallet;
if (!(await getNodeIsElectrsSPEnabled(wallet))) {
final node = Node(
useSSL: false,
uri: 'electrs.cakewallet.com:${(wallet.network == BitcoinNetwork.testnet ? 50002 : 50001)}',
);
node.type = WalletType.bitcoin;
await bitcoinWallet.connectToNode(node: node);
}
bitcoinWallet.rescan(height: height, doSingleScan: doSingleScan);
}

View file

@ -227,6 +227,8 @@ Future<void> defaultSettingsMigration(
break;
case 34:
await _addElectRsNode(nodes, sharedPreferences);
case 35:
await _switchElectRsNode(nodes, sharedPreferences);
break;
default:
break;
@ -825,6 +827,39 @@ Future<void> _addElectRsNode(Box<Node> nodeSource, SharedPreferences sharedPrefe
}
}
Future<void> _switchElectRsNode(Box<Node> nodeSource, SharedPreferences sharedPreferences) async {
final currentBitcoinNodeId =
sharedPreferences.getInt(PreferencesKey.currentBitcoinElectrumSererIdKey);
final currentBitcoinNode =
nodeSource.values.firstWhere((node) => node.key == currentBitcoinNodeId);
final needToReplaceCurrentBitcoinNode =
currentBitcoinNode.uri.toString().contains('electrs.cakewallet.com');
if (!needToReplaceCurrentBitcoinNode) return;
final btcElectrumNode = nodeSource.values.firstWhereOrNull(
(node) => node.uri.toString().contains('btc-electrum.cakewallet.com'),
);
if (btcElectrumNode == null) {
final newBtcElectrumBitcoinNode = Node(
uri: newCakeWalletBitcoinUri,
type: WalletType.bitcoin,
useSSL: false,
);
await nodeSource.add(newBtcElectrumBitcoinNode);
await sharedPreferences.setInt(
PreferencesKey.currentBitcoinElectrumSererIdKey,
newBtcElectrumBitcoinNode.key as int,
);
} else {
await sharedPreferences.setInt(
PreferencesKey.currentBitcoinElectrumSererIdKey,
btcElectrumNode.key as int,
);
}
}
Future<void> checkCurrentNodes(
Box<Node> nodeSource, Box<Node> powNodeSource, SharedPreferences sharedPreferences) async {
final currentMoneroNodeId = sharedPreferences.getInt(PreferencesKey.currentNodeIdKey);

View file

@ -202,7 +202,7 @@ Future<void> initializeAppConfigs() async {
transactionDescriptions: transactionDescriptions,
secureStorage: secureStorage,
anonpayInvoiceInfo: anonpayInvoiceInfo,
initialMigrationVersion: 34,
initialMigrationVersion: 35,
);
}