mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-02-02 03:06:35 +00:00
feat: check if node is electrs, and supports sp
This commit is contained in:
parent
da59860241
commit
cfa4515a82
5 changed files with 43 additions and 16 deletions
|
@ -150,7 +150,8 @@ class ElectrumClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<String>> version() => call(method: 'server.version').then((dynamic result) {
|
Future<List<String>> version() =>
|
||||||
|
call(method: 'server.version', params: ["", "1.4"]).then((dynamic result) {
|
||||||
if (result is List) {
|
if (result is List) {
|
||||||
return result.map((dynamic val) => val.toString()).toList();
|
return result.map((dynamic val) => val.toString()).toList();
|
||||||
}
|
}
|
||||||
|
@ -287,9 +288,8 @@ class ElectrumClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, dynamic>> getTweaks({required int height}) async =>
|
Future<dynamic> getTweaks({required int height}) async =>
|
||||||
await callWithTimeout(method: 'blockchain.tweaks.get', params: [height], timeout: 10000)
|
await callWithTimeout(method: 'blockchain.tweaks.subscribe', params: [height, 1, false]);
|
||||||
as Map<String, dynamic>;
|
|
||||||
|
|
||||||
Future<double> estimatefee({required int p}) =>
|
Future<double> estimatefee({required int p}) =>
|
||||||
call(method: 'blockchain.estimatefee', params: [p]).then((dynamic result) {
|
call(method: 'blockchain.estimatefee', params: [p]).then((dynamic result) {
|
||||||
|
|
|
@ -509,8 +509,7 @@ class CWBitcoin extends Bitcoin {
|
||||||
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;
|
||||||
|
|
||||||
// TODO: always when setting to scanning active, will force switch nodes. Remove when not needed anymore
|
if (!(await getNodeIsElectrsSPEnabled(wallet))) {
|
||||||
if (!getNodeIsCakeElectrs(wallet)) {
|
|
||||||
final node = Node(
|
final node = Node(
|
||||||
useSSL: false,
|
useSSL: false,
|
||||||
uri: 'electrs.cakewallet.com:${(wallet.network == BitcoinNetwork.testnet ? 50002 : 50001)}',
|
uri: 'electrs.cakewallet.com:${(wallet.network == BitcoinNetwork.testnet ? 50002 : 50001)}',
|
||||||
|
@ -535,8 +534,7 @@ 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;
|
||||||
// TODO: always when setting to scanning active, will force switch nodes. Remove when not needed anymore
|
if (!(await getNodeIsElectrsSPEnabled(wallet))) {
|
||||||
if (!getNodeIsCakeElectrs(wallet)) {
|
|
||||||
final node = Node(
|
final node = Node(
|
||||||
useSSL: false,
|
useSSL: false,
|
||||||
uri: 'electrs.cakewallet.com:${(wallet.network == BitcoinNetwork.testnet ? 50002 : 50001)}',
|
uri: 'electrs.cakewallet.com:${(wallet.network == BitcoinNetwork.testnet ? 50002 : 50001)}',
|
||||||
|
@ -547,13 +545,40 @@ class CWBitcoin extends Bitcoin {
|
||||||
bitcoinWallet.rescan(height: height, doSingleScan: doSingleScan);
|
bitcoinWallet.rescan(height: height, doSingleScan: doSingleScan);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
Future<bool> getNodeIsElectrs(Object wallet) async {
|
||||||
bool getNodeIsCakeElectrs(Object wallet) {
|
|
||||||
final bitcoinWallet = wallet as ElectrumWallet;
|
final bitcoinWallet = wallet as ElectrumWallet;
|
||||||
final node = bitcoinWallet.node;
|
|
||||||
|
|
||||||
return node?.uri.host == 'electrs.cakewallet.com' &&
|
final version = await bitcoinWallet.electrumClient.version();
|
||||||
node?.uri.port == (wallet.network == BitcoinNetwork.testnet ? 50002 : 50001);
|
|
||||||
|
if (version.isEmpty) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final server = version[0];
|
||||||
|
|
||||||
|
if (server.toLowerCase().contains('electrs')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> getNodeIsElectrsSPEnabled(Object wallet) async {
|
||||||
|
if (!(await getNodeIsElectrs(wallet))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final bitcoinWallet = wallet as ElectrumWallet;
|
||||||
|
final tweaksResponse = await bitcoinWallet.electrumClient.getTweaks(height: 0);
|
||||||
|
|
||||||
|
print('tweaksResponse: $tweaksResponse');
|
||||||
|
|
||||||
|
if (tweaksResponse != null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -329,7 +329,8 @@ class CryptoBalanceWidget extends StatelessWidget {
|
||||||
final isSilentPaymentsScanningActive = dashboardViewModel.silentPaymentsScanningActive;
|
final isSilentPaymentsScanningActive = dashboardViewModel.silentPaymentsScanningActive;
|
||||||
final newValue = !isSilentPaymentsScanningActive;
|
final newValue = !isSilentPaymentsScanningActive;
|
||||||
|
|
||||||
final needsToSwitch = bitcoin!.getNodeIsCakeElectrs(dashboardViewModel.wallet) == false;
|
final needsToSwitch = !isSilentPaymentsScanningActive &&
|
||||||
|
await bitcoin!.getNodeIsElectrsSPEnabled(dashboardViewModel.wallet) == false;
|
||||||
|
|
||||||
if (needsToSwitch) {
|
if (needsToSwitch) {
|
||||||
return showPopUp<void>(
|
return showPopUp<void>(
|
||||||
|
|
|
@ -55,7 +55,8 @@ class RescanPage extends BasePage {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _toggleSilentPaymentsScanning(BuildContext context) async {
|
Future<void> _toggleSilentPaymentsScanning(BuildContext context) async {
|
||||||
final needsToSwitch = bitcoin!.getNodeIsCakeElectrs(_rescanViewModel.wallet) == false;
|
final needsToSwitch =
|
||||||
|
await bitcoin!.getNodeIsElectrsSPEnabled(_rescanViewModel.wallet) == false;
|
||||||
|
|
||||||
if (needsToSwitch) {
|
if (needsToSwitch) {
|
||||||
return showPopUp<void>(
|
return showPopUp<void>(
|
||||||
|
|
|
@ -213,7 +213,7 @@ abstract class Bitcoin {
|
||||||
{int? outputsCount, int? size});
|
{int? outputsCount, int? size});
|
||||||
int getHeightByDate({required DateTime date});
|
int getHeightByDate({required DateTime date});
|
||||||
Future<void> rescan(Object wallet, {required int height, bool? doSingleScan});
|
Future<void> rescan(Object wallet, {required int height, bool? doSingleScan});
|
||||||
bool getNodeIsCakeElectrs(Object wallet);
|
bool getNodeIsElectrsSPEnabled(Object wallet);
|
||||||
void deleteSilentPaymentAddress(Object wallet, String address);
|
void deleteSilentPaymentAddress(Object wallet, String address);
|
||||||
Future<void> updateFeeRates(Object wallet);
|
Future<void> updateFeeRates(Object wallet);
|
||||||
int getMaxCustomFeeRate(Object wallet);
|
int getMaxCustomFeeRate(Object wallet);
|
||||||
|
|
Loading…
Reference in a new issue