pass proxyInfo to Solana RpcClient if Tor is enabled

This commit is contained in:
sneurlax 2024-04-19 16:05:24 -05:00
parent 896689a90e
commit 4f9eae7169
3 changed files with 25 additions and 29 deletions

View file

@ -4,7 +4,6 @@ import 'dart:math';
import 'package:isar/isar.dart';
import 'package:solana/dto.dart';
import 'package:solana/solana.dart';
import 'package:stackwallet/electrumx_rpc/electrumx_client.dart';
import 'package:stackwallet/models/balance.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart'
as isar;
@ -29,7 +28,6 @@ class SolanaWallet extends Bip39Wallet<Solana> {
NodeModel? _solNode;
ElectrumXClient? electrumXClient; // Used for Tor.
RpcClient? rpcClient; // The Solana RpcClient.
Future<Ed25519HDKeyPair> _getKeyPair() async {
@ -212,8 +210,8 @@ class SolanaWallet extends Bip39Wallet<Solana> {
@override
Future<bool> pingCheck() {
try {
var rpcClient = RpcClient("${getCurrentNode().host}:${getCurrentNode().port}");
rpcClient.getHealth();
_checkClient();
rpcClient?.getHealth();
return Future.value(true);
} catch (e, s) {
Logging.instance.log(
@ -414,24 +412,17 @@ class SolanaWallet extends Bip39Wallet<Solana> {
return Future.value(false);
}
/// Check that the ElectrumXClient is active and usable by a Solana RpcClient.
Future<void> _checkClients() async {
/// Make sure the Solana RpcClient uses Tor if it's enabled.
///
/// TODO: Make synchronous.
Future<void> _checkClient() async {
if (prefs.useTor) {
electrumXClient ??= ElectrumXClient(
host: getCurrentNode().host,
port: getCurrentNode().port,
useSSL: getCurrentNode().useSSL,
failovers: [],
prefs: prefs,
coin: Coin.solana,
);
int torPort = electrumXClient?.rpcClient?.proxyInfo?.port ??
TorService.sharedInstance.getProxyInfo().port;
rpcClient = RpcClient("${InternetAddress.loopbackIPv4}:$torPort");
} else {
rpcClient =
RpcClient("${getCurrentNode().host}:${getCurrentNode().port}");
}
final ({InternetAddress host, int port}) proxyInfo =
TorService.sharedInstance.getProxyInfo();
// If Tor is enabled, pass the optional proxyInfo to the Solana RpcClient.
rpcClient = RpcClient("${getCurrentNode().host}:${getCurrentNode().port}",
proxyInfo: {'host': proxyInfo.host, 'port': proxyInfo.port});
} else {}
return;
}
}

View file

@ -1545,10 +1545,10 @@ packages:
dependency: "direct main"
description:
name: socks5_proxy
sha256: e0cba6917cd374de6f6cb0ce081e50e6efc24c61644b8e9f20c8bf8b91bb0b75
sha256: "1d21b5606169654bbf4cfb904e8e6ed897e9f763358709f87310c757096d909a"
url: "https://pub.dev"
source: hosted
version: "1.0.3+dev.3"
version: "1.0.4"
socks_socket:
dependency: "direct main"
description:
@ -1561,11 +1561,12 @@ packages:
solana:
dependency: "direct main"
description:
name: solana
sha256: "99a6a40a847f57ccf4687a730413d67fcaef4fc6778ddd9c3258e7fe8e4c6743"
url: "https://pub.dev"
source: hosted
version: "0.30.3"
path: "packages/solana"
ref: "2d7189d31f1bfd5d6779268c81a897f03f339f5d"
resolved-ref: "2d7189d31f1bfd5d6779268c81a897f03f339f5d"
url: "https://github.com/cypherstack/espresso-cash-public.git"
source: git
version: "0.30.4"
source_gen:
dependency: transitive
description:

View file

@ -177,7 +177,11 @@ dependencies:
url: https://github.com/cypherstack/electrum_adapter.git
ref: 9e9441fc1e9ace8907256fff05fe2c607b0933b6
stream_channel: ^2.1.0
solana: ^0.30.3
solana:
git: # TODO: Revert to official package once Tor support is merged upstream.
url: https://github.com/cypherstack/espresso-cash-public.git
ref: 2d7189d31f1bfd5d6779268c81a897f03f339f5d # tor branch.
path: packages/solana
dev_dependencies:
flutter_test: