mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 11:39:22 +00:00
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
This commit is contained in:
parent
30dc8f9238
commit
1dd2c7da56
6 changed files with 67 additions and 30 deletions
|
@ -64,7 +64,7 @@ class ElectrumClient {
|
||||||
await socket?.close();
|
await socket?.close();
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
|
||||||
if (useSSL == false) {
|
if (useSSL == false || (useSSL == null && uri.toString().contains("btc-electrum"))) {
|
||||||
socket = await Socket.connect(host, port, timeout: connectionTimeout);
|
socket = await Socket.connect(host, port, timeout: connectionTimeout);
|
||||||
} else {
|
} else {
|
||||||
socket = await SecureSocket.connect(host, port,
|
socket = await SecureSocket.connect(host, port,
|
||||||
|
|
|
@ -197,7 +197,7 @@ abstract class ElectrumWalletBase
|
||||||
bool silentPaymentsScanningActive = false;
|
bool silentPaymentsScanningActive = false;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
Future<void> setSilentPaymentsScanning(bool active) async {
|
Future<void> setSilentPaymentsScanning(bool active, bool usingElectrs) async {
|
||||||
silentPaymentsScanningActive = active;
|
silentPaymentsScanningActive = active;
|
||||||
|
|
||||||
if (active) {
|
if (active) {
|
||||||
|
@ -210,7 +210,11 @@ abstract class ElectrumWalletBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tip > walletInfo.restoreHeight) {
|
if (tip > walletInfo.restoreHeight) {
|
||||||
_setListeners(walletInfo.restoreHeight, chainTipParam: _currentChainTip);
|
_setListeners(
|
||||||
|
walletInfo.restoreHeight,
|
||||||
|
chainTipParam: _currentChainTip,
|
||||||
|
usingElectrs: usingElectrs,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
alwaysScan = false;
|
alwaysScan = false;
|
||||||
|
@ -277,7 +281,12 @@ abstract class ElectrumWalletBase
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@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();
|
final chainTip = chainTipParam ?? await getUpdatedChainTip();
|
||||||
|
|
||||||
if (chainTip == height) {
|
if (chainTip == height) {
|
||||||
|
@ -303,7 +312,7 @@ abstract class ElectrumWalletBase
|
||||||
chainTip: chainTip,
|
chainTip: chainTip,
|
||||||
electrumClient: ElectrumClient(),
|
electrumClient: ElectrumClient(),
|
||||||
transactionHistoryIds: transactionHistory.transactions.keys.toList(),
|
transactionHistoryIds: transactionHistory.transactions.keys.toList(),
|
||||||
node: ScanNode(node!.uri, node!.useSSL),
|
node: usingElectrs == true ? ScanNode(node!.uri, node!.useSSL) : null,
|
||||||
labels: walletAddresses.labels,
|
labels: walletAddresses.labels,
|
||||||
labelIndexes: walletAddresses.silentAddresses
|
labelIndexes: walletAddresses.silentAddresses
|
||||||
.where((addr) => addr.type == SilentPaymentsAddresType.p2sp && addr.index >= 1)
|
.where((addr) => addr.type == SilentPaymentsAddresType.p2sp && addr.index >= 1)
|
||||||
|
@ -1122,8 +1131,13 @@ abstract class ElectrumWalletBase
|
||||||
|
|
||||||
@action
|
@action
|
||||||
@override
|
@override
|
||||||
Future<void> rescan(
|
Future<void> rescan({
|
||||||
{required int height, int? chainTip, ScanData? scanData, bool? doSingleScan}) async {
|
required int height,
|
||||||
|
int? chainTip,
|
||||||
|
ScanData? scanData,
|
||||||
|
bool? doSingleScan,
|
||||||
|
bool? usingElectrs,
|
||||||
|
}) async {
|
||||||
silentPaymentsScanningActive = true;
|
silentPaymentsScanningActive = true;
|
||||||
_setListeners(height, doSingleScan: doSingleScan);
|
_setListeners(height, doSingleScan: doSingleScan);
|
||||||
}
|
}
|
||||||
|
@ -1820,7 +1834,7 @@ class ScanData {
|
||||||
final SendPort sendPort;
|
final SendPort sendPort;
|
||||||
final SilentPaymentOwner silentAddress;
|
final SilentPaymentOwner silentAddress;
|
||||||
final int height;
|
final int height;
|
||||||
final ScanNode node;
|
final ScanNode? node;
|
||||||
final BasedUtxoNetwork network;
|
final BasedUtxoNetwork network;
|
||||||
final int chainTip;
|
final int chainTip;
|
||||||
final ElectrumClient electrumClient;
|
final ElectrumClient electrumClient;
|
||||||
|
@ -1881,7 +1895,10 @@ Future<void> startRefresh(ScanData scanData) async {
|
||||||
scanData.sendPort.send(SyncResponse(syncHeight, syncingStatus));
|
scanData.sendPort.send(SyncResponse(syncHeight, syncingStatus));
|
||||||
|
|
||||||
final electrumClient = scanData.electrumClient;
|
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) {
|
if (tweaksSubscription == null) {
|
||||||
final count = scanData.isSingleScan ? 1 : TWEAKS_COUNT;
|
final count = scanData.isSingleScan ? 1 : TWEAKS_COUNT;
|
||||||
|
|
|
@ -245,6 +245,7 @@ Future<int> getHavenCurrentHeight() async {
|
||||||
|
|
||||||
// Data taken from https://timechaincalendar.com/
|
// Data taken from https://timechaincalendar.com/
|
||||||
const bitcoinDates = {
|
const bitcoinDates = {
|
||||||
|
"2024-06": 846005,
|
||||||
"2024-05": 841590,
|
"2024-05": 841590,
|
||||||
"2024-04": 837182,
|
"2024-04": 837182,
|
||||||
"2024-03": 832623,
|
"2024-03": 832623,
|
||||||
|
|
|
@ -514,18 +514,10 @@ class CWBitcoin extends Bitcoin {
|
||||||
@override
|
@override
|
||||||
Future<void> setScanningActive(Object wallet, bool active) async {
|
Future<void> setScanningActive(Object wallet, bool active) async {
|
||||||
final bitcoinWallet = wallet as ElectrumWallet;
|
final bitcoinWallet = wallet as ElectrumWallet;
|
||||||
|
bitcoinWallet.setSilentPaymentsScanning(
|
||||||
if (active && !(await getNodeIsElectrsSPEnabled(wallet))) {
|
active,
|
||||||
final node = Node(
|
active && (await getNodeIsElectrsSPEnabled(wallet)),
|
||||||
useSSL: false,
|
);
|
||||||
uri: 'electrs.cakewallet.com:${(wallet.network == BitcoinNetwork.testnet ? 50002 : 50001)}',
|
|
||||||
);
|
|
||||||
node.type = WalletType.bitcoin;
|
|
||||||
|
|
||||||
await bitcoinWallet.connectToNode(node: node);
|
|
||||||
}
|
|
||||||
|
|
||||||
bitcoinWallet.setSilentPaymentsScanning(active);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -540,14 +532,6 @@ class CWBitcoin extends Bitcoin {
|
||||||
@override
|
@override
|
||||||
Future<void> rescan(Object wallet, {required int height, bool? doSingleScan}) async {
|
Future<void> rescan(Object wallet, {required int height, bool? doSingleScan}) async {
|
||||||
final bitcoinWallet = wallet as ElectrumWallet;
|
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);
|
bitcoinWallet.rescan(height: height, doSingleScan: doSingleScan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,6 +227,8 @@ Future<void> defaultSettingsMigration(
|
||||||
break;
|
break;
|
||||||
case 34:
|
case 34:
|
||||||
await _addElectRsNode(nodes, sharedPreferences);
|
await _addElectRsNode(nodes, sharedPreferences);
|
||||||
|
case 35:
|
||||||
|
await _switchElectRsNode(nodes, sharedPreferences);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
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(
|
Future<void> checkCurrentNodes(
|
||||||
Box<Node> nodeSource, Box<Node> powNodeSource, SharedPreferences sharedPreferences) async {
|
Box<Node> nodeSource, Box<Node> powNodeSource, SharedPreferences sharedPreferences) async {
|
||||||
final currentMoneroNodeId = sharedPreferences.getInt(PreferencesKey.currentNodeIdKey);
|
final currentMoneroNodeId = sharedPreferences.getInt(PreferencesKey.currentNodeIdKey);
|
||||||
|
|
|
@ -202,7 +202,7 @@ Future<void> initializeAppConfigs() async {
|
||||||
transactionDescriptions: transactionDescriptions,
|
transactionDescriptions: transactionDescriptions,
|
||||||
secureStorage: secureStorage,
|
secureStorage: secureStorage,
|
||||||
anonpayInvoiceInfo: anonpayInvoiceInfo,
|
anonpayInvoiceInfo: anonpayInvoiceInfo,
|
||||||
initialMigrationVersion: 34,
|
initialMigrationVersion: 35,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue