[skip ci] [wip] check if node supports mweb

This commit is contained in:
Matthew Fosse 2024-10-28 10:53:48 -07:00
parent 767b507a8d
commit 04afc64b41
4 changed files with 46 additions and 0 deletions

View file

@ -569,6 +569,29 @@ abstract class ElectrumWalletBase
return node!.supportsSilentPayments!;
}
Future<bool> getNodeSupportsMweb() async {
final version = await electrumClient.version();
if (node == null) {
return false;
}
if (version.isNotEmpty) {
final server = version[0];
print("server: $server");
return false;
// if (server.toLowerCase().contains('electrs')) {
// node!.isElectrs = true;
// node!.save();
// return node!.isElectrs!;
// }
}
return node!.supportsMweb!;
}
@action
@override
Future<void> connectToNode({required Node node}) async {

View file

@ -9,6 +9,7 @@ import 'package:crypto/crypto.dart';
import 'package:cw_bitcoin/bitcoin_transaction_credentials.dart';
import 'package:cw_core/cake_hive.dart';
import 'package:cw_core/mweb_utxo.dart';
import 'package:cw_core/node.dart';
import 'package:cw_mweb/mwebd.pbgrpc.dart';
import 'package:fixnum/fixnum.dart';
import 'package:bip39/bip39.dart' as bip39;
@ -287,6 +288,15 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
await (walletAddresses as LitecoinWalletAddresses).ensureMwebAddressUpToIndexExists(1020);
}
@action
@override
Future<void> connectToNode({required Node node}) async {
await super.connectToNode(node: node);
if (await getNodeSupportsMweb()) {
await CwMweb.setNodeUriOverride(node.uri.toString());
}
}
@action
@override
Future<void> startSync() async {

View file

@ -79,6 +79,9 @@ class Node extends HiveObject with Keyable {
@HiveField(9)
bool? supportsSilentPayments;
@HiveField(10)
bool? supportsMweb;
bool get isSSL => useSSL ?? false;
bool get useSocksProxy => socksProxyAddress == null ? false : socksProxyAddress!.isNotEmpty;

View file

@ -15,6 +15,16 @@ class CwMweb {
static int? _port;
static const TIMEOUT_DURATION = Duration(seconds: 15);
static Timer? logTimer;
static String? nodeUriOverride;
static Future<void> setNodeUriOverride(String uri) async {
nodeUriOverride = uri;
if (_rpcClient != null) {
await stop();
await _initializeClient();
}
}
static void readFileWithTimer(String filePath) {
final file = File(filePath);