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_riverpod/flutter_riverpod.dart';
import 'package:solana/solana.dart';
import '../networking/http.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/intermediate/cryptonote_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 'logger.dart';
import 'test_epic_box_connection.dart';
@ -210,14 +210,20 @@ Future<bool> testNodeConnection({
case Solana():
try {
RpcClient rpcClient;
if (formData.host!.startsWith("http") ||
formData.host!.startsWith("https")) {
rpcClient = RpcClient("${formData.host}:${formData.port}");
} else {
rpcClient = RpcClient("http://${formData.host}:${formData.port}");
}
await rpcClient.getEpochInfo().then((value) => testPassed = true);
final rpcClient = SolanaWallet.createRpcClient(
formData.host!,
formData.port!,
formData.useSSL ?? false,
ref.read(prefsChangeNotifierProvider),
ref.read(pTorService),
);
final health = await rpcClient.getHealth();
Logging.instance.log(
"Solana testNodeConnection \"health=$health\"",
level: LogLevel.Info,
);
return true;
} catch (_) {
testPassed = false;
}

View file

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

View file

@ -18,6 +18,7 @@ import '../../../services/node_service.dart';
import '../../../services/tor_service.dart';
import '../../../utilities/amount/amount.dart';
import '../../../utilities/logger.dart';
import '../../../utilities/prefs.dart';
import '../../crypto_currency/crypto_currency.dart';
import '../../models/tx_data.dart';
import '../intermediate/bip39_wallet.dart';
@ -245,14 +246,15 @@ class SolanaWallet extends Bip39Wallet<Solana> {
}
@override
Future<bool> pingCheck() {
Future<bool> pingCheck() async {
String? health;
try {
_checkClient();
_rpcClient?.getHealth();
return Future.value(true);
health = await _rpcClient?.getHealth();
return health != null;
} catch (e, s) {
Logging.instance.log(
"$runtimeType Solana pingCheck failed: $e\n$s",
"$runtimeType Solana pingCheck failed \"health=$health\": $e\n$s",
level: LogLevel.Error,
);
return Future.value(false);
@ -453,32 +455,67 @@ class SolanaWallet extends Bip39Wallet<Solana> {
}
@override
Future<bool> updateUTXOs() {
Future<bool> updateUTXOs() async {
// No UTXOs in Solana
return Future.value(false);
return false;
}
/// 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;
if (prefs.useTor) {
// Make proxied HttpClient.
final ({InternetAddress host, int port}) proxyInfo =
TorService.sharedInstance.getProxyInfo();
final proxyInfo = torService.getProxyInfo();
final proxySettings = ProxySettings(proxyInfo.host, proxyInfo.port);
httpClient = HttpClient();
SocksTCPClient.assignToHttpClient(httpClient, [proxySettings]);
}
_rpcClient = RpcClient(
"${getCurrentNode().host}:${getCurrentNode().port}",
final regex = RegExp("^(http|https)://");
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),
customHeaders: {},
httpClient: httpClient,
);
return;
}
}