mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-22 19:39:22 +00:00
feat: total tor support for cardano
This commit is contained in:
parent
02dc5c9416
commit
1ec7ee95d2
4 changed files with 60 additions and 39 deletions
|
@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:on_chain/ada/ada.dart';
|
||||
import 'package:on_chain/ada/src/provider/provider/provider.dart';
|
||||
import 'package:socks5_proxy/socks.dart';
|
||||
|
||||
import '../networking/http.dart';
|
||||
import '../pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart';
|
||||
|
@ -243,9 +244,21 @@ Future<bool> testNodeConnection({
|
|||
|
||||
case Cardano():
|
||||
try {
|
||||
final client = HttpClient();
|
||||
if (ref
|
||||
.read(prefsChangeNotifierProvider)
|
||||
.useTor) {
|
||||
final proxyInfo = TorService.sharedInstance.getProxyInfo();
|
||||
final proxySettings = ProxySettings(
|
||||
proxyInfo.host,
|
||||
proxyInfo.port,
|
||||
);
|
||||
SocksTCPClient.assignToHttpClient(client, [proxySettings]);
|
||||
}
|
||||
final blockfrostProvider = BlockforestProvider(
|
||||
BlockfrostHttpProvider(
|
||||
url: "${formData.host!}:${formData.port!}/api/v0",
|
||||
client: client,
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -1,51 +1,49 @@
|
|||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:io';
|
||||
import 'package:on_chain/ada/src/provider/blockfrost/core/core.dart';
|
||||
import 'package:on_chain/ada/src/provider/service/service.dart';
|
||||
|
||||
import '../../../utilities/logger.dart';
|
||||
|
||||
class BlockfrostHttpProvider implements BlockfrostServiceProvider {
|
||||
BlockfrostHttpProvider(
|
||||
{required this.url,
|
||||
this.version = "v0",
|
||||
this.projectId,
|
||||
http.Client? client,
|
||||
this.defaultRequestTimeout = const Duration(seconds: 30)})
|
||||
: client = client ?? http.Client();
|
||||
BlockfrostHttpProvider({
|
||||
required this.url,
|
||||
this.version = "v0",
|
||||
this.projectId,
|
||||
HttpClient? client,
|
||||
this.defaultRequestTimeout = const Duration(seconds: 30),
|
||||
}) : client = client ?? HttpClient();
|
||||
@override
|
||||
final String url;
|
||||
final String version;
|
||||
final String? projectId;
|
||||
final http.Client client;
|
||||
final HttpClient client;
|
||||
final Duration defaultRequestTimeout;
|
||||
|
||||
@override
|
||||
Future<dynamic> get(BlockforestRequestDetails params,
|
||||
[Duration? timeout]) async {
|
||||
final response =
|
||||
await client.get(Uri.parse(params.url(url, "api/$version")), headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Accept": "application/json",
|
||||
if (projectId != null) ...{"project_id": projectId!},
|
||||
}).timeout(timeout ?? defaultRequestTimeout);
|
||||
final data = json.decode(response.body);
|
||||
[Duration? timeout,]) async {
|
||||
final response = await client.getUrl(Uri.parse(params.url(url, "api/$version"))).timeout(timeout ?? defaultRequestTimeout);
|
||||
response.headers.add("Content-Type", "application/json");
|
||||
response.headers.add("Accept", "application/json");
|
||||
if (projectId != null) {
|
||||
response.headers.add("project_id", projectId!);
|
||||
}
|
||||
final responseStream = await response.close();
|
||||
final data = json.decode(await responseStream.transform(utf8.decoder).join());
|
||||
return data;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<dynamic> post(BlockforestRequestDetails params,
|
||||
[Duration? timeout]) async {
|
||||
final response = await client
|
||||
.post(Uri.parse(params.url(url, "api/$version")),
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
if (projectId != null) ...{"project_id": projectId!},
|
||||
...params.header
|
||||
},
|
||||
body: params.body)
|
||||
.timeout(timeout ?? defaultRequestTimeout);
|
||||
final data = json.decode(response.body);
|
||||
[Duration? timeout,]) async {
|
||||
final request = await client.postUrl(Uri.parse(params.url(url, "api/$version"))).timeout(timeout ?? defaultRequestTimeout);
|
||||
request.headers.add("Content-Type", "application/json");
|
||||
request.headers.add("Accept", "application/json");
|
||||
if (projectId != null) {
|
||||
request.headers.add("project_id", projectId!);
|
||||
}
|
||||
request.write(json.encode(params.body));
|
||||
final response = await request.close();
|
||||
final data = json.decode(await response.transform(utf8.decoder).join());
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,6 +111,9 @@ class Cardano extends Bip39Currency {
|
|||
@override
|
||||
int get targetBlockTimeSeconds => 20;
|
||||
|
||||
@override
|
||||
bool get torSupport => true;
|
||||
|
||||
@override
|
||||
bool validateAddress(String address) {
|
||||
switch (network) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:blockchain_utils/bip/bip/bip44/base/bip44_base.dart';
|
||||
import 'package:blockchain_utils/bip/cardano/bip32/cardano_icarus_bip32.dart';
|
||||
|
@ -7,6 +8,7 @@ import 'package:blockchain_utils/bip/cardano/cip1852/conf/cip1852_coins.dart';
|
|||
import 'package:blockchain_utils/bip/cardano/mnemonic/cardano_icarus_seed_generator.dart';
|
||||
import 'package:blockchain_utils/bip/cardano/shelley/cardano_shelley.dart';
|
||||
import 'package:on_chain/ada/ada.dart';
|
||||
import 'package:socks5_proxy/socks.dart';
|
||||
import '../../../models/balance.dart';
|
||||
import '../../../models/isar/models/blockchain_data/address.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
@ -84,12 +86,7 @@ class CardanoWallet extends Bip39Wallet<Cardano> {
|
|||
@override
|
||||
Future<bool> pingCheck() async {
|
||||
try {
|
||||
final currentNode = getCurrentNode();
|
||||
blockfrostProvider = BlockforestProvider(
|
||||
BlockfrostHttpProvider(
|
||||
url: "${currentNode.host}:${currentNode.port}/api/v0",
|
||||
),
|
||||
);
|
||||
await updateProvider();
|
||||
|
||||
final health = await blockfrostProvider!.request(
|
||||
BlockfrostRequestBackendHealthStatus(),
|
||||
|
@ -176,7 +173,7 @@ class CardanoWallet extends Bip39Wallet<Cardano> {
|
|||
);
|
||||
|
||||
var leftAmountForUtxos = txData.amount!.raw;
|
||||
var listOfUtxosToBeUsed = <ADAAccountUTXOResponse>[];
|
||||
final listOfUtxosToBeUsed = <ADAAccountUTXOResponse>[];
|
||||
var totalBalance = BigInt.zero;
|
||||
|
||||
for (final utxo in utxos) {
|
||||
|
@ -271,7 +268,7 @@ class CardanoWallet extends Bip39Wallet<Cardano> {
|
|||
|
||||
|
||||
var leftAmountForUtxos = txData.amount!.raw + txData.fee!.raw;
|
||||
var listOfUtxosToBeUsed = <ADAAccountUTXOResponse>[];
|
||||
final listOfUtxosToBeUsed = <ADAAccountUTXOResponse>[];
|
||||
var totalBalance = BigInt.zero;
|
||||
|
||||
for (final utxo in utxos) {
|
||||
|
@ -551,9 +548,19 @@ class CardanoWallet extends Bip39Wallet<Cardano> {
|
|||
|
||||
Future<void> updateProvider() async {
|
||||
final currentNode = getCurrentNode();
|
||||
final client = HttpClient();
|
||||
if (prefs.useTor) {
|
||||
final proxyInfo = TorService.sharedInstance.getProxyInfo();
|
||||
final proxySettings = ProxySettings(
|
||||
proxyInfo.host,
|
||||
proxyInfo.port,
|
||||
);
|
||||
SocksTCPClient.assignToHttpClient(client, [proxySettings]);
|
||||
}
|
||||
blockfrostProvider = BlockforestProvider(
|
||||
BlockfrostHttpProvider(
|
||||
url: "${currentNode.host}:${currentNode.port}/",
|
||||
client: client,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue