mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-23 07:38:49 +00:00
move dataHandler and errorHandler up in scope
This commit is contained in:
parent
4c12e870b1
commit
73ecbf15d5
1 changed files with 12 additions and 5 deletions
|
@ -17,10 +17,13 @@ class JsonRPC {
|
||||||
final String host;
|
final String host;
|
||||||
final int port;
|
final int port;
|
||||||
final Duration connectionTimeout;
|
final Duration connectionTimeout;
|
||||||
Socket? socket;
|
|
||||||
|
|
||||||
|
Socket? socket;
|
||||||
StreamSubscription<Uint8List>? _subscription;
|
StreamSubscription<Uint8List>? _subscription;
|
||||||
|
|
||||||
|
void Function(List<int>)? _onData;
|
||||||
|
void Function(Object, StackTrace)? _onError;
|
||||||
|
|
||||||
Future<dynamic> request(String jsonRpcRequest) async {
|
Future<dynamic> request(String jsonRpcRequest) async {
|
||||||
final completer = Completer<dynamic>();
|
final completer = Completer<dynamic>();
|
||||||
final List<int> responseData = [];
|
final List<int> responseData = [];
|
||||||
|
@ -49,6 +52,8 @@ class JsonRPC {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onData = dataHandler;
|
||||||
|
|
||||||
void errorHandler(Object error, StackTrace trace) {
|
void errorHandler(Object error, StackTrace trace) {
|
||||||
Logging.instance
|
Logging.instance
|
||||||
.log("JsonRPC errorHandler: $error\n$trace", level: LogLevel.Error);
|
.log("JsonRPC errorHandler: $error\n$trace", level: LogLevel.Error);
|
||||||
|
@ -61,6 +66,8 @@ class JsonRPC {
|
||||||
// TODO do we need to recreate the socket?
|
// TODO do we need to recreate the socket?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onError = errorHandler;
|
||||||
|
|
||||||
void doneHandler() {
|
void doneHandler() {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"JsonRPC doneHandler: not destroying socket ${socket?.address}:${socket?.port}",
|
"JsonRPC doneHandler: not destroying socket ${socket?.address}:${socket?.port}",
|
||||||
|
@ -78,8 +85,8 @@ class JsonRPC {
|
||||||
socket ??= await SecureSocket.connect(host, port,
|
socket ??= await SecureSocket.connect(host, port,
|
||||||
timeout: connectionTimeout, onBadCertificate: (_) => true);
|
timeout: connectionTimeout, onBadCertificate: (_) => true);
|
||||||
_subscription ??= socket!.listen(
|
_subscription ??= socket!.listen(
|
||||||
dataHandler,
|
_onData,
|
||||||
onError: errorHandler,
|
onError: _onError,
|
||||||
onDone: doneHandler,
|
onDone: doneHandler,
|
||||||
cancelOnError: true,
|
cancelOnError: true,
|
||||||
);
|
);
|
||||||
|
@ -90,8 +97,8 @@ class JsonRPC {
|
||||||
timeout: connectionTimeout,
|
timeout: connectionTimeout,
|
||||||
);
|
);
|
||||||
_subscription ??= socket!.listen(
|
_subscription ??= socket!.listen(
|
||||||
dataHandler,
|
_onData,
|
||||||
onError: errorHandler,
|
onError: _onError,
|
||||||
onDone: doneHandler,
|
onDone: doneHandler,
|
||||||
cancelOnError: true,
|
cancelOnError: true,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue