Merge pull request #907 from cypherstack/sol

Sol fixes
This commit is contained in:
julian-CStack 2024-07-01 13:05:29 -06:00 committed by GitHub
commit 40f8767b11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 72 additions and 26 deletions

View file

@ -4,7 +4,6 @@ import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:solana/solana.dart';
import '../networking/http.dart'; import '../networking/http.dart';
import '../pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart'; import '../pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart';
@ -15,6 +14,7 @@ import '../wallets/crypto_currency/crypto_currency.dart';
import '../wallets/crypto_currency/interfaces/electrumx_currency_interface.dart'; import '../wallets/crypto_currency/interfaces/electrumx_currency_interface.dart';
import '../wallets/crypto_currency/intermediate/cryptonote_currency.dart'; import '../wallets/crypto_currency/intermediate/cryptonote_currency.dart';
import '../wallets/crypto_currency/intermediate/nano_currency.dart'; import '../wallets/crypto_currency/intermediate/nano_currency.dart';
import '../wallets/wallet/impl/solana_wallet.dart';
import 'connection_check/electrum_connection_check.dart'; import 'connection_check/electrum_connection_check.dart';
import 'logger.dart'; import 'logger.dart';
import 'test_epic_box_connection.dart'; import 'test_epic_box_connection.dart';
@ -210,14 +210,20 @@ Future<bool> testNodeConnection({
case Solana(): case Solana():
try { try {
RpcClient rpcClient; final rpcClient = SolanaWallet.createRpcClient(
if (formData.host!.startsWith("http") || formData.host!,
formData.host!.startsWith("https")) { formData.port!,
rpcClient = RpcClient("${formData.host}:${formData.port}"); formData.useSSL ?? false,
} else { ref.read(prefsChangeNotifierProvider),
rpcClient = RpcClient("http://${formData.host}:${formData.port}"); ref.read(pTorService),
} );
await rpcClient.getEpochInfo().then((value) => testPassed = true);
final health = await rpcClient.getHealth();
Logging.instance.log(
"Solana testNodeConnection \"health=$health\"",
level: LogLevel.Info,
);
return true;
} catch (_) { } catch (_) {
testPassed = false; testPassed = false;
} }

View file

@ -46,8 +46,7 @@ class Solana extends Bip39Currency {
switch (network) { switch (network) {
case CryptoCurrencyNetwork.main: case CryptoCurrencyNetwork.main:
return NodeModel( return NodeModel(
host: host: "https://solana.stackwallet.com",
"https://api.mainnet-beta.solana.com/", // TODO: Change this to stack wallet one
port: 443, port: 443,
name: DefaultNodes.defaultName, name: DefaultNodes.defaultName,
id: DefaultNodes.buildId(this), id: DefaultNodes.buildId(this),
@ -70,9 +69,13 @@ class Solana extends Bip39Currency {
@override @override
bool validateAddress(String address) { bool validateAddress(String address) {
return isPointOnEd25519Curve( try {
Ed25519HDPublicKey.fromBase58(address).toByteArray(), return isPointOnEd25519Curve(
); Ed25519HDPublicKey.fromBase58(address).toByteArray(),
);
} catch (_) {
return false;
}
} }
@override @override

View file

@ -18,6 +18,7 @@ import '../../../services/node_service.dart';
import '../../../services/tor_service.dart'; import '../../../services/tor_service.dart';
import '../../../utilities/amount/amount.dart'; import '../../../utilities/amount/amount.dart';
import '../../../utilities/logger.dart'; import '../../../utilities/logger.dart';
import '../../../utilities/prefs.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';
@ -245,14 +246,15 @@ class SolanaWallet extends Bip39Wallet<Solana> {
} }
@override @override
Future<bool> pingCheck() { Future<bool> pingCheck() async {
String? health;
try { try {
_checkClient(); _checkClient();
_rpcClient?.getHealth(); health = await _rpcClient?.getHealth();
return Future.value(true); return health != null;
} catch (e, s) { } catch (e, s) {
Logging.instance.log( Logging.instance.log(
"$runtimeType Solana pingCheck failed: $e\n$s", "$runtimeType Solana pingCheck failed \"health=$health\": $e\n$s",
level: LogLevel.Error, level: LogLevel.Error,
); );
return Future.value(false); return Future.value(false);
@ -453,32 +455,67 @@ class SolanaWallet extends Bip39Wallet<Solana> {
} }
@override @override
Future<bool> updateUTXOs() { Future<bool> updateUTXOs() async {
// No UTXOs in Solana // No UTXOs in Solana
return Future.value(false); return false;
} }
/// Make sure the Solana RpcClient uses Tor if it's enabled. /// Make sure the Solana RpcClient uses Tor if it's enabled.
/// ///
void _checkClient() async { void _checkClient() {
final node = getCurrentNode();
_rpcClient = createRpcClient(
node.host,
node.port,
node.useSSL,
prefs,
TorService.sharedInstance,
);
}
// static helper function for building a sol rpc client
static RpcClient createRpcClient(
final String host,
final int port,
final bool useSSL,
final Prefs prefs,
final TorService torService,
) {
HttpClient? httpClient; HttpClient? httpClient;
if (prefs.useTor) { if (prefs.useTor) {
// Make proxied HttpClient. // Make proxied HttpClient.
final ({InternetAddress host, int port}) proxyInfo = final proxyInfo = torService.getProxyInfo();
TorService.sharedInstance.getProxyInfo();
final proxySettings = ProxySettings(proxyInfo.host, proxyInfo.port); final proxySettings = ProxySettings(proxyInfo.host, proxyInfo.port);
httpClient = HttpClient(); httpClient = HttpClient();
SocksTCPClient.assignToHttpClient(httpClient, [proxySettings]); SocksTCPClient.assignToHttpClient(httpClient, [proxySettings]);
} }
_rpcClient = RpcClient( final regex = RegExp("^(http|https)://");
"${getCurrentNode().host}:${getCurrentNode().port}",
String editedHost;
if (host.startsWith(regex)) {
editedHost = host.replaceFirst(regex, "");
} else {
editedHost = host;
}
while (editedHost.endsWith("/")) {
editedHost = editedHost.substring(0, editedHost.length - 1);
}
final uri = Uri(
scheme: useSSL ? "https" : "http",
host: editedHost,
port: port,
);
return RpcClient(
uri.toString(),
timeout: const Duration(seconds: 30), timeout: const Duration(seconds: 30),
customHeaders: {}, customHeaders: {},
httpClient: httpClient, httpClient: httpClient,
); );
return;
} }
} }