mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-10 20:54:33 +00:00
clean up test epicbox connection
This commit is contained in:
parent
bfba6d9f5d
commit
3fe7f47d8b
3 changed files with 44 additions and 58 deletions
|
@ -36,7 +36,7 @@ import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
|
||||||
import 'package:stackwallet/wallets/models/tx_data.dart';
|
import 'package:stackwallet/wallets/models/tx_data.dart';
|
||||||
import 'package:stackwallet/wallets/wallet/intermediate/bip39_wallet.dart';
|
import 'package:stackwallet/wallets/wallet/intermediate/bip39_wallet.dart';
|
||||||
import 'package:stackwallet/wallets/wallet/supporting/epiccash_wallet_info_extension.dart';
|
import 'package:stackwallet/wallets/wallet/supporting/epiccash_wallet_info_extension.dart';
|
||||||
import 'package:websocket_universal/websocket_universal.dart';
|
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||||
|
|
||||||
//
|
//
|
||||||
// refactor of https://github.com/cypherstack/stack_wallet/blob/1d9fb4cd069f22492ece690ac788e05b8f8b1209/lib/services/coins/epiccash/epiccash_wallet.dart
|
// refactor of https://github.com/cypherstack/stack_wallet/blob/1d9fb4cd069f22492ece690ac788e05b8f8b1209/lib/services/coins/epiccash/epiccash_wallet.dart
|
||||||
|
@ -103,8 +103,9 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<EpicBoxConfigModel> getEpicBoxConfig() async {
|
Future<EpicBoxConfigModel> getEpicBoxConfig() async {
|
||||||
EpicBoxConfigModel? _epicBoxConfig =
|
EpicBoxConfigModel? _epicBoxConfig = EpicBoxConfigModel.fromServer(
|
||||||
EpicBoxConfigModel.fromServer(DefaultEpicBoxes.defaultEpicBoxServer);
|
DefaultEpicBoxes.defaultEpicBoxServer,
|
||||||
|
);
|
||||||
|
|
||||||
//Get the default Epicbox server and check if it's conected
|
//Get the default Epicbox server and check if it's conected
|
||||||
// bool isEpicboxConnected = await _testEpicboxServer(
|
// bool isEpicboxConnected = await _testEpicboxServer(
|
||||||
|
@ -231,48 +232,33 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> _testEpicboxServer(String host, int port) async {
|
Future<bool> _testEpicboxServer(EpicBoxConfigModel epicboxConfig) async {
|
||||||
// TODO use an EpicBoxServerModel as the only param
|
final host = epicboxConfig.host;
|
||||||
final websocketConnectionUri = 'wss://$host:$port';
|
final port = epicboxConfig.port ?? 443;
|
||||||
const connectionOptions = SocketConnectionOptions(
|
WebSocketChannel? channel;
|
||||||
pingIntervalMs: 3000,
|
try {
|
||||||
timeoutConnectionMs: 4000,
|
final uri = Uri.parse('wss://$host:$port');
|
||||||
|
|
||||||
/// see ping/pong messages in [logEventStream] stream
|
channel = WebSocketChannel.connect(
|
||||||
skipPingMessages: true,
|
uri,
|
||||||
|
|
||||||
/// Set this attribute to `true` if do not need any ping/pong
|
|
||||||
/// messages and ping measurement. Default is `false`
|
|
||||||
pingRestrictionForce: true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final IMessageProcessor<String, String> textSocketProcessor =
|
await channel.ready;
|
||||||
SocketSimpleTextProcessor();
|
|
||||||
final textSocketHandler = IWebSocketHandler<String, String>.createClient(
|
final response = await channel.stream.first.timeout(
|
||||||
websocketConnectionUri,
|
const Duration(seconds: 2),
|
||||||
textSocketProcessor,
|
|
||||||
connectionOptions: connectionOptions,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Listening to server responses:
|
return response is String && response.contains("Challenge");
|
||||||
bool isConnected = true;
|
} catch (_) {
|
||||||
textSocketHandler.incomingMessagesStream.listen((inMsg) {
|
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
'> webSocket got text message from server: "$inMsg" '
|
"_testEpicBoxConnection failed on \"$host:$port\"",
|
||||||
'[ping: ${textSocketHandler.pingDelayMs}]',
|
level: LogLevel.Info,
|
||||||
level: LogLevel.Info);
|
);
|
||||||
});
|
return false;
|
||||||
|
} finally {
|
||||||
// Connecting to server:
|
await channel?.sink.close();
|
||||||
final isTextSocketConnected = await textSocketHandler.connect();
|
|
||||||
if (!isTextSocketConnected) {
|
|
||||||
// ignore: avoid_print
|
|
||||||
Logging.instance.log(
|
|
||||||
'Connection to [$websocketConnectionUri] failed for some reason!',
|
|
||||||
level: LogLevel.Error);
|
|
||||||
isConnected = false;
|
|
||||||
}
|
}
|
||||||
return isConnected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> _putSendToAddresses(
|
Future<bool> _putSendToAddresses(
|
||||||
|
@ -335,9 +321,9 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Address> thisWalletAddress(int index, EpicBoxConfigModel epicboxConfig) async {
|
Future<Address> thisWalletAddress(
|
||||||
final wallet =
|
int index, EpicBoxConfigModel epicboxConfig) async {
|
||||||
await secureStorageInterface.read(key: '${walletId}_wallet');
|
final wallet = await secureStorageInterface.read(key: '${walletId}_wallet');
|
||||||
// EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig();
|
// EpicBoxConfigModel epicboxConfig = await getEpicBoxConfig();
|
||||||
|
|
||||||
final walletAddress = await epiccash.LibEpiccash.getAddressInfo(
|
final walletAddress = await epiccash.LibEpiccash.getAddressInfo(
|
||||||
|
@ -594,7 +580,8 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
if (!receiverAddress.startsWith("http://") ||
|
if (!receiverAddress.startsWith("http://") ||
|
||||||
!receiverAddress.startsWith("https://")) {
|
!receiverAddress.startsWith("https://")) {
|
||||||
bool isEpicboxConnected = await _testEpicboxServer(
|
bool isEpicboxConnected = await _testEpicboxServer(
|
||||||
epicboxConfig.host, epicboxConfig.port ?? 443);
|
epicboxConfig,
|
||||||
|
);
|
||||||
if (!isEpicboxConnected) {
|
if (!isEpicboxConnected) {
|
||||||
throw Exception("Failed to send TX : Unable to reach epicbox server");
|
throw Exception("Failed to send TX : Unable to reach epicbox server");
|
||||||
}
|
}
|
||||||
|
@ -934,7 +921,6 @@ class EpiccashWallet extends Bip39Wallet {
|
||||||
.findAll();
|
.findAll();
|
||||||
final myAddressesSet = myAddresses.toSet();
|
final myAddressesSet = myAddresses.toSet();
|
||||||
|
|
||||||
|
|
||||||
final transactions = await epiccash.LibEpiccash.getTransactions(
|
final transactions = await epiccash.LibEpiccash.getTransactions(
|
||||||
wallet: wallet!,
|
wallet: wallet!,
|
||||||
refreshFromNode: refreshFromNode,
|
refreshFromNode: refreshFromNode,
|
||||||
|
|
24
pubspec.lock
24
pubspec.lock
|
@ -1970,6 +1970,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.1.0"
|
||||||
|
web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: web
|
||||||
|
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.5.1"
|
||||||
web3dart:
|
web3dart:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -1979,13 +1987,13 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.6.1"
|
version: "2.6.1"
|
||||||
web_socket_channel:
|
web_socket_channel:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: web_socket_channel
|
name: web_socket_channel
|
||||||
sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b
|
sha256: "58c6666b342a38816b2e7e50ed0f1e261959630becd4c879c4f26bfa14aa5a42"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.0"
|
version: "2.4.5"
|
||||||
webdriver:
|
webdriver:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -2002,14 +2010,6 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.1"
|
version: "1.2.1"
|
||||||
websocket_universal:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: websocket_universal
|
|
||||||
sha256: "681e3050bd70b9c94617394f87a021746d24d4b3c8302be8c6b0b2a3e4209d7f"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "0.5.2"
|
|
||||||
win32:
|
win32:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -2076,5 +2076,5 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=3.2.0 <4.0.0"
|
dart: ">=3.3.0 <4.0.0"
|
||||||
flutter: ">=3.16.0"
|
flutter: ">=3.16.0"
|
||||||
|
|
|
@ -22,7 +22,7 @@ dependencies:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
ffi: ^2.0.1
|
ffi: ^2.0.1
|
||||||
mutex: ^3.0.0
|
mutex: ^3.0.0
|
||||||
websocket_universal: ^0.5.1
|
web_socket_channel: ^2.4.5
|
||||||
|
|
||||||
lelantus:
|
lelantus:
|
||||||
path: ./crypto_plugins/flutter_liblelantus
|
path: ./crypto_plugins/flutter_liblelantus
|
||||||
|
|
Loading…
Reference in a new issue