mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-03 17:29:23 +00:00
badly hack tor node settings into epic wallets
This commit is contained in:
parent
7b603cd7f9
commit
8a63c42582
2 changed files with 54 additions and 1 deletions
|
@ -15,6 +15,7 @@ import '../pages/settings_views/global_settings_view/manage_nodes_views/add_edit
|
||||||
import '../services/tor_service.dart';
|
import '../services/tor_service.dart';
|
||||||
import 'logger.dart';
|
import 'logger.dart';
|
||||||
import 'prefs.dart';
|
import 'prefs.dart';
|
||||||
|
import 'tor_plain_net_option_enum.dart';
|
||||||
|
|
||||||
Future<bool> _testEpicBoxNodeConnection(Uri uri) async {
|
Future<bool> _testEpicBoxNodeConnection(Uri uri) async {
|
||||||
final HTTP client = HTTP();
|
final HTTP client = HTTP();
|
||||||
|
@ -50,6 +51,17 @@ Future<NodeFormData?> testEpicNodeConnection(NodeFormData data) async {
|
||||||
if (data.host == null || data.port == null || data.useSSL == null) {
|
if (data.host == null || data.port == null || data.useSSL == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Prefs.instance.useTor) {
|
||||||
|
if (data.netOption == TorPlainNetworkOption.clear) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (data.netOption == TorPlainNetworkOption.tor) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const String path_postfix = "/v1/version";
|
const String path_postfix = "/v1/version";
|
||||||
|
|
||||||
if (data.host!.startsWith("https://")) {
|
if (data.host!.startsWith("https://")) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import 'package:mutex/mutex.dart';
|
||||||
import 'package:stack_wallet_backup/generate_password.dart';
|
import 'package:stack_wallet_backup/generate_password.dart';
|
||||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||||
|
|
||||||
|
import '../../../exceptions/wallet/node_tor_mismatch_config_exception.dart';
|
||||||
import '../../../models/balance.dart';
|
import '../../../models/balance.dart';
|
||||||
import '../../../models/epicbox_config_model.dart';
|
import '../../../models/epicbox_config_model.dart';
|
||||||
import '../../../models/isar/models/blockchain_data/address.dart';
|
import '../../../models/isar/models/blockchain_data/address.dart';
|
||||||
|
@ -32,6 +33,7 @@ import '../../../utilities/flutter_secure_storage_interface.dart';
|
||||||
import '../../../utilities/logger.dart';
|
import '../../../utilities/logger.dart';
|
||||||
import '../../../utilities/stack_file_system.dart';
|
import '../../../utilities/stack_file_system.dart';
|
||||||
import '../../../utilities/test_epic_box_connection.dart';
|
import '../../../utilities/test_epic_box_connection.dart';
|
||||||
|
import '../../../utilities/tor_plain_net_option_enum.dart';
|
||||||
import '../../crypto_currency/crypto_currency.dart';
|
import '../../crypto_currency/crypto_currency.dart';
|
||||||
import '../../models/tx_data.dart';
|
import '../../models/tx_data.dart';
|
||||||
import '../intermediate/bip39_wallet.dart';
|
import '../intermediate/bip39_wallet.dart';
|
||||||
|
@ -82,6 +84,7 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
/// returns an empty String on success, error message on failure
|
/// returns an empty String on success, error message on failure
|
||||||
Future<String> cancelPendingTransactionAndPost(String txSlateId) async {
|
Future<String> cancelPendingTransactionAndPost(String txSlateId) async {
|
||||||
try {
|
try {
|
||||||
|
_hackedCheckTorNodePrefs();
|
||||||
final String wallet = (await secureStorageInterface.read(
|
final String wallet = (await secureStorageInterface.read(
|
||||||
key: '${walletId}_wallet',
|
key: '${walletId}_wallet',
|
||||||
))!;
|
))!;
|
||||||
|
@ -173,6 +176,7 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
}) async {
|
}) async {
|
||||||
final wallet = await secureStorageInterface.read(key: '${walletId}_wallet');
|
final wallet = await secureStorageInterface.read(key: '${walletId}_wallet');
|
||||||
try {
|
try {
|
||||||
|
_hackedCheckTorNodePrefs();
|
||||||
final available = info.cachedBalance.spendable.raw.toInt();
|
final available = info.cachedBalance.spendable.raw.toInt();
|
||||||
|
|
||||||
final transactionFees = await epiccash.LibEpiccash.getTransactionFees(
|
final transactionFees = await epiccash.LibEpiccash.getTransactionFees(
|
||||||
|
@ -198,6 +202,7 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _startSync() async {
|
Future<void> _startSync() async {
|
||||||
|
_hackedCheckTorNodePrefs();
|
||||||
Logging.instance.log("request start sync", level: LogLevel.Info);
|
Logging.instance.log("request start sync", level: LogLevel.Info);
|
||||||
final wallet = await secureStorageInterface.read(key: '${walletId}_wallet');
|
final wallet = await secureStorageInterface.read(key: '${walletId}_wallet');
|
||||||
const int refreshFromNode = 1;
|
const int refreshFromNode = 1;
|
||||||
|
@ -222,6 +227,7 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
double spendable,
|
double spendable,
|
||||||
double total
|
double total
|
||||||
})> _allWalletBalances() async {
|
})> _allWalletBalances() async {
|
||||||
|
_hackedCheckTorNodePrefs();
|
||||||
final wallet = await secureStorageInterface.read(key: '${walletId}_wallet');
|
final wallet = await secureStorageInterface.read(key: '${walletId}_wallet');
|
||||||
const refreshFromNode = 0;
|
const refreshFromNode = 0;
|
||||||
return await epiccash.LibEpiccash.getWalletBalances(
|
return await epiccash.LibEpiccash.getWalletBalances(
|
||||||
|
@ -232,6 +238,7 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> _testEpicboxServer(EpicBoxConfigModel epicboxConfig) async {
|
Future<bool> _testEpicboxServer(EpicBoxConfigModel epicboxConfig) async {
|
||||||
|
_hackedCheckTorNodePrefs();
|
||||||
final host = epicboxConfig.host;
|
final host = epicboxConfig.host;
|
||||||
final port = epicboxConfig.port ?? 443;
|
final port = epicboxConfig.port ?? 443;
|
||||||
WebSocketChannel? channel;
|
WebSocketChannel? channel;
|
||||||
|
@ -576,6 +583,7 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
@override
|
@override
|
||||||
Future<TxData> confirmSend({required TxData txData}) async {
|
Future<TxData> confirmSend({required TxData txData}) async {
|
||||||
try {
|
try {
|
||||||
|
_hackedCheckTorNodePrefs();
|
||||||
final wallet =
|
final wallet =
|
||||||
await secureStorageInterface.read(key: '${walletId}_wallet');
|
await secureStorageInterface.read(key: '${walletId}_wallet');
|
||||||
final EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig();
|
final EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig();
|
||||||
|
@ -638,6 +646,7 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
@override
|
@override
|
||||||
Future<TxData> prepareSend({required TxData txData}) async {
|
Future<TxData> prepareSend({required TxData txData}) async {
|
||||||
try {
|
try {
|
||||||
|
_hackedCheckTorNodePrefs();
|
||||||
if (txData.recipients?.length != 1) {
|
if (txData.recipients?.length != 1) {
|
||||||
throw Exception("Epic cash prepare send requires a single recipient!");
|
throw Exception("Epic cash prepare send requires a single recipient!");
|
||||||
}
|
}
|
||||||
|
@ -679,6 +688,7 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
@override
|
@override
|
||||||
Future<void> recover({required bool isRescan}) async {
|
Future<void> recover({required bool isRescan}) async {
|
||||||
try {
|
try {
|
||||||
|
_hackedCheckTorNodePrefs();
|
||||||
await refreshMutex.protect(() async {
|
await refreshMutex.protect(() async {
|
||||||
if (isRescan) {
|
if (isRescan) {
|
||||||
// clear blockchain info
|
// clear blockchain info
|
||||||
|
@ -782,6 +792,7 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
cryptoCurrency,
|
cryptoCurrency,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
_hackedCheckTorNodePrefs();
|
||||||
|
|
||||||
// if (info.epicData?.creationHeight == null) {
|
// if (info.epicData?.creationHeight == null) {
|
||||||
// await info.updateExtraEpiccashWalletInfo(epicData: inf, isar: isar)
|
// await info.updateExtraEpiccashWalletInfo(epicData: inf, isar: isar)
|
||||||
|
@ -880,6 +891,7 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
@override
|
@override
|
||||||
Future<void> updateBalance() async {
|
Future<void> updateBalance() async {
|
||||||
try {
|
try {
|
||||||
|
_hackedCheckTorNodePrefs();
|
||||||
final balances = await _allWalletBalances();
|
final balances = await _allWalletBalances();
|
||||||
final balance = Balance(
|
final balance = Balance(
|
||||||
total: Amount.fromDecimal(
|
total: Amount.fromDecimal(
|
||||||
|
@ -915,6 +927,7 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
@override
|
@override
|
||||||
Future<void> updateTransactions() async {
|
Future<void> updateTransactions() async {
|
||||||
try {
|
try {
|
||||||
|
_hackedCheckTorNodePrefs();
|
||||||
final wallet =
|
final wallet =
|
||||||
await secureStorageInterface.read(key: '${walletId}_wallet');
|
await secureStorageInterface.read(key: '${walletId}_wallet');
|
||||||
const refreshFromNode = 1;
|
const refreshFromNode = 1;
|
||||||
|
@ -1083,7 +1096,11 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
NodeFormData()
|
NodeFormData()
|
||||||
..host = node!.host
|
..host = node!.host
|
||||||
..useSSL = node.useSSL
|
..useSSL = node.useSSL
|
||||||
..port = node.port,
|
..port = node.port
|
||||||
|
..netOption = TorPlainNetworkOption.fromNodeData(
|
||||||
|
node.torEnabled,
|
||||||
|
node.clearnetEnabled,
|
||||||
|
),
|
||||||
) !=
|
) !=
|
||||||
null;
|
null;
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
|
@ -1094,6 +1111,7 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateChainHeight() async {
|
Future<void> updateChainHeight() async {
|
||||||
|
_hackedCheckTorNodePrefs();
|
||||||
final config = await _getRealConfig();
|
final config = await _getRealConfig();
|
||||||
final latestHeight =
|
final latestHeight =
|
||||||
await epiccash.LibEpiccash.getChainHeight(config: config);
|
await epiccash.LibEpiccash.getChainHeight(config: config);
|
||||||
|
@ -1105,6 +1123,7 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Amount> estimateFeeFor(Amount amount, int feeRate) async {
|
Future<Amount> estimateFeeFor(Amount amount, int feeRate) async {
|
||||||
|
_hackedCheckTorNodePrefs();
|
||||||
// setting ifErrorEstimateFee doesn't do anything as its not used in the nativeFee function?????
|
// setting ifErrorEstimateFee doesn't do anything as its not used in the nativeFee function?????
|
||||||
final int currentFee = await _nativeFee(
|
final int currentFee = await _nativeFee(
|
||||||
amount.raw.toInt(),
|
amount.raw.toInt(),
|
||||||
|
@ -1143,6 +1162,28 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
await super.exit();
|
await super.exit();
|
||||||
Logging.instance.log("EpicCash_wallet exit finished", level: LogLevel.Info);
|
Logging.instance.log("EpicCash_wallet exit finished", level: LogLevel.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _hackedCheckTorNodePrefs() {
|
||||||
|
final node = nodeService.getPrimaryNodeFor(currency: cryptoCurrency)!;
|
||||||
|
final netOption = TorPlainNetworkOption.fromNodeData(
|
||||||
|
node.torEnabled,
|
||||||
|
node.clearnetEnabled,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (prefs.useTor) {
|
||||||
|
if (netOption == TorPlainNetworkOption.clear) {
|
||||||
|
throw NodeTorMismatchConfigException(
|
||||||
|
message: "TOR enabled but node set to clearnet only",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (netOption == TorPlainNetworkOption.tor) {
|
||||||
|
throw NodeTorMismatchConfigException(
|
||||||
|
message: "TOR off but node set to TOR only",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> deleteEpicWallet({
|
Future<String> deleteEpicWallet({
|
||||||
|
|
Loading…
Reference in a new issue