2021-12-24 12:52:08 +00:00
|
|
|
import 'dart:io';
|
|
|
|
import 'package:cw_core/keyable.dart';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:hive/hive.dart';
|
2023-08-15 00:47:25 +00:00
|
|
|
import 'package:cw_core/hive_type_ids.dart';
|
2021-12-24 12:52:08 +00:00
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2022-02-03 10:16:24 +00:00
|
|
|
import 'package:http/io_client.dart' as ioc;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
part 'node.g.dart';
|
|
|
|
|
2023-10-05 01:09:07 +00:00
|
|
|
Uri createUriFromElectrumAddress(String address) => Uri.tryParse('tcp://$address')!;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
@HiveType(typeId: Node.typeId)
|
|
|
|
class Node extends HiveObject with Keyable {
|
2023-10-05 01:09:07 +00:00
|
|
|
Node({
|
|
|
|
this.login,
|
|
|
|
this.password,
|
|
|
|
this.useSSL,
|
|
|
|
this.trusted = false,
|
|
|
|
this.socksProxyAddress,
|
|
|
|
String? uri,
|
|
|
|
WalletType? type,
|
|
|
|
}) {
|
2022-10-12 17:09:57 +00:00
|
|
|
if (uri != null) {
|
|
|
|
uriRaw = uri;
|
|
|
|
}
|
|
|
|
if (type != null) {
|
|
|
|
this.type = type;
|
|
|
|
}
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
Node.fromMap(Map<String, Object?> map)
|
|
|
|
: uriRaw = map['uri'] as String? ?? '',
|
2022-10-19 22:23:53 +00:00
|
|
|
login = map['login'] as String?,
|
|
|
|
password = map['password'] as String?,
|
2022-10-20 11:18:00 +00:00
|
|
|
useSSL = map['useSSL'] as bool?,
|
2023-08-02 11:48:52 +00:00
|
|
|
trusted = map['trusted'] as bool? ?? false,
|
|
|
|
socksProxyAddress = map['socksProxyPort'] as String?;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2023-08-15 00:47:25 +00:00
|
|
|
static const typeId = NODE_TYPE_ID;
|
2021-12-24 12:52:08 +00:00
|
|
|
static const boxName = 'Nodes';
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(0, defaultValue: '')
|
2022-10-12 17:09:57 +00:00
|
|
|
late String uriRaw;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
@HiveField(1)
|
2022-10-12 17:09:57 +00:00
|
|
|
String? login;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
@HiveField(2)
|
2022-10-12 17:09:57 +00:00
|
|
|
String? password;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(3, defaultValue: 0)
|
2022-10-12 17:09:57 +00:00
|
|
|
late int typeRaw;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
@HiveField(4)
|
2022-10-12 17:09:57 +00:00
|
|
|
bool? useSSL;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2022-12-12 19:34:45 +00:00
|
|
|
@HiveField(5, defaultValue: false)
|
|
|
|
bool trusted;
|
2022-10-04 12:54:39 +00:00
|
|
|
|
2023-08-02 11:48:52 +00:00
|
|
|
@HiveField(6)
|
|
|
|
String? socksProxyAddress;
|
2024-01-27 00:37:21 +00:00
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
bool get isSSL => useSSL ?? false;
|
|
|
|
|
2023-08-02 11:48:52 +00:00
|
|
|
bool get useSocksProxy => socksProxyAddress == null ? false : socksProxyAddress!.isNotEmpty;
|
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
Uri get uri {
|
|
|
|
switch (type) {
|
|
|
|
case WalletType.monero:
|
CW-555-Add-Solana-Wallet (#1272)
* chore: Create cw_solana package and clean up files
* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens
* fix: Make transactions file specific to solana only for solana transactions
* chore: Revert inject app details script
* fix: Fix issue with node and switch current node to main beta instead of testnet
* fix: Fix merge conflicts and adjust migration version
* fix: Fetch spl token error
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
* fix: Diplay and activate spl tokens bug
* fix: Review and fixes
* fix: reverted formatting for cryptocurrency class
* fix: Review comments, split sending flow into signing and sending separately, fix issues
* fix: Revert throwing unimplenented error
* chore: Fix comment
* chore: Fix comment
* fix: Errors in flow
* Update provider_types.dart [skip ci]
* fix: Issues with solana wallet
* Update solana_wallet.dart [skip ci]
* fix: Review comments
* fix: Date time config
* fix: Revert bash script for app details
* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list
* fix: Issues with address validation when sending spl tokens and walletconnect initial setup
* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect
* fix: Adjust imports that would affect monerocom building successfully
* fix: Refine transaction direction and continue work on walletconnect
* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction
* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions
* feat: Switch node and revert solana chain id to previous id
* fix: Remove print statement
* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message
* chore: Code refactoring and streamlined wallet type check for solana send success message
* fix: Make timeout error for node silent and add spl token images
---------
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-02-23 13:39:19 +00:00
|
|
|
case WalletType.haven:
|
2021-12-24 12:52:08 +00:00
|
|
|
return Uri.http(uriRaw, '');
|
|
|
|
case WalletType.bitcoin:
|
|
|
|
case WalletType.litecoin:
|
2023-10-12 22:50:16 +00:00
|
|
|
case WalletType.bitcoinCash:
|
|
|
|
return createUriFromElectrumAddress(uriRaw);
|
2023-10-05 01:09:07 +00:00
|
|
|
case WalletType.nano:
|
|
|
|
case WalletType.banano:
|
|
|
|
if (isSSL) {
|
|
|
|
return Uri.https(uriRaw, '');
|
|
|
|
} else {
|
|
|
|
return Uri.http(uriRaw, '');
|
|
|
|
}
|
CW-555-Add-Solana-Wallet (#1272)
* chore: Create cw_solana package and clean up files
* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens
* fix: Make transactions file specific to solana only for solana transactions
* chore: Revert inject app details script
* fix: Fix issue with node and switch current node to main beta instead of testnet
* fix: Fix merge conflicts and adjust migration version
* fix: Fetch spl token error
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
* fix: Diplay and activate spl tokens bug
* fix: Review and fixes
* fix: reverted formatting for cryptocurrency class
* fix: Review comments, split sending flow into signing and sending separately, fix issues
* fix: Revert throwing unimplenented error
* chore: Fix comment
* chore: Fix comment
* fix: Errors in flow
* Update provider_types.dart [skip ci]
* fix: Issues with solana wallet
* Update solana_wallet.dart [skip ci]
* fix: Review comments
* fix: Date time config
* fix: Revert bash script for app details
* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list
* fix: Issues with address validation when sending spl tokens and walletconnect initial setup
* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect
* fix: Adjust imports that would affect monerocom building successfully
* fix: Refine transaction direction and continue work on walletconnect
* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction
* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions
* feat: Switch node and revert solana chain id to previous id
* fix: Remove print statement
* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message
* chore: Code refactoring and streamlined wallet type check for solana send success message
* fix: Make timeout error for node silent and add spl token images
---------
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-02-23 13:39:19 +00:00
|
|
|
case WalletType.ethereum:
|
2023-12-02 02:26:43 +00:00
|
|
|
case WalletType.polygon:
|
CW-555-Add-Solana-Wallet (#1272)
* chore: Create cw_solana package and clean up files
* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens
* fix: Make transactions file specific to solana only for solana transactions
* chore: Revert inject app details script
* fix: Fix issue with node and switch current node to main beta instead of testnet
* fix: Fix merge conflicts and adjust migration version
* fix: Fetch spl token error
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
* fix: Diplay and activate spl tokens bug
* fix: Review and fixes
* fix: reverted formatting for cryptocurrency class
* fix: Review comments, split sending flow into signing and sending separately, fix issues
* fix: Revert throwing unimplenented error
* chore: Fix comment
* chore: Fix comment
* fix: Errors in flow
* Update provider_types.dart [skip ci]
* fix: Issues with solana wallet
* Update solana_wallet.dart [skip ci]
* fix: Review comments
* fix: Date time config
* fix: Revert bash script for app details
* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list
* fix: Issues with address validation when sending spl tokens and walletconnect initial setup
* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect
* fix: Adjust imports that would affect monerocom building successfully
* fix: Refine transaction direction and continue work on walletconnect
* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction
* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions
* feat: Switch node and revert solana chain id to previous id
* fix: Remove print statement
* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message
* chore: Code refactoring and streamlined wallet type check for solana send success message
* fix: Make timeout error for node silent and add spl token images
---------
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-02-23 13:39:19 +00:00
|
|
|
case WalletType.solana:
|
2023-12-02 02:26:43 +00:00
|
|
|
return Uri.https(uriRaw, '');
|
2021-12-24 12:52:08 +00:00
|
|
|
default:
|
2022-10-12 17:09:57 +00:00
|
|
|
throw Exception('Unexpected type ${type.toString()} for Node uri');
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-20 17:40:47 +00:00
|
|
|
bool get isValidProxyAddress => socksProxyAddress?.contains(':') ?? false;
|
|
|
|
|
2023-04-14 18:55:12 +00:00
|
|
|
@override
|
|
|
|
bool operator ==(other) =>
|
|
|
|
other is Node &&
|
2023-10-05 01:09:07 +00:00
|
|
|
(other.uriRaw == uriRaw &&
|
|
|
|
other.login == login &&
|
|
|
|
other.password == password &&
|
|
|
|
other.typeRaw == typeRaw &&
|
|
|
|
other.useSSL == useSSL &&
|
|
|
|
other.trusted == trusted &&
|
|
|
|
other.socksProxyAddress == socksProxyAddress);
|
2023-04-14 18:55:12 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
int get hashCode =>
|
|
|
|
uriRaw.hashCode ^
|
|
|
|
login.hashCode ^
|
|
|
|
password.hashCode ^
|
|
|
|
typeRaw.hashCode ^
|
|
|
|
useSSL.hashCode ^
|
2023-08-02 11:48:52 +00:00
|
|
|
trusted.hashCode ^
|
|
|
|
socksProxyAddress.hashCode;
|
2023-04-14 18:55:12 +00:00
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
@override
|
|
|
|
dynamic get keyIndex {
|
|
|
|
_keyIndex ??= key;
|
|
|
|
return _keyIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
WalletType get type => deserializeFromInt(typeRaw);
|
|
|
|
|
|
|
|
set type(WalletType type) => typeRaw = serializeToInt(type);
|
|
|
|
|
|
|
|
dynamic _keyIndex;
|
|
|
|
|
|
|
|
Future<bool> requestNode() async {
|
|
|
|
try {
|
|
|
|
switch (type) {
|
|
|
|
case WalletType.monero:
|
2022-06-08 08:17:03 +00:00
|
|
|
case WalletType.haven:
|
|
|
|
return requestMoneroNode();
|
2023-10-05 01:09:07 +00:00
|
|
|
case WalletType.nano:
|
|
|
|
case WalletType.banano:
|
|
|
|
return requestNanoNode();
|
CW-555-Add-Solana-Wallet (#1272)
* chore: Create cw_solana package and clean up files
* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens
* fix: Make transactions file specific to solana only for solana transactions
* chore: Revert inject app details script
* fix: Fix issue with node and switch current node to main beta instead of testnet
* fix: Fix merge conflicts and adjust migration version
* fix: Fetch spl token error
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
* fix: Diplay and activate spl tokens bug
* fix: Review and fixes
* fix: reverted formatting for cryptocurrency class
* fix: Review comments, split sending flow into signing and sending separately, fix issues
* fix: Revert throwing unimplenented error
* chore: Fix comment
* chore: Fix comment
* fix: Errors in flow
* Update provider_types.dart [skip ci]
* fix: Issues with solana wallet
* Update solana_wallet.dart [skip ci]
* fix: Review comments
* fix: Date time config
* fix: Revert bash script for app details
* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list
* fix: Issues with address validation when sending spl tokens and walletconnect initial setup
* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect
* fix: Adjust imports that would affect monerocom building successfully
* fix: Refine transaction direction and continue work on walletconnect
* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction
* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions
* feat: Switch node and revert solana chain id to previous id
* fix: Remove print statement
* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message
* chore: Code refactoring and streamlined wallet type check for solana send success message
* fix: Make timeout error for node silent and add spl token images
---------
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-02-23 13:39:19 +00:00
|
|
|
case WalletType.bitcoin:
|
|
|
|
case WalletType.litecoin:
|
|
|
|
case WalletType.bitcoinCash:
|
|
|
|
case WalletType.ethereum:
|
2023-12-02 02:26:43 +00:00
|
|
|
case WalletType.polygon:
|
CW-555-Add-Solana-Wallet (#1272)
* chore: Create cw_solana package and clean up files
* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens
* fix: Make transactions file specific to solana only for solana transactions
* chore: Revert inject app details script
* fix: Fix issue with node and switch current node to main beta instead of testnet
* fix: Fix merge conflicts and adjust migration version
* fix: Fetch spl token error
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
* fix: Diplay and activate spl tokens bug
* fix: Review and fixes
* fix: reverted formatting for cryptocurrency class
* fix: Review comments, split sending flow into signing and sending separately, fix issues
* fix: Revert throwing unimplenented error
* chore: Fix comment
* chore: Fix comment
* fix: Errors in flow
* Update provider_types.dart [skip ci]
* fix: Issues with solana wallet
* Update solana_wallet.dart [skip ci]
* fix: Review comments
* fix: Date time config
* fix: Revert bash script for app details
* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list
* fix: Issues with address validation when sending spl tokens and walletconnect initial setup
* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect
* fix: Adjust imports that would affect monerocom building successfully
* fix: Refine transaction direction and continue work on walletconnect
* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction
* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions
* feat: Switch node and revert solana chain id to previous id
* fix: Remove print statement
* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message
* chore: Code refactoring and streamlined wallet type check for solana send success message
* fix: Make timeout error for node silent and add spl token images
---------
Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-02-23 13:39:19 +00:00
|
|
|
case WalletType.solana:
|
2023-12-02 02:26:43 +00:00
|
|
|
return requestElectrumServer();
|
2021-12-24 12:52:08 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} catch (_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<bool> requestMoneroNode() async {
|
2024-01-27 02:02:10 +00:00
|
|
|
if (uri.toString().contains(".onion") || useSocksProxy) {
|
|
|
|
return await requestNodeWithProxy();
|
|
|
|
}
|
2022-02-03 11:46:45 +00:00
|
|
|
final path = '/json_rpc';
|
|
|
|
final rpcUri = isSSL ? Uri.https(uri.authority, path) : Uri.http(uri.authority, path);
|
|
|
|
final realm = 'monero-rpc';
|
2023-10-05 01:09:07 +00:00
|
|
|
final body = {'jsonrpc': '2.0', 'id': '0', 'method': 'get_info'};
|
2022-02-03 11:46:45 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
final authenticatingClient = HttpClient();
|
2022-10-20 11:18:00 +00:00
|
|
|
|
2023-11-03 19:24:45 +00:00
|
|
|
authenticatingClient.badCertificateCallback =
|
|
|
|
((X509Certificate cert, String host, int port) => true);
|
|
|
|
|
2022-02-03 11:46:45 +00:00
|
|
|
authenticatingClient.addCredentials(
|
2023-10-05 01:09:07 +00:00
|
|
|
rpcUri,
|
|
|
|
realm,
|
|
|
|
HttpClientDigestCredentials(login ?? '', password ?? ''),
|
2022-02-03 11:46:45 +00:00
|
|
|
);
|
2022-10-20 11:18:00 +00:00
|
|
|
|
2024-01-27 02:02:10 +00:00
|
|
|
final http.Client client = ioc.IOClient(authenticatingClient);
|
|
|
|
|
|
|
|
final response = await client.post(
|
|
|
|
rpcUri,
|
|
|
|
headers: {'Content-Type': 'application/json'},
|
|
|
|
body: json.encode(body),
|
|
|
|
);
|
2022-02-03 11:46:45 +00:00
|
|
|
|
2024-01-27 02:02:10 +00:00
|
|
|
client.close();
|
|
|
|
|
|
|
|
final resBody = json.decode(response.body) as Map<String, dynamic>;
|
2022-02-03 11:46:45 +00:00
|
|
|
return !(resBody['result']['offline'] as bool);
|
|
|
|
} catch (_) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-08-04 17:01:49 +00:00
|
|
|
}
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2023-10-05 01:09:07 +00:00
|
|
|
Future<bool> requestNanoNode() async {
|
|
|
|
http.Response response = await http.post(
|
|
|
|
uri,
|
|
|
|
headers: {'Content-type': 'application/json'},
|
|
|
|
body: json.encode(
|
|
|
|
{
|
|
|
|
"action": "block_count",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-08-02 11:48:52 +00:00
|
|
|
|
2023-11-18 13:43:15 +00:00
|
|
|
Future<bool> requestNodeWithProxy() async {
|
2024-01-27 02:02:10 +00:00
|
|
|
if (!isValidProxyAddress) {
|
2023-08-02 11:48:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
2023-11-18 13:43:15 +00:00
|
|
|
|
|
|
|
String? proxy = socksProxyAddress;
|
|
|
|
|
2023-12-05 00:35:33 +00:00
|
|
|
if (proxy == null) {
|
|
|
|
return false;
|
2023-11-18 13:43:15 +00:00
|
|
|
}
|
2024-01-27 02:02:10 +00:00
|
|
|
final proxyAddress = proxy.split(':')[0];
|
2023-08-02 11:48:52 +00:00
|
|
|
final proxyPort = int.parse(proxy.split(':')[1]);
|
|
|
|
try {
|
|
|
|
final socket = await Socket.connect(proxyAddress, proxyPort, timeout: Duration(seconds: 5));
|
|
|
|
socket.destroy();
|
|
|
|
return true;
|
|
|
|
} catch (_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
Future<bool> requestElectrumServer() async {
|
|
|
|
try {
|
|
|
|
await SecureSocket.connect(uri.host, uri.port,
|
|
|
|
timeout: Duration(seconds: 5), onBadCertificate: (_) => true);
|
|
|
|
return true;
|
|
|
|
} catch (_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-08-04 17:01:49 +00:00
|
|
|
|
|
|
|
Future<bool> requestEthereumServer() async {
|
|
|
|
try {
|
|
|
|
final response = await http.get(
|
|
|
|
uri,
|
|
|
|
headers: {'Content-Type': 'application/json'},
|
|
|
|
);
|
|
|
|
|
|
|
|
return response.statusCode >= 200 && response.statusCode < 300;
|
|
|
|
} catch (_) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|