use and pass SSL and Tor proxyInfo variables to electrum_adapter methods

This commit is contained in:
sneurlax 2024-02-14 16:50:01 -06:00
parent 8fc2043910
commit 2339b33798
5 changed files with 71 additions and 16 deletions

View file

@ -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<String, dynamic> result = await client.getTransaction(txHash);

View file

@ -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<String, dynamic> 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<int> 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<String, dynamic> 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<String, dynamic> 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<dynamic> 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<Map<String, dynamic>> 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();
}

View file

@ -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<dynamic> _controller =

View file

@ -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"

View file

@ -176,7 +176,7 @@ dependencies:
electrum_adapter:
git:
url: https://github.com/cypherstack/electrum_adapter.git
ref: dd443e293feb3b37eb494ab7c8dadef9205de14c
ref: dd83940d73429d917f9e50b3a765adbf5e06df6d
dev_dependencies:
flutter_test: