Fixes node connection, and sp, and electrum (#1577)

* refactor: remove bitcoin_flutter, update deps, electrs node improvements

* feat: connecting/disconnecting improvements, fix rescan by date, scanning message

* chore: print

* Update pubspec.yaml

* Update pubspec.yaml

* handle null sockets, retry connection on connect failure

* fix imports

* fix transaction history

* fix RBF

* minor fixes/readability enhancements [skip ci]

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
Co-authored-by: Matthew Fosse <matt@fosse.co>
This commit is contained in:
Rafael
2024-08-12 02:49:45 +03:00
committed by GitHub
co-authored by Omar Hatem Matthew Fosse
parent 96baf460f3
commit bbba41396d
60 changed files with 525 additions and 455 deletions
+4 -46
View File
@@ -302,16 +302,13 @@ class CWBitcoin extends Bitcoin {
await electrumClient.connectToUri(node.uri, useSSL: node.useSSL);
late BasedUtxoNetwork network;
btc.NetworkType networkType;
switch (node.type) {
case WalletType.litecoin:
network = LitecoinNetwork.mainnet;
networkType = litecoinNetwork;
break;
case WalletType.bitcoin:
default:
network = BitcoinNetwork.mainnet;
networkType = btc.bitcoin;
break;
}
@@ -341,10 +338,8 @@ class CWBitcoin extends Bitcoin {
balancePath += "/0";
}
final hd = btc.HDWallet.fromSeed(
seedBytes,
network: networkType,
).derivePath(balancePath);
final hd = Bip32Slip10Secp256k1.fromSeed(seedBytes).derivePath(balancePath)
as Bip32Slip10Secp256k1;
// derive address at index 0:
String? address;
@@ -515,10 +510,7 @@ class CWBitcoin extends Bitcoin {
@override
Future<void> setScanningActive(Object wallet, bool active) async {
final bitcoinWallet = wallet as ElectrumWallet;
bitcoinWallet.setSilentPaymentsScanning(
active,
active && (await getNodeIsElectrsSPEnabled(wallet)),
);
bitcoinWallet.setSilentPaymentsScanning(active);
}
@override
@@ -536,44 +528,10 @@ class CWBitcoin extends Bitcoin {
bitcoinWallet.rescan(height: height, doSingleScan: doSingleScan);
}
Future<bool> getNodeIsElectrs(Object wallet) async {
final bitcoinWallet = wallet as ElectrumWallet;
final version = await bitcoinWallet.electrumClient.version();
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;
try {
final tweaksResponse = await bitcoinWallet.electrumClient.getTweaks(height: 0);
if (tweaksResponse != null) {
return true;
}
} on RequestFailedTimeoutException catch (_) {
return false;
} catch (_) {
rethrow;
}
return false;
return bitcoinWallet.getNodeSupportsSilentPayments();
}
@override
+4
View File
@@ -52,5 +52,9 @@ String syncStatusTitle(SyncStatus syncStatus) {
return S.current.sync_status_syncronizing;
}
if (syncStatus is StartingScanSyncStatus) {
return S.current.sync_status_starting_scan;
}
return '';
}
@@ -34,7 +34,7 @@ class CakePayBuyCardDetailPage extends BasePage {
@override
Widget? middle(BuildContext context) {
return Text(
return Text(
title,
textAlign: TextAlign.center,
maxLines: 2,
@@ -359,7 +359,7 @@ class CakePayBuyCardDetailPage extends BasePage {
reaction((_) => cakePayPurchaseViewModel.sendViewModel.state, (ExecutionState state) {
if (state is FailureState) {
WidgetsBinding.instance.addPostFrameCallback((_) {
showStateAlert(context, S.of(context).error, state.error);
if (context.mounted) showStateAlert(context, S.of(context).error, state.error);
});
}
@@ -381,31 +381,35 @@ class CakePayBuyCardDetailPage extends BasePage {
}
void showStateAlert(BuildContext context, String title, String content) {
showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithOneAction(
alertTitle: title,
alertContent: content,
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop());
});
if (context.mounted) {
showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithOneAction(
alertTitle: title,
alertContent: content,
buttonText: S.of(context).ok,
buttonAction: () => Navigator.of(context).pop());
});
}
}
Future<void> showSentAlert(BuildContext context) async {
if (!context.mounted) {
return;
}
final order = cakePayPurchaseViewModel.order!.orderId;
final isCopy = await showPopUp<bool>(
context: context,
builder: (BuildContext context) {
return AlertWithTwoActions(
alertTitle: S.of(context).transaction_sent,
alertContent:
S.of(context).cake_pay_save_order + '\n${order}',
leftButtonText: S.of(context).ignor,
rightButtonText: S.of(context).copy,
actionLeftButton: () => Navigator.of(context).pop(false),
actionRightButton: () => Navigator.of(context).pop(true));
}) ??
context: context,
builder: (BuildContext context) {
return AlertWithTwoActions(
alertTitle: S.of(context).transaction_sent,
alertContent: S.of(context).cake_pay_save_order + '\n${order}',
leftButtonText: S.of(context).ignor,
rightButtonText: S.of(context).copy,
actionLeftButton: () => Navigator.of(context).pop(false),
actionRightButton: () => Navigator.of(context).pop(true));
}) ??
false;
if (isCopy) {