diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index 6be525a1f..09dc24aa3 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -167,6 +167,12 @@ abstract class ElectrumWalletBase @override Future connectToNode({required Node node}) async { try { + // we can't connect over tor in this wallet type (yet): + if (node.connectOverTorOnly) { + syncStatus = FailedSyncStatus(); + return; + } + syncStatus = ConnectingSyncStatus(); await electrumClient.connectToUri(node.uri); electrumClient.onConnectionStatusChange = (bool isConnected) { diff --git a/cw_core/lib/node.dart b/cw_core/lib/node.dart index 882499ade..45d95544b 100644 --- a/cw_core/lib/node.dart +++ b/cw_core/lib/node.dart @@ -63,6 +63,8 @@ class Node extends HiveObject with Keyable { @HiveField(6) String? socksProxyAddress; + bool connectOverTorOnly = false; + bool get isSSL => useSSL ?? false; bool get useSocksProxy => socksProxyAddress == null ? false : socksProxyAddress!.isNotEmpty; diff --git a/lib/anonpay/anonpay_api.dart b/lib/anonpay/anonpay_api.dart index 5fdfcddd9..f8f4f5652 100644 --- a/lib/anonpay/anonpay_api.dart +++ b/lib/anonpay/anonpay_api.dart @@ -201,7 +201,6 @@ class AnonPayApi { return await proxy.get( onionUri: onionUri, clearnetUri: clearnetUri, - torOnly: false, ); } } diff --git a/lib/core/fiat_conversion_service.dart b/lib/core/fiat_conversion_service.dart index 9b01255b2..1b9ba87d0 100644 --- a/lib/core/fiat_conversion_service.dart +++ b/lib/core/fiat_conversion_service.dart @@ -45,7 +45,6 @@ Future _fetchPrice(Map args) async { onionUri: onionUri, clearnetUri: clearnetUri, portOverride: mainThreadProxyPort, - torOnly: false, torConnectionMode: torConnectionMode, ); diff --git a/lib/exchange/provider/trocador_exchange_provider.dart b/lib/exchange/provider/trocador_exchange_provider.dart index 7a8c5c510..9c3df4dc8 100644 --- a/lib/exchange/provider/trocador_exchange_provider.dart +++ b/lib/exchange/provider/trocador_exchange_provider.dart @@ -311,7 +311,6 @@ class TrocadorExchangeProvider extends ExchangeProvider { return await proxy.get( onionUri: onionUri, clearnetUri: clearnetUri, - torOnly: false, ); } } diff --git a/lib/utils/proxy_wrapper.dart b/lib/utils/proxy_wrapper.dart index f331a6bc2..5373c57dd 100644 --- a/lib/utils/proxy_wrapper.dart +++ b/lib/utils/proxy_wrapper.dart @@ -82,7 +82,6 @@ class ProxyWrapper { Future get({ Map? headers, int? portOverride, - bool torOnly = false, TorConnectionMode? torConnectionMode, Uri? clearnetUri, Uri? onionUri, @@ -90,17 +89,13 @@ class ProxyWrapper { HttpClient? torClient; late bool torEnabled; torConnectionMode ??= settingsStore?.torConnectionMode ?? TorConnectionMode.disabled; - if (torConnectionMode == TorConnectionMode.onionOnly || + if (torConnectionMode == TorConnectionMode.torOnly || torConnectionMode == TorConnectionMode.enabled) { torEnabled = true; } else { torEnabled = false; } - if (torConnectionMode == TorConnectionMode.onionOnly && onionUri == null) { - throw Exception("Cannot connect to clearnet"); - } - // if tor is enabled, try to connect to the onion url first: if (torEnabled) { try { @@ -117,7 +112,7 @@ class ProxyWrapper { } catch (_) {} } - if (clearnetUri != null && torConnectionMode != TorConnectionMode.onionOnly) { + if (clearnetUri != null) { try { return await makeGet( client: torClient!, @@ -128,7 +123,7 @@ class ProxyWrapper { } } - if (clearnetUri != null && !torOnly && torConnectionMode != TorConnectionMode.onionOnly) { + if (clearnetUri != null && torConnectionMode != TorConnectionMode.torOnly) { try { return HttpOverrides.runZoned( () async { @@ -152,7 +147,6 @@ class ProxyWrapper { Future post({ Map? headers, int? portOverride, - bool torOnly = false, TorConnectionMode? torConnectionMode, Uri? clearnetUri, Uri? onionUri, @@ -160,17 +154,13 @@ class ProxyWrapper { HttpClient? torClient; late bool torEnabled; torConnectionMode ??= settingsStore?.torConnectionMode ?? TorConnectionMode.disabled; - if (torConnectionMode == TorConnectionMode.onionOnly || + if (torConnectionMode == TorConnectionMode.torOnly || torConnectionMode == TorConnectionMode.enabled) { torEnabled = true; } else { torEnabled = false; } - if (torConnectionMode == TorConnectionMode.onionOnly && onionUri == null) { - throw Exception("Cannot connect to clearnet"); - } - // if tor is enabled, try to connect to the onion url first: if (torEnabled) { @@ -188,7 +178,7 @@ class ProxyWrapper { } catch (_) {} } - if (clearnetUri != null && torConnectionMode != TorConnectionMode.onionOnly) { + if (clearnetUri != null) { try { return await makePost( client: torClient!, @@ -199,7 +189,7 @@ class ProxyWrapper { } } - if (clearnetUri != null && !torOnly && torConnectionMode != TorConnectionMode.onionOnly) { + if (clearnetUri != null && torConnectionMode != TorConnectionMode.torOnly) { try { return HttpOverrides.runZoned( () async { diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index 8ef89569f..fcdb0f6a0 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -719,10 +719,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with } void _setProviders() { - if (_settingsStore.torConnectionMode == TorConnectionMode.onionOnly) - providerList = _allProviders.where((provider) => provider.supportsOnionAddress).toList(); - else - providerList = _allProviders; + providerList = _allProviders; } int get depositMaxDigits => depositCurrency.decimals; diff --git a/lib/view_model/settings/tor_connection.dart b/lib/view_model/settings/tor_connection.dart index 5b3b3b3ae..39c0317fc 100644 --- a/lib/view_model/settings/tor_connection.dart +++ b/lib/view_model/settings/tor_connection.dart @@ -4,11 +4,11 @@ import 'package:cw_core/enumerable_item.dart'; class TorConnectionMode extends EnumerableItem with Serializable { const TorConnectionMode({required String title, required int raw}) : super(title: title, raw: raw); - static const all = [TorConnectionMode.enabled, TorConnectionMode.disabled, TorConnectionMode.onionOnly]; + static const all = [TorConnectionMode.enabled, TorConnectionMode.disabled, TorConnectionMode.torOnly]; static const enabled = TorConnectionMode(raw: 0, title: 'Enabled'); static const disabled = TorConnectionMode(raw: 1, title: 'Disabled'); - static const onionOnly = TorConnectionMode(raw: 2, title: 'Onion only'); + static const torOnly = TorConnectionMode(raw: 2, title: 'Tor only'); static TorConnectionMode deserialize({required int raw}) { switch (raw) { @@ -17,7 +17,7 @@ class TorConnectionMode extends EnumerableItem with Serializable { case 1: return disabled; case 2: - return onionOnly; + return torOnly; default: throw Exception('Unexpected token: $raw for TorConnectionMode deserialize'); } @@ -30,8 +30,8 @@ class TorConnectionMode extends EnumerableItem with Serializable { return S.current.enabled; case TorConnectionMode.disabled: return S.current.disabled; - case TorConnectionMode.onionOnly: - return S.current.onion_only; + case TorConnectionMode.torOnly: + return S.current.tor_only; default: return ''; } diff --git a/lib/view_model/settings/tor_view_model.dart b/lib/view_model/settings/tor_view_model.dart index d01f57368..ac3b6cc84 100644 --- a/lib/view_model/settings/tor_view_model.dart +++ b/lib/view_model/settings/tor_view_model.dart @@ -17,7 +17,7 @@ enum TorConnectionStatus { connecting, connected, disconnected } abstract class TorViewModelBase with Store { TorViewModelBase(this._settingsStore) { reaction((_) => torConnectionMode, (TorConnectionMode mode) async { - if (mode == TorConnectionMode.enabled || mode == TorConnectionMode.onionOnly) { + if (mode == TorConnectionMode.enabled || mode == TorConnectionMode.torOnly) { startTor(); } else { stopTor(); @@ -50,6 +50,7 @@ abstract class TorViewModelBase with Store { } else if (!connect) { node.socksProxyAddress = null; } + node.connectOverTorOnly = _settingsStore.torConnectionMode == TorConnectionMode.torOnly; await appStore.wallet!.connectToNode(node: node); } }