hack in a tor check to nano and banano

This commit is contained in:
julian 2024-11-26 10:14:02 -06:00
parent d87af969d6
commit 31fe9a538b

View file

@ -5,6 +5,7 @@ import 'package:isar/isar.dart';
import 'package:nanodart/nanodart.dart'; import 'package:nanodart/nanodart.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
import '../../../exceptions/wallet/node_tor_mismatch_config_exception.dart';
import '../../../external_api_keys.dart'; import '../../../external_api_keys.dart';
import '../../../models/balance.dart'; import '../../../models/balance.dart';
import '../../../models/isar/models/blockchain_data/address.dart'; import '../../../models/isar/models/blockchain_data/address.dart';
@ -18,6 +19,7 @@ import '../../../services/tor_service.dart';
import '../../../utilities/amount/amount.dart'; import '../../../utilities/amount/amount.dart';
import '../../../utilities/extensions/impl/string.dart'; import '../../../utilities/extensions/impl/string.dart';
import '../../../utilities/logger.dart'; import '../../../utilities/logger.dart';
import '../../../utilities/tor_plain_net_option_enum.dart';
import '../../crypto_currency/intermediate/nano_currency.dart'; import '../../crypto_currency/intermediate/nano_currency.dart';
import '../../models/tx_data.dart'; import '../../models/tx_data.dart';
import '../intermediate/bip39_wallet.dart'; import '../intermediate/bip39_wallet.dart';
@ -47,6 +49,7 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
final _httpClient = HTTP(); final _httpClient = HTTP();
Future<String?> _requestWork(String hash) async { Future<String?> _requestWork(String hash) async {
_hackedCheckTorNodePrefs();
return _httpClient return _httpClient
.post( .post(
url: Uri.parse(_kWorkServer), // this should be a url: Uri.parse(_kWorkServer), // this should be a
@ -104,6 +107,7 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
String amountRaw, String amountRaw,
String publicAddress, String publicAddress,
) async { ) async {
_hackedCheckTorNodePrefs();
// TODO: the opening block of an account is a special case // TODO: the opening block of an account is a special case
bool openBlock = false; bool openBlock = false;
@ -223,6 +227,7 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
} }
Future<void> _confirmAllReceivable(String accountAddress) async { Future<void> _confirmAllReceivable(String accountAddress) async {
_hackedCheckTorNodePrefs();
final node = getCurrentNode(); final node = getCurrentNode();
final receivableResponse = await _httpClient.post( final receivableResponse = await _httpClient.post(
url: Uri.parse(node.host), url: Uri.parse(node.host),
@ -254,6 +259,7 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
//========= public =========================================================== //========= public ===========================================================
Future<String> getCurrentRepresentative() async { Future<String> getCurrentRepresentative() async {
_hackedCheckTorNodePrefs();
final serverURI = Uri.parse(getCurrentNode().host); final serverURI = Uri.parse(getCurrentNode().host);
final address = final address =
(_cachedAddress ?? await getCurrentReceivingAddress())!.value; (_cachedAddress ?? await getCurrentReceivingAddress())!.value;
@ -272,6 +278,7 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
Future<bool> changeRepresentative(String newRepresentative) async { Future<bool> changeRepresentative(String newRepresentative) async {
try { try {
_hackedCheckTorNodePrefs();
final node = getCurrentNode(); final node = getCurrentNode();
final serverURI = Uri.parse(node.host); final serverURI = Uri.parse(node.host);
await updateBalance(); await updateBalance();
@ -347,6 +354,11 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
@override @override
Future<bool> pingCheck() async { Future<bool> pingCheck() async {
try {
_hackedCheckTorNodePrefs();
} catch (_) {
return false;
}
final node = getCurrentNode(); final node = getCurrentNode();
final uri = Uri.parse(node.host); final uri = Uri.parse(node.host);
final response = await _httpClient.post( final response = await _httpClient.post(
@ -365,6 +377,7 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
@override @override
Future<TxData> prepareSend({required TxData txData}) async { Future<TxData> prepareSend({required TxData txData}) async {
_hackedCheckTorNodePrefs();
if (txData.recipients!.length != 1) { if (txData.recipients!.length != 1) {
throw ArgumentError( throw ArgumentError(
"${cryptoCurrency.runtimeType} currently only " "${cryptoCurrency.runtimeType} currently only "
@ -383,6 +396,7 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
@override @override
Future<TxData> confirmSend({required TxData txData}) async { Future<TxData> confirmSend({required TxData txData}) async {
try { try {
_hackedCheckTorNodePrefs();
// our address: // our address:
final String publicAddress = final String publicAddress =
(_cachedAddress ?? await getCurrentReceivingAddress())!.value; (_cachedAddress ?? await getCurrentReceivingAddress())!.value;
@ -483,6 +497,7 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
@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) {
await mainDB.deleteWalletBlockchainData(walletId); await mainDB.deleteWalletBlockchainData(walletId);
@ -505,6 +520,7 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
String? previous, String? previous,
Map<String, dynamic>? data, Map<String, dynamic>? data,
) async { ) async {
_hackedCheckTorNodePrefs();
final node = getCurrentNode(); final node = getCurrentNode();
final body = { final body = {
"action": "account_history", "action": "account_history",
@ -543,6 +559,7 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
@override @override
Future<void> updateTransactions() async { Future<void> updateTransactions() async {
_hackedCheckTorNodePrefs();
await updateChainHeight(); await updateChainHeight();
final receivingAddress = final receivingAddress =
(_cachedAddress ?? await getCurrentReceivingAddress())!; (_cachedAddress ?? await getCurrentReceivingAddress())!;
@ -613,6 +630,7 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
@override @override
Future<void> updateBalance() async { Future<void> updateBalance() async {
try { try {
_hackedCheckTorNodePrefs();
final addressString = final addressString =
(_cachedAddress ??= (await getCurrentReceivingAddress())!).value; (_cachedAddress ??= (await getCurrentReceivingAddress())!).value;
final body = jsonEncode({ final body = jsonEncode({
@ -661,6 +679,7 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
@override @override
Future<void> updateChainHeight() async { Future<void> updateChainHeight() async {
try { try {
_hackedCheckTorNodePrefs();
final String publicAddress = final String publicAddress =
(_cachedAddress ??= (await getCurrentReceivingAddress())!).value; (_cachedAddress ??= (await getCurrentReceivingAddress())!).value;
@ -724,4 +743,26 @@ mixin NanoInterface<T extends NanoCurrency> on Bip39Wallet<T> {
medium: 0, medium: 0,
slow: 0, slow: 0,
); );
void _hackedCheckTorNodePrefs() {
final node = getCurrentNode();
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",
);
}
}
}
} }