mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-21 06:18:42 +02:00
Merge redesign part 4.
This commit is contained in:
@@ -6,6 +6,16 @@ import 'package:cake_wallet/bitcoin/script_hash.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
class UriParseException implements Exception {
|
||||
UriParseException(this.uri);
|
||||
|
||||
final String uri;
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'Cannot parse host and port from uri. Invalid uri format. Uri: $uri';
|
||||
}
|
||||
|
||||
String jsonrpcparams(List<Object> params) {
|
||||
final _params = params?.map((val) => '"${val.toString()}"')?.join(',');
|
||||
return '[$_params]';
|
||||
@@ -40,9 +50,14 @@ class ElectrumClient {
|
||||
Timer _aliveTimer;
|
||||
|
||||
Future<void> connectToUri(String uri) async {
|
||||
final _uri = Uri.parse(uri);
|
||||
final host = _uri.scheme;
|
||||
final port = int.parse(_uri.path);
|
||||
final splittedUri = uri.split(':');
|
||||
|
||||
if (splittedUri.length != 2) {
|
||||
throw UriParseException(uri);
|
||||
}
|
||||
|
||||
final host = splittedUri.first;
|
||||
final port = int.parse(splittedUri.last);
|
||||
await connect(host: host, port: port);
|
||||
}
|
||||
|
||||
@@ -51,7 +66,8 @@ class ElectrumClient {
|
||||
await socket?.close();
|
||||
} catch (_) {}
|
||||
|
||||
socket = await SecureSocket.connect(host, port, timeout: connectionTimeout);
|
||||
socket = await SecureSocket.connect(host, port,
|
||||
timeout: connectionTimeout, onBadCertificate: (_) => true);
|
||||
_setIsConnected(true);
|
||||
|
||||
socket.listen((Uint8List event) {
|
||||
|
||||
Reference in New Issue
Block a user