diff --git a/lib/wallets/wallet/impl/stellar_wallet.dart b/lib/wallets/wallet/impl/stellar_wallet.dart index d078dd98e..edea60fe5 100644 --- a/lib/wallets/wallet/impl/stellar_wallet.dart +++ b/lib/wallets/wallet/impl/stellar_wallet.dart @@ -1,7 +1,9 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:io'; import 'package:isar/isar.dart'; +import 'package:socks5_proxy/socks.dart'; import 'package:stackwallet/models/balance.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/address.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart'; @@ -9,6 +11,7 @@ import 'package:stackwallet/models/isar/models/blockchain_data/v2/input_v2.dart' import 'package:stackwallet/models/isar/models/blockchain_data/v2/output_v2.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/v2/transaction_v2.dart'; import 'package:stackwallet/models/paymint/fee_object_model.dart'; +import 'package:stackwallet/services/tor_service.dart'; import 'package:stackwallet/utilities/amount/amount.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; @@ -43,6 +46,7 @@ class StellarWallet extends Bip39Wallet { // ============== Private ==================================================== stellar.StellarSDK? _stellarSdk; + HttpClient? _httpClient; Future _getBaseFee() async { final fees = await stellarSdk.feeStats.execute(); @@ -51,7 +55,21 @@ class StellarWallet extends Bip39Wallet { void _updateSdk() { final currentNode = getCurrentNode(); - _stellarSdk = stellar.StellarSDK("${currentNode.host}:${currentNode.port}"); + + // TODO [prio=med]: refactor out and call before requests in case Tor is enabled/disabled, listen to prefs change, or similar. + if (prefs.useTor) { + final ({InternetAddress host, int port}) proxyInfo = + TorService.sharedInstance.getProxyInfo(); + + _httpClient = HttpClient(); + SocksTCPClient.assignToHttpClient( + _httpClient!, [ProxySettings(proxyInfo.host, proxyInfo.port)]); + } else { + _httpClient = null; + } + + _stellarSdk = stellar.StellarSDK("${currentNode.host}:${currentNode.port}", + httpClient: _httpClient); } Future _accountExists(String accountId) async { diff --git a/pubspec.lock b/pubspec.lock index 4e4d39cb7..afd26b39f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1659,10 +1659,11 @@ packages: stellar_flutter_sdk: dependency: "direct main" description: - name: stellar_flutter_sdk - sha256: "4c55b1b6dfbde7f89bba59a422754280715fa3b5726cff5e7eeaed454d2c4b89" - url: "https://pub.dev" - source: hosted + path: "." + ref: eca1d730e952cf6a6d64502f977cfc03876b75d4 + resolved-ref: eca1d730e952cf6a6d64502f977cfc03876b75d4 + url: "https://github.com/cypherstack/stellar_flutter_sdk.git" + source: git version: "1.5.3" stream_channel: dependency: "direct main" @@ -2109,5 +2110,5 @@ packages: source: hosted version: "1.0.0" sdks: - dart: ">=3.3.0 <4.0.0" - flutter: ">=3.16.0" + dart: ">=3.3.3 <4.0.0" + flutter: ">=3.19.5" diff --git a/pubspec.yaml b/pubspec.yaml index 16db28f97..2c432f6e0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -156,7 +156,10 @@ dependencies: desktop_drop: ^0.4.1 nanodart: ^2.0.0 basic_utils: ^5.5.4 - stellar_flutter_sdk: ^1.5.3 + stellar_flutter_sdk: # ^1.5.3 + git: # TODO Revert to official package once Tor support is merged upstream. + url: https://github.com/cypherstack/stellar_flutter_sdk.git + ref: eca1d730e952cf6a6d64502f977cfc03876b75d4 # tor-backport branch (based on 1.5.3). socks_socket: git: url: https://github.com/cypherstack/socks_socket.git