diff --git a/lib/electrumx_rpc/cached_electrumx_client.dart b/lib/electrumx_rpc/cached_electrumx_client.dart index a92203cc4..b0838e93d 100644 --- a/lib/electrumx_rpc/cached_electrumx_client.dart +++ b/lib/electrumx_rpc/cached_electrumx_client.dart @@ -14,8 +14,10 @@ import 'dart:math'; import 'package:electrum_adapter/electrum_adapter.dart' as electrum_adapter; import 'package:stackwallet/db/hive/db.dart'; import 'package:stackwallet/electrumx_rpc/electrumx_client.dart'; +import 'package:stackwallet/services/tor_service.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; +import 'package:stackwallet/utilities/prefs.dart'; import 'package:string_validator/string_validator.dart'; class CachedElectrumXClient { @@ -190,7 +192,11 @@ class CachedElectrumXClient { final cachedTx = box.get(txHash) as Map?; if (cachedTx == null) { var channel = await electrum_adapter.connect(electrumXClient.host, - port: electrumXClient.port); // TODO pass useSLL. + port: electrumXClient.port, + useSSL: electrumXClient.useSSL, + proxyInfo: Prefs.instance.useTor + ? TorService.sharedInstance.getProxyInfo() + : null); var client = electrum_adapter.ElectrumClient( channel, electrumXClient.host, electrumXClient.port); final Map result = await client.getTransaction(txHash); diff --git a/lib/electrumx_rpc/electrumx_client.dart b/lib/electrumx_rpc/electrumx_client.dart index dcbc47568..14f3f6bac 100644 --- a/lib/electrumx_rpc/electrumx_client.dart +++ b/lib/electrumx_rpc/electrumx_client.dart @@ -745,8 +745,12 @@ class ElectrumXClient { }) async { Logging.instance.log("attempting to fetch blockchain.transaction.get...", level: LogLevel.Info); - var channel = - await electrum_adapter.connect(host, port: port); // TODO pass useSLL. + var channel = await electrum_adapter.connect(host, + port: port, + useSSL: useSSL, + proxyInfo: Prefs.instance.useTor + ? TorService.sharedInstance.getProxyInfo() + : null); var client = electrum_adapter.ElectrumClient(channel, host, port); dynamic response = await client.getTransaction(txHash); Logging.instance.log("Fetching blockchain.transaction.get finished", @@ -780,7 +784,12 @@ class ElectrumXClient { }) async { Logging.instance.log("attempting to fetch lelantus.getanonymityset...", level: LogLevel.Info); - var channel = await electrum_adapter.connect(host, port: port); + var channel = await electrum_adapter.connect(host, + port: port, + useSSL: useSSL, + proxyInfo: Prefs.instance.useTor + ? TorService.sharedInstance.getProxyInfo() + : null); var client = electrum_adapter.FiroElectrumClient(channel); Map anonymitySet = await client.getLelantusAnonymitySet( groupId: groupId, blockHash: blockhash); @@ -799,7 +808,12 @@ class ElectrumXClient { }) async { Logging.instance.log("attempting to fetch lelantus.getmintmetadata...", level: LogLevel.Info); - var channel = await electrum_adapter.connect(host, port: port); + var channel = await electrum_adapter.connect(host, + port: port, + useSSL: useSSL, + proxyInfo: Prefs.instance.useTor + ? TorService.sharedInstance.getProxyInfo() + : null); var client = electrum_adapter.FiroElectrumClient(channel); dynamic mintData = await client.getLelantusMintData(mints: mints); Logging.instance.log("Fetching lelantus.getmintmetadata finished", @@ -815,7 +829,12 @@ class ElectrumXClient { }) async { Logging.instance.log("attempting to fetch lelantus.getusedcoinserials...", level: LogLevel.Info); - var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var channel = await electrum_adapter.connect(host, + port: port, + useSSL: useSSL, + proxyInfo: Prefs.instance.useTor + ? TorService.sharedInstance.getProxyInfo() + : null); var client = electrum_adapter.FiroElectrumClient(channel); int retryCount = 3; @@ -840,7 +859,12 @@ class ElectrumXClient { Future getLelantusLatestCoinId({String? requestID}) async { Logging.instance.log("attempting to fetch lelantus.getlatestcoinid...", level: LogLevel.Info); - var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var channel = await electrum_adapter.connect(host, + port: port, + useSSL: useSSL, + proxyInfo: Prefs.instance.useTor + ? TorService.sharedInstance.getProxyInfo() + : null); var client = electrum_adapter.FiroElectrumClient(channel); int latestCoinId = await client.getLatestCoinId(); Logging.instance.log("Fetching lelantus.getlatestcoinid finished", @@ -871,7 +895,12 @@ class ElectrumXClient { try { Logging.instance.log("attempting to fetch spark.getsparkanonymityset...", level: LogLevel.Info); - var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var channel = await electrum_adapter.connect(host, + port: port, + useSSL: useSSL, + proxyInfo: Prefs.instance.useTor + ? TorService.sharedInstance.getProxyInfo() + : null); var client = electrum_adapter.FiroElectrumClient(channel); Map anonymitySet = await client.getSparkAnonymitySet( coinGroupId: coinGroupId, startBlockHash: startBlockHash); @@ -893,7 +922,12 @@ class ElectrumXClient { // Use electrum_adapter package's getSparkUsedCoinsTags method. Logging.instance.log("attempting to fetch spark.getusedcoinstags...", level: LogLevel.Info); - var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var channel = await electrum_adapter.connect(host, + port: port, + useSSL: useSSL, + proxyInfo: Prefs.instance.useTor + ? TorService.sharedInstance.getProxyInfo() + : null); var client = electrum_adapter.FiroElectrumClient(channel); Map usedCoinsTags = await client.getUsedCoinsTags(startNumber: startNumber); @@ -926,7 +960,12 @@ class ElectrumXClient { try { Logging.instance.log("attempting to fetch spark.getsparkmintmetadata...", level: LogLevel.Info); - var channel = await electrum_adapter.connect('firo.stackwallet.com'); + var channel = await electrum_adapter.connect(host, + port: port, + useSSL: useSSL, + proxyInfo: Prefs.instance.useTor + ? TorService.sharedInstance.getProxyInfo() + : null); var client = electrum_adapter.FiroElectrumClient(channel); List mintMetaData = await client.getSparkMintMetaData(sparkCoinHashes: sparkCoinHashes); @@ -948,7 +987,12 @@ class ElectrumXClient { try { Logging.instance.log("attempting to fetch spark.getsparklatestcoinid...", level: LogLevel.Info); - var channel = await electrum_adapter.connect(host, port: port); + var channel = await electrum_adapter.connect(host, + port: port, + useSSL: useSSL, + proxyInfo: Prefs.instance.useTor + ? TorService.sharedInstance.getProxyInfo() + : null); var client = electrum_adapter.FiroElectrumClient(channel); int latestCoinId = await client.getSparkLatestCoinId(); Logging.instance.log("Fetching spark.getsparklatestcoinid finished", @@ -970,7 +1014,12 @@ class ElectrumXClient { /// "rate": 1000, /// } Future> getFeeRate({String? requestID}) async { - var channel = await electrum_adapter.connect(host, port: port); + var channel = await electrum_adapter.connect(host, + port: port, + useSSL: useSSL, + proxyInfo: Prefs.instance.useTor + ? TorService.sharedInstance.getProxyInfo() + : null); var client = electrum_adapter.FiroElectrumClient(channel); return await client.getFeeRate(); } diff --git a/lib/electrumx_rpc/subscribable_electrumx_client.dart b/lib/electrumx_rpc/subscribable_electrumx_client.dart index 5db7cefc1..b17227c8b 100644 --- a/lib/electrumx_rpc/subscribable_electrumx_client.dart +++ b/lib/electrumx_rpc/subscribable_electrumx_client.dart @@ -14,7 +14,6 @@ import 'dart:io'; import 'package:event_bus/event_bus.dart'; import 'package:mutex/mutex.dart'; -import 'package:socks_socket/socks_socket.dart'; import 'package:stackwallet/electrumx_rpc/electrumx_client.dart'; import 'package:stackwallet/exceptions/json_rpc/json_rpc_exception.dart'; import 'package:stackwallet/services/event_bus/events/global/tor_connection_status_changed_event.dart'; @@ -23,6 +22,7 @@ import 'package:stackwallet/services/event_bus/global_event_bus.dart'; import 'package:stackwallet/services/tor_service.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/prefs.dart'; +import 'package:tor_ffi_plugin/socks_socket.dart'; class ElectrumXSubscription { final StreamController _controller = diff --git a/pubspec.lock b/pubspec.lock index b87faa62d..35624bfec 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -528,8 +528,8 @@ packages: dependency: "direct main" description: path: "." - ref: dd443e293feb3b37eb494ab7c8dadef9205de14c - resolved-ref: dd443e293feb3b37eb494ab7c8dadef9205de14c + ref: dd83940d73429d917f9e50b3a765adbf5e06df6d + resolved-ref: dd83940d73429d917f9e50b3a765adbf5e06df6d url: "https://github.com/cypherstack/electrum_adapter.git" source: git version: "3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 1534b95a8..ce3ac48f4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -176,7 +176,7 @@ dependencies: electrum_adapter: git: url: https://github.com/cypherstack/electrum_adapter.git - ref: dd443e293feb3b37eb494ab7c8dadef9205de14c + ref: dd83940d73429d917f9e50b3a765adbf5e06df6d dev_dependencies: flutter_test: