Merge pull request #563 from cypherstack/persistence

Persistent socket connections when possible
This commit is contained in:
julian-CStack 2023-05-29 17:14:04 -06:00 committed by GitHub
commit 6fcabcaed3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 619 additions and 685 deletions

View file

@ -132,13 +132,12 @@ class ElectrumX {
final response = await _rpcClient!.request(jsonRequestString); final response = await _rpcClient!.request(jsonRequestString);
print("================================================="); if (response.exception != null) {
print("TYPE: ${response.runtimeType}"); throw response.exception!;
print("RESPONSE: $response"); }
print("=================================================");
if (response["error"] != null) { if (response.data["error"] != null) {
if (response["error"] if (response.data["error"]
.toString() .toString()
.contains("No such mempool or blockchain transaction")) { .contains("No such mempool or blockchain transaction")) {
throw NoSuchTransactionException( throw NoSuchTransactionException(
@ -148,11 +147,15 @@ class ElectrumX {
} }
throw Exception( throw Exception(
"JSONRPC response \ncommand: $command \nargs: $args \nerror: $response"); "JSONRPC response\n"
" command: $command\n"
" args: $args\n"
" error: $response.data",
);
} }
currentFailoverIndex = -1; currentFailoverIndex = -1;
return response; return response.data;
} on WifiOnlyException { } on WifiOnlyException {
rethrow; rethrow;
} on SocketException { } on SocketException {
@ -233,7 +236,13 @@ class ElectrumX {
// Logging.instance.log("batch request: $request"); // Logging.instance.log("batch request: $request");
// send batch request // send batch request
final response = (await _rpcClient!.request(request)) as List<dynamic>; final jsonRpcResponse = (await _rpcClient!.request(request));
if (jsonRpcResponse.exception != null) {
throw jsonRpcResponse.exception!;
}
final response = jsonRpcResponse.data as List;
// check for errors, format and throw if there are any // check for errors, format and throw if there are any
final List<String> errors = []; final List<String> errors = [];

View file

@ -1,12 +1,12 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:mutex/mutex.dart'; import 'package:mutex/mutex.dart';
import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/logger.dart';
// hacky fix to receive large jsonrpc responses // Json RPC class to handle connecting to electrumx servers
class JsonRPC { class JsonRPC {
JsonRPC({ JsonRPC({
required this.host, required this.host,
@ -25,90 +25,60 @@ class JsonRPC {
StreamSubscription<Uint8List>? _subscription; StreamSubscription<Uint8List>? _subscription;
void _dataHandler(List<int> data) { void _dataHandler(List<int> data) {
if (_requestQueue.isEmpty) { _requestQueue.nextIncompleteReq.then((req) {
// probably just return although this case should never actually hit if (req != null) {
return;
}
final req = _requestQueue.next;
req.appendDataAndCheckIfComplete(data); req.appendDataAndCheckIfComplete(data);
if (req.isComplete) { if (req.isComplete) {
_onReqCompleted(req); _onReqCompleted(req);
} }
} else {
Logging.instance.log(
"_dataHandler found a null req!",
level: LogLevel.Warning,
);
}
});
} }
void _errorHandler(Object error, StackTrace trace) { void _errorHandler(Object error, StackTrace trace) {
Logging.instance.log( _requestQueue.nextIncompleteReq.then((req) {
"JsonRPC errorHandler: $error\n$trace", if (req != null) {
level: LogLevel.Error,
);
final req = _requestQueue.next;
req.completer.completeError(error, trace); req.completer.completeError(error, trace);
_onReqCompleted(req); _onReqCompleted(req);
} }
});
}
void _doneHandler() { void _doneHandler() {
Logging.instance.log( disconnect(reason: "JsonRPC _doneHandler() called");
"JsonRPC doneHandler: "
"connection closed to $host:$port, destroying socket",
level: LogLevel.Info,
);
if (_requestQueue.isNotEmpty) {
Logging.instance.log(
"JsonRPC doneHandler: queue not empty but connection closed, "
"completing pending requests with errors",
level: LogLevel.Error,
);
for (final req in _requestQueue.queue) {
if (!req.isComplete) {
try {
throw Exception(
"JsonRPC doneHandler: socket closed "
"before request could complete",
);
} catch (e, s) {
req.completer.completeError(e, s);
}
}
}
_requestQueue.clear();
}
disconnect();
} }
void _onReqCompleted(_JsonRPCRequest req) { void _onReqCompleted(_JsonRPCRequest req) {
_requestQueue.remove(req); _requestQueue.remove(req).then((_) {
if (_requestQueue.isNotEmpty) { // attempt to send next request
_sendNextAvailableRequest(); _sendNextAvailableRequest();
} });
} }
void _sendNextAvailableRequest() { void _sendNextAvailableRequest() {
if (_requestQueue.isEmpty) { _requestQueue.nextIncompleteReq.then((req) {
// TODO handle properly if (req != null) {
throw Exception("JSON RPC queue empty"); // \r\n required by electrumx server
}
final req = _requestQueue.next;
_socket!.write('${req.jsonRequest}\r\n'); _socket!.write('${req.jsonRequest}\r\n');
req.initiateTimeout(const Duration(seconds: 10)); // TODO different timeout length?
// Logging.instance.log( req.initiateTimeout(
// "JsonRPC request: wrote request ${req.jsonRequest} " const Duration(seconds: 10),
// "to socket $host:$port", onTimedOut: () {
// level: LogLevel.Info, _requestQueue.remove(req);
// ); },
);
}
});
} }
Future<dynamic> request(String jsonRpcRequest) async { Future<JsonRPCResponse> request(String jsonRpcRequest) async {
// todo: handle this better?
// Do we need to check the subscription, too?
await _requestMutex.protect(() async { await _requestMutex.protect(() async {
if (_socket == null) { if (_socket == null) {
Logging.instance.log( Logging.instance.log(
@ -121,51 +91,69 @@ class JsonRPC {
final req = _JsonRPCRequest( final req = _JsonRPCRequest(
jsonRequest: jsonRpcRequest, jsonRequest: jsonRpcRequest,
completer: Completer<dynamic>(), completer: Completer<JsonRPCResponse>(),
); );
_requestQueue.add(req); final future = req.completer.future.onError(
(error, stackTrace) async {
await disconnect(
reason: "return req.completer.future.onError: $error\n$stackTrace",
);
return JsonRPCResponse(
exception: error is Exception
? error
: Exception(
"req.completer.future.onError: $error\n$stackTrace",
),
);
},
);
// if this is the only/first request then send it right away // if this is the only/first request then send it right away
if (_requestQueue.length == 1) { await _requestQueue.add(
_sendNextAvailableRequest(); req,
} else { onInitialRequestAdded: _sendNextAvailableRequest,
// Logging.instance.log(
// "JsonRPC request: queued request $jsonRpcRequest "
// "to socket $host:$port",
// level: LogLevel.Info,
// );
}
return req.completer.future.onError(
(error, stackTrace) =>
Exception("return req.completer.future.onError: $error"),
); );
return future;
} }
void disconnect() { Future<void> disconnect({required String reason}) async {
// TODO: maybe clear req queue here and wrap in mutex? await _requestMutex.protect(() async {
_subscription?.cancel().then((_) => _subscription = null); await _subscription?.cancel();
_subscription = null;
_socket?.destroy(); _socket?.destroy();
_socket = null; _socket = null;
// clean up remaining queue
await _requestQueue.completeRemainingWithError(
"JsonRPC disconnect() called with reason: \"$reason\"",
);
});
} }
Future<void> connect() async { Future<void> connect() async {
if (_socket != null) {
throw Exception(
"JsonRPC attempted to connect to an already existing socket!",
);
}
if (useSSL) { if (useSSL) {
_socket ??= await SecureSocket.connect( _socket = await SecureSocket.connect(
host, host,
port, port,
timeout: connectionTimeout, timeout: connectionTimeout,
onBadCertificate: (_) => true, onBadCertificate: (_) => true,
); // TODO do not automatically trust bad certificates ); // TODO do not automatically trust bad certificates
} else { } else {
_socket ??= await Socket.connect( _socket = await Socket.connect(
host, host,
port, port,
timeout: connectionTimeout, timeout: connectionTimeout,
); );
} }
await _subscription?.cancel();
_subscription = _socket!.listen( _subscription = _socket!.listen(
_dataHandler, _dataHandler,
onError: _errorHandler, onError: _errorHandler,
@ -176,36 +164,85 @@ class JsonRPC {
} }
class _JsonRPCRequestQueue { class _JsonRPCRequestQueue {
final _lock = Mutex();
final List<_JsonRPCRequest> _rq = []; final List<_JsonRPCRequest> _rq = [];
void add(_JsonRPCRequest req) => _rq.add(req); Future<void> add(
_JsonRPCRequest req, {
VoidCallback? onInitialRequestAdded,
}) async {
return await _lock.protect(() async {
_rq.add(req);
if (_rq.length == 1) {
onInitialRequestAdded?.call();
}
});
}
bool remove(_JsonRPCRequest req) => _rq.remove(req); Future<bool> remove(_JsonRPCRequest req) async {
return await _lock.protect(() async {
final result = _rq.remove(req);
return result;
});
}
void clear() => _rq.clear(); Future<_JsonRPCRequest?> get nextIncompleteReq async {
return await _lock.protect(() async {
int removeCount = 0;
_JsonRPCRequest? returnValue;
for (final req in _rq) {
if (req.isComplete) {
removeCount++;
} else {
returnValue = req;
break;
}
}
bool get isEmpty => _rq.isEmpty; _rq.removeRange(0, removeCount);
bool get isNotEmpty => _rq.isNotEmpty;
int get length => _rq.length; return returnValue;
_JsonRPCRequest get next => _rq.first; });
List<_JsonRPCRequest> get queue => _rq.toList(growable: false); }
Future<void> completeRemainingWithError(
String error, {
StackTrace? stackTrace,
}) async {
await _lock.protect(() async {
for (final req in _rq) {
if (!req.isComplete) {
req.completer.completeError(Exception(error), stackTrace);
}
}
_rq.clear();
});
}
Future<bool> get isEmpty async {
return await _lock.protect(() async {
return _rq.isEmpty;
});
}
} }
class _JsonRPCRequest { class _JsonRPCRequest {
// 0x0A is newline
// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-basics.html
static const int separatorByte = 0x0A;
final String jsonRequest; final String jsonRequest;
final Completer<dynamic> completer; final Completer<JsonRPCResponse> completer;
final List<int> _responseData = []; final List<int> _responseData = [];
_JsonRPCRequest({required this.jsonRequest, required this.completer}); _JsonRPCRequest({required this.jsonRequest, required this.completer});
void appendDataAndCheckIfComplete(List<int> data) { void appendDataAndCheckIfComplete(List<int> data) {
_responseData.addAll(data); _responseData.addAll(data);
// 0x0A is newline if (data.last == separatorByte) {
// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-basics.html
if (data.last == 0x0A) {
try { try {
final response = json.decode(String.fromCharCodes(_responseData)); final response = json.decode(String.fromCharCodes(_responseData));
completer.complete(response); completer.complete(JsonRPCResponse(data: response));
} catch (e, s) { } catch (e, s) {
Logging.instance.log( Logging.instance.log(
"JsonRPC json.decode: $e\n$s", "JsonRPC json.decode: $e\n$s",
@ -216,13 +253,17 @@ class _JsonRPCRequest {
} }
} }
void initiateTimeout(Duration timeout) { void initiateTimeout(
Duration timeout, {
VoidCallback? onTimedOut,
}) {
Future<void>.delayed(timeout).then((_) { Future<void>.delayed(timeout).then((_) {
if (!isComplete) { if (!isComplete) {
try { try {
throw Exception("_JsonRPCRequest timed out: $jsonRequest"); throw Exception("_JsonRPCRequest timed out: $jsonRequest");
} catch (e, s) { } catch (e, s) {
completer.completeError(e, s); completer.completeError(e, s);
onTimedOut?.call();
} }
} }
}); });
@ -230,3 +271,10 @@ class _JsonRPCRequest {
bool get isComplete => completer.isCompleted; bool get isComplete => completer.isCompleted;
} }
class JsonRPCResponse {
final dynamic data;
final Exception? exception;
JsonRPCResponse({this.data, this.exception});
}

View file

@ -1,261 +0,0 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:mutex/mutex.dart';
import 'package:stackwallet/utilities/logger.dart';
// hacky fix to receive large jsonrpc responses
class JsonRPC {
JsonRPC({
required this.host,
required this.port,
this.useSSL = false,
this.connectionTimeout = const Duration(seconds: 60),
});
final bool useSSL;
final String host;
final int port;
final Duration connectionTimeout;
final _requestMutex = Mutex();
final _JsonRPCRequestQueue _requestQueue = _JsonRPCRequestQueue();
Socket? _socket;
StreamSubscription<Uint8List>? _subscription;
void _dataHandler(List<int> data) {
_requestQueue.nextIncompleteReq.then((req) {
if (req != null) {
req.appendDataAndCheckIfComplete(data);
if (req.isComplete) {
_onReqCompleted(req);
}
} else {
Logging.instance.log(
"_dataHandler found a null req!",
level: LogLevel.Warning,
);
}
});
}
void _errorHandler(Object error, StackTrace trace) {
_requestQueue.nextIncompleteReq.then((req) {
if (req != null) {
req.completer.completeError(error, trace);
_onReqCompleted(req);
} else {
Logging.instance.log(
"_errorHandler found a null req!",
level: LogLevel.Warning,
);
}
});
}
void _doneHandler() {
Logging.instance.log(
"JsonRPC doneHandler: "
"connection closed to $host:$port, destroying socket",
level: LogLevel.Info,
);
disconnect(reason: "JsonRPC _doneHandler() called");
}
void _onReqCompleted(_JsonRPCRequest req) {
_requestQueue.remove(req).then((value) {
if (kDebugMode) {
print("Request removed from queue: $value");
}
// attempt to send next request
_sendNextAvailableRequest();
});
}
void _sendNextAvailableRequest() {
_requestQueue.nextIncompleteReq.then((req) {
if (req != null) {
// \r\n required by electrumx server
_socket!.write('${req.jsonRequest}\r\n');
// TODO different timeout length?
req.initiateTimeout(const Duration(seconds: 10));
} else {
Logging.instance.log(
"_sendNextAvailableRequest found a null req!",
level: LogLevel.Warning,
);
}
});
}
// TODO: non dynamic type
Future<dynamic> request(String jsonRpcRequest) async {
await _requestMutex.protect(() async {
if (_socket == null) {
Logging.instance.log(
"JsonRPC request: opening socket $host:$port",
level: LogLevel.Info,
);
await connect();
}
});
final req = _JsonRPCRequest(
jsonRequest: jsonRpcRequest,
completer: Completer<dynamic>(),
);
// if this is the only/first request then send it right away
await _requestQueue.add(
req,
onInitialRequestAdded: _sendNextAvailableRequest,
);
return req.completer.future.onError(
(error, stackTrace) => Exception(
"return req.completer.future.onError: $error",
),
);
}
Future<void> disconnect({String reason = "none"}) async {
await _requestMutex.protect(() async {
await _subscription?.cancel();
_subscription = null;
_socket?.destroy();
_socket = null;
// clean up remaining queue
await _requestQueue.completeRemainingWithError(
"JsonRPC disconnect() called with reason: \"$reason\"",
);
});
}
Future<void> connect() async {
if (_socket != null) {
throw Exception(
"JsonRPC attempted to connect to an already existing socket!",
);
}
if (useSSL) {
_socket = await SecureSocket.connect(
host,
port,
timeout: connectionTimeout,
onBadCertificate: (_) => true,
); // TODO do not automatically trust bad certificates
} else {
_socket = await Socket.connect(
host,
port,
timeout: connectionTimeout,
);
}
_subscription = _socket!.listen(
_dataHandler,
onError: _errorHandler,
onDone: _doneHandler,
cancelOnError: true,
);
}
}
class _JsonRPCRequestQueue {
final m = Mutex();
final List<_JsonRPCRequest> _rq = [];
Future<void> add(
_JsonRPCRequest req, {
VoidCallback? onInitialRequestAdded,
}) async {
return await m.protect(() async {
_rq.add(req);
if (_rq.length == 1) {
onInitialRequestAdded?.call();
}
});
}
Future<bool> remove(_JsonRPCRequest req) async {
return await m.protect(() async => _rq.remove(req));
}
Future<_JsonRPCRequest?> get nextIncompleteReq async {
return await m.protect(() async {
try {
return _rq.firstWhere((e) => !e.isComplete);
} catch (_) {
// no incomplete requests found
return null;
}
});
}
Future<void> completeRemainingWithError(
String error, {
StackTrace? stackTrace,
}) async {
await m.protect(() async {
for (final req in _rq) {
if (!req.isComplete) {
req.completer.completeError(Exception(error), stackTrace);
}
}
_rq.clear();
});
}
Future<bool> get isEmpty async {
return await m.protect(() async {
return _rq.isEmpty;
});
}
}
class _JsonRPCRequest {
final String jsonRequest;
final Completer<dynamic> completer;
final List<int> _responseData = [];
_JsonRPCRequest({required this.jsonRequest, required this.completer});
void appendDataAndCheckIfComplete(List<int> data) {
_responseData.addAll(data);
// 0x0A is newline
// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-basics.html
if (data.last == 0x0A) {
try {
final response = json.decode(String.fromCharCodes(_responseData));
completer.complete(response);
} catch (e, s) {
Logging.instance.log(
"JsonRPC json.decode: $e\n$s",
level: LogLevel.Error,
);
completer.completeError(e, s);
}
}
}
void initiateTimeout(Duration timeout) {
Future<void>.delayed(timeout).then((_) {
if (!isComplete) {
try {
throw Exception("_JsonRPCRequest timed out: $jsonRequest");
} catch (e, s) {
completer.completeError(e, s);
}
}
});
}
bool get isComplete => completer.isCompleted;
}

View file

@ -50,6 +50,10 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
currenciesWithoutSelected.remove(current); currenciesWithoutSelected.remove(current);
currenciesWithoutSelected.insert(0, current); currenciesWithoutSelected.insert(0, current);
ref.read(prefsChangeNotifierProvider).currency = current; ref.read(prefsChangeNotifierProvider).currency = current;
if (ref.read(prefsChangeNotifierProvider).externalCalls) {
ref.read(priceAnd24hChangeNotifierProvider).updatePrice();
}
} }
} }

View file

@ -1201,13 +1201,18 @@ class BitcoinWallet extends CoinServiceAPI
void _periodicPingCheck() async { void _periodicPingCheck() async {
bool hasNetwork = await testNetworkConnection(); bool hasNetwork = await testNetworkConnection();
_isConnected = hasNetwork;
if (_isConnected != hasNetwork) { if (_isConnected != hasNetwork) {
NodeConnectionStatus status = hasNetwork NodeConnectionStatus status = hasNetwork
? NodeConnectionStatus.connected ? NodeConnectionStatus.connected
: NodeConnectionStatus.disconnected; : NodeConnectionStatus.disconnected;
GlobalEventBus.instance GlobalEventBus.instance
.fire(NodeConnectionStatusChangedEvent(status, walletId, coin)); .fire(NodeConnectionStatusChangedEvent(status, walletId, coin));
_isConnected = hasNetwork;
if (hasNetwork) {
unawaited(refresh());
}
} }
} }

View file

@ -1072,13 +1072,18 @@ class BitcoinCashWallet extends CoinServiceAPI
void _periodicPingCheck() async { void _periodicPingCheck() async {
bool hasNetwork = await testNetworkConnection(); bool hasNetwork = await testNetworkConnection();
_isConnected = hasNetwork;
if (_isConnected != hasNetwork) { if (_isConnected != hasNetwork) {
NodeConnectionStatus status = hasNetwork NodeConnectionStatus status = hasNetwork
? NodeConnectionStatus.connected ? NodeConnectionStatus.connected
: NodeConnectionStatus.disconnected; : NodeConnectionStatus.disconnected;
GlobalEventBus.instance GlobalEventBus.instance
.fire(NodeConnectionStatusChangedEvent(status, walletId, coin)); .fire(NodeConnectionStatusChangedEvent(status, walletId, coin));
_isConnected = hasNetwork;
if (hasNetwork) {
unawaited(refresh());
}
} }
} }

View file

@ -1058,13 +1058,18 @@ class DogecoinWallet extends CoinServiceAPI
void _periodicPingCheck() async { void _periodicPingCheck() async {
bool hasNetwork = await testNetworkConnection(); bool hasNetwork = await testNetworkConnection();
_isConnected = hasNetwork;
if (_isConnected != hasNetwork) { if (_isConnected != hasNetwork) {
NodeConnectionStatus status = hasNetwork NodeConnectionStatus status = hasNetwork
? NodeConnectionStatus.connected ? NodeConnectionStatus.connected
: NodeConnectionStatus.disconnected; : NodeConnectionStatus.disconnected;
GlobalEventBus.instance GlobalEventBus.instance
.fire(NodeConnectionStatusChangedEvent(status, walletId, coin)); .fire(NodeConnectionStatusChangedEvent(status, walletId, coin));
_isConnected = hasNetwork;
if (hasNetwork) {
unawaited(refresh());
}
} }
} }

View file

@ -2680,13 +2680,18 @@ class ECashWallet extends CoinServiceAPI
void _periodicPingCheck() async { void _periodicPingCheck() async {
bool hasNetwork = await testNetworkConnection(); bool hasNetwork = await testNetworkConnection();
_isConnected = hasNetwork;
if (_isConnected != hasNetwork) { if (_isConnected != hasNetwork) {
NodeConnectionStatus status = hasNetwork NodeConnectionStatus status = hasNetwork
? NodeConnectionStatus.connected ? NodeConnectionStatus.connected
: NodeConnectionStatus.disconnected; : NodeConnectionStatus.disconnected;
GlobalEventBus.instance GlobalEventBus.instance
.fire(NodeConnectionStatusChangedEvent(status, walletId, coin)); .fire(NodeConnectionStatusChangedEvent(status, walletId, coin));
_isConnected = hasNetwork;
if (hasNetwork) {
unawaited(refresh());
}
} }
} }

View file

@ -1616,13 +1616,18 @@ class EpicCashWallet extends CoinServiceAPI
void _periodicPingCheck() async { void _periodicPingCheck() async {
bool hasNetwork = await testNetworkConnection(); bool hasNetwork = await testNetworkConnection();
_isConnected = hasNetwork;
if (_isConnected != hasNetwork) { if (_isConnected != hasNetwork) {
NodeConnectionStatus status = hasNetwork NodeConnectionStatus status = hasNetwork
? NodeConnectionStatus.connected ? NodeConnectionStatus.connected
: NodeConnectionStatus.disconnected; : NodeConnectionStatus.disconnected;
GlobalEventBus.instance GlobalEventBus.instance
.fire(NodeConnectionStatusChangedEvent(status, walletId, coin)); .fire(NodeConnectionStatusChangedEvent(status, walletId, coin));
_isConnected = hasNetwork;
if (hasNetwork) {
unawaited(refresh());
}
} }
} }

View file

@ -987,13 +987,18 @@ class FiroWallet extends CoinServiceAPI
void _periodicPingCheck() async { void _periodicPingCheck() async {
bool hasNetwork = await testNetworkConnection(); bool hasNetwork = await testNetworkConnection();
_isConnected = hasNetwork;
if (_isConnected != hasNetwork) { if (_isConnected != hasNetwork) {
NodeConnectionStatus status = hasNetwork NodeConnectionStatus status = hasNetwork
? NodeConnectionStatus.connected ? NodeConnectionStatus.connected
: NodeConnectionStatus.disconnected; : NodeConnectionStatus.disconnected;
GlobalEventBus.instance GlobalEventBus.instance
.fire(NodeConnectionStatusChangedEvent(status, walletId, coin)); .fire(NodeConnectionStatusChangedEvent(status, walletId, coin));
_isConnected = hasNetwork;
if (hasNetwork) {
unawaited(refresh());
}
} }
} }

View file

@ -1189,13 +1189,18 @@ class LitecoinWallet extends CoinServiceAPI
void _periodicPingCheck() async { void _periodicPingCheck() async {
bool hasNetwork = await testNetworkConnection(); bool hasNetwork = await testNetworkConnection();
_isConnected = hasNetwork;
if (_isConnected != hasNetwork) { if (_isConnected != hasNetwork) {
NodeConnectionStatus status = hasNetwork NodeConnectionStatus status = hasNetwork
? NodeConnectionStatus.connected ? NodeConnectionStatus.connected
: NodeConnectionStatus.disconnected; : NodeConnectionStatus.disconnected;
GlobalEventBus.instance GlobalEventBus.instance
.fire(NodeConnectionStatusChangedEvent(status, walletId, coin)); .fire(NodeConnectionStatusChangedEvent(status, walletId, coin));
_isConnected = hasNetwork;
if (hasNetwork) {
unawaited(refresh());
}
} }
} }

View file

@ -1179,13 +1179,18 @@ class NamecoinWallet extends CoinServiceAPI
void _periodicPingCheck() async { void _periodicPingCheck() async {
bool hasNetwork = await testNetworkConnection(); bool hasNetwork = await testNetworkConnection();
_isConnected = hasNetwork;
if (_isConnected != hasNetwork) { if (_isConnected != hasNetwork) {
NodeConnectionStatus status = hasNetwork NodeConnectionStatus status = hasNetwork
? NodeConnectionStatus.connected ? NodeConnectionStatus.connected
: NodeConnectionStatus.disconnected; : NodeConnectionStatus.disconnected;
GlobalEventBus.instance GlobalEventBus.instance
.fire(NodeConnectionStatusChangedEvent(status, walletId, coin)); .fire(NodeConnectionStatusChangedEvent(status, walletId, coin));
_isConnected = hasNetwork;
if (hasNetwork) {
unawaited(refresh());
}
} }
} }

View file

@ -1106,13 +1106,18 @@ class ParticlWallet extends CoinServiceAPI
void _periodicPingCheck() async { void _periodicPingCheck() async {
bool hasNetwork = await testNetworkConnection(); bool hasNetwork = await testNetworkConnection();
_isConnected = hasNetwork;
if (_isConnected != hasNetwork) { if (_isConnected != hasNetwork) {
NodeConnectionStatus status = hasNetwork NodeConnectionStatus status = hasNetwork
? NodeConnectionStatus.connected ? NodeConnectionStatus.connected
: NodeConnectionStatus.disconnected; : NodeConnectionStatus.disconnected;
GlobalEventBus.instance GlobalEventBus.instance
.fire(NodeConnectionStatusChangedEvent(status, walletId, coin)); .fire(NodeConnectionStatusChangedEvent(status, walletId, coin));
_isConnected = hasNetwork;
if (hasNetwork) {
unawaited(refresh());
}
} }
} }

View file

@ -57,16 +57,18 @@ void main() {
const jsonArgs = '["",true]'; const jsonArgs = '["",true]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"error": { "error": {
"code": 1, "code": 1,
"message": "None should be a transaction hash", "message": "None should be a transaction hash",
}, },
"id": "some requestId", "id": "some requestId",
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -93,13 +95,15 @@ void main() {
const jsonArgs = '[]'; const jsonArgs = '[]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": {"height": 520481, "hex": "some block hex string"}, "result": {"height": 520481, "hex": "some block hex string"},
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -126,7 +130,9 @@ void main() {
const jsonArgs = '[]'; const jsonArgs = '[]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -153,9 +159,15 @@ void main() {
const jsonArgs = '[]'; const jsonArgs = '[]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => {"jsonrpc": "2.0", "result": null, "id": "some requestId"}, (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0",
"result": null,
"id": "some requestId",
}),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -181,7 +193,9 @@ void main() {
const jsonArgs = '[]'; const jsonArgs = '[]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -208,9 +222,11 @@ void main() {
const jsonArgs = '[]'; const jsonArgs = '[]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": { "result": {
"genesis_hash": "genesis_hash":
@ -225,7 +241,7 @@ void main() {
"hash_function": "sha256" "hash_function": "sha256"
}, },
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -263,7 +279,9 @@ void main() {
const jsonArgs = '[]'; const jsonArgs = '[]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -290,13 +308,15 @@ void main() {
const jsonArgs = '["some raw transaction string"]'; const jsonArgs = '["some raw transaction string"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": "the txid of the rawtx", "result": "the txid of the rawtx",
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -323,7 +343,9 @@ void main() {
const jsonArgs = '["some raw transaction string"]'; const jsonArgs = '["some raw transaction string"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -353,16 +375,18 @@ void main() {
const jsonArgs = '["dummy hash"]'; const jsonArgs = '["dummy hash"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": { "result": {
"confirmed": 103873966, "confirmed": 103873966,
"unconfirmed": 23684400, "unconfirmed": 23684400,
}, },
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -389,7 +413,9 @@ void main() {
const jsonArgs = '["dummy hash"]'; const jsonArgs = '["dummy hash"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -418,9 +444,11 @@ void main() {
const jsonArgs = '["dummy hash"]'; const jsonArgs = '["dummy hash"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": [ "result": [
{ {
@ -435,7 +463,7 @@ void main() {
} }
], ],
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -473,7 +501,9 @@ void main() {
const jsonArgs = '["dummy hash"]'; const jsonArgs = '["dummy hash"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -502,9 +532,11 @@ void main() {
const jsonArgs = '["dummy hash"]'; const jsonArgs = '["dummy hash"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": [ "result": [
{ {
@ -523,7 +555,7 @@ void main() {
} }
], ],
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -565,7 +597,9 @@ void main() {
const jsonArgs = '["dummy hash"]'; const jsonArgs = '["dummy hash"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -594,13 +628,15 @@ void main() {
const jsonArgs = '["${SampleGetTransactionData.txHash0}",true]'; const jsonArgs = '["${SampleGetTransactionData.txHash0}",true]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": SampleGetTransactionData.txData0, "result": SampleGetTransactionData.txData0,
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -629,7 +665,9 @@ void main() {
const jsonArgs = '["${SampleGetTransactionData.txHash0}",true]'; const jsonArgs = '["${SampleGetTransactionData.txHash0}",true]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -659,13 +697,15 @@ void main() {
const jsonArgs = '["1",""]'; const jsonArgs = '["1",""]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": GetAnonymitySetSampleData.data, "result": GetAnonymitySetSampleData.data,
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -692,7 +732,9 @@ void main() {
const jsonArgs = '["1",""]'; const jsonArgs = '["1",""]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -721,13 +763,15 @@ void main() {
const jsonArgs = '["some mints"]'; const jsonArgs = '["some mints"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": "mint meta data", "result": "mint meta data",
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -754,7 +798,9 @@ void main() {
const jsonArgs = '["some mints"]'; const jsonArgs = '["some mints"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -783,13 +829,15 @@ void main() {
const jsonArgs = '["0"]'; const jsonArgs = '["0"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": GetUsedSerialsSampleData.serials, "result": GetUsedSerialsSampleData.serials,
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -816,7 +864,9 @@ void main() {
const jsonArgs = '["0"]'; const jsonArgs = '["0"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -845,9 +895,15 @@ void main() {
const jsonArgs = '[]'; const jsonArgs = '[]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => {"jsonrpc": "2.0", "result": 1, "id": "some requestId"}, (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0",
"result": 1,
"id": "some requestId",
}),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -873,7 +929,9 @@ void main() {
const jsonArgs = '[]'; const jsonArgs = '[]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -886,7 +944,10 @@ void main() {
prefs: mockPrefs, prefs: mockPrefs,
failovers: []); failovers: []);
expect(() => client.getLatestCoinId(requestID: "some requestId"), expect(
() => client.getLatestCoinId(
requestID: "some requestId",
),
throwsA(isA<Exception>())); throwsA(isA<Exception>()));
verify(mockPrefs.wifiOnly).called(1); verify(mockPrefs.wifiOnly).called(1);
verifyNoMoreInteractions(mockPrefs); verifyNoMoreInteractions(mockPrefs);
@ -900,13 +961,15 @@ void main() {
const jsonArgs = '["1",""]'; const jsonArgs = '["1",""]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": GetAnonymitySetSampleData.data, "result": GetAnonymitySetSampleData.data,
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -933,7 +996,9 @@ void main() {
const jsonArgs = '["1",""]'; const jsonArgs = '["1",""]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -947,8 +1012,10 @@ void main() {
failovers: []); failovers: []);
expect( expect(
() => () => client.getAnonymitySet(
client.getAnonymitySet(groupId: "1", requestID: "some requestId"), groupId: "1",
requestID: "some requestId",
),
throwsA(isA<Exception>())); throwsA(isA<Exception>()));
verify(mockPrefs.wifiOnly).called(1); verify(mockPrefs.wifiOnly).called(1);
verifyNoMoreInteractions(mockPrefs); verifyNoMoreInteractions(mockPrefs);
@ -962,13 +1029,15 @@ void main() {
const jsonArgs = '["some mints"]'; const jsonArgs = '["some mints"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": "mint meta data", "result": "mint meta data",
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -995,7 +1064,9 @@ void main() {
const jsonArgs = '["some mints"]'; const jsonArgs = '["some mints"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -1010,7 +1081,9 @@ void main() {
expect( expect(
() => client.getMintData( () => client.getMintData(
mints: "some mints", requestID: "some requestId"), mints: "some mints",
requestID: "some requestId",
),
throwsA(isA<Exception>())); throwsA(isA<Exception>()));
verify(mockPrefs.wifiOnly).called(1); verify(mockPrefs.wifiOnly).called(1);
verifyNoMoreInteractions(mockPrefs); verifyNoMoreInteractions(mockPrefs);
@ -1024,13 +1097,15 @@ void main() {
const jsonArgs = '["0"]'; const jsonArgs = '["0"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": GetUsedSerialsSampleData.serials, "result": GetUsedSerialsSampleData.serials,
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -1057,7 +1132,9 @@ void main() {
const jsonArgs = '["0"]'; const jsonArgs = '["0"]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -1086,9 +1163,15 @@ void main() {
const jsonArgs = '[]'; const jsonArgs = '[]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => {"jsonrpc": "2.0", "result": 1, "id": "some requestId"}, (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0",
"result": 1,
"id": "some requestId",
}),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -1114,7 +1197,9 @@ void main() {
const jsonArgs = '[]'; const jsonArgs = '[]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -1141,15 +1226,17 @@ void main() {
const jsonArgs = '[]'; const jsonArgs = '[]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenAnswer( ).thenAnswer(
(_) async => { (_) async => JsonRPCResponse(data: {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"result": { "result": {
"rate": 1000, "rate": 1000,
}, },
"id": "some requestId" "id": "some requestId"
}, }),
); );
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();
@ -1175,7 +1262,9 @@ void main() {
const jsonArgs = '[]'; const jsonArgs = '[]';
when( when(
mockClient.request( mockClient.request(
'{"jsonrpc": "2.0", "id": "some requestId","method": "$command","params": $jsonArgs}'), '{"jsonrpc": "2.0", "id": "some requestId",'
'"method": "$command","params": $jsonArgs}',
),
).thenThrow(Exception()); ).thenThrow(Exception());
final mockPrefs = MockPrefs(); final mockPrefs = MockPrefs();

View file

@ -33,6 +33,17 @@ class _FakeDuration_0 extends _i1.SmartFake implements Duration {
); );
} }
class _FakeJsonRPCResponse_1 extends _i1.SmartFake
implements _i2.JsonRPCResponse {
_FakeJsonRPCResponse_1(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
/// A class which mocks [JsonRPC]. /// A class which mocks [JsonRPC].
/// ///
/// See the documentation for Mockito's code generation for more information. /// See the documentation for Mockito's code generation for more information.
@ -65,21 +76,31 @@ class MockJsonRPC extends _i1.Mock implements _i2.JsonRPC {
), ),
) as Duration); ) as Duration);
@override @override
_i3.Future<dynamic> request(String? jsonRpcRequest) => (super.noSuchMethod( _i3.Future<_i2.JsonRPCResponse> request(String? jsonRpcRequest) =>
(super.noSuchMethod(
Invocation.method( Invocation.method(
#request, #request,
[jsonRpcRequest], [jsonRpcRequest],
), ),
returnValue: _i3.Future<dynamic>.value(), returnValue:
) as _i3.Future<dynamic>); _i3.Future<_i2.JsonRPCResponse>.value(_FakeJsonRPCResponse_1(
this,
Invocation.method(
#request,
[jsonRpcRequest],
),
)),
) as _i3.Future<_i2.JsonRPCResponse>);
@override @override
void disconnect() => super.noSuchMethod( _i3.Future<void> disconnect({required String? reason}) => (super.noSuchMethod(
Invocation.method( Invocation.method(
#disconnect, #disconnect,
[], [],
{#reason: reason},
), ),
returnValueForMissingStub: null, returnValue: _i3.Future<void>.value(),
); returnValueForMissingStub: _i3.Future<void>.value(),
) as _i3.Future<void>);
@override @override
_i3.Future<void> connect() => (super.noSuchMethod( _i3.Future<void> connect() => (super.noSuchMethod(
Invocation.method( Invocation.method(

View file

@ -17,7 +17,7 @@ void main() {
'{"jsonrpc": "2.0", "id": "some id","method": "server.ping","params": []}'; '{"jsonrpc": "2.0", "id": "some id","method": "server.ping","params": []}';
final result = await jsonRPC.request(jsonRequestString); final result = await jsonRPC.request(jsonRequestString);
expect(result, {"jsonrpc": "2.0", "result": null, "id": "some id"}); expect(result.data, {"jsonrpc": "2.0", "result": null, "id": "some id"});
}); });
test("JsonRPC.request fails due to SocketException", () async { test("JsonRPC.request fails due to SocketException", () async {

View file

@ -3,24 +3,23 @@
// Do not manually edit this file. // Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes // ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i9; import 'dart:async' as _i8;
import 'dart:ui' as _i15; import 'dart:ui' as _i14;
import 'package:local_auth/auth_strings.dart' as _i12; import 'package:local_auth/auth_strings.dart' as _i11;
import 'package:local_auth/local_auth.dart' as _i11; import 'package:local_auth/local_auth.dart' as _i10;
import 'package:mockito/mockito.dart' as _i1; import 'package:mockito/mockito.dart' as _i1;
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart' as _i7; import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart' as _i7;
import 'package:stackwallet/electrumx_rpc/electrumx.dart' as _i8; import 'package:stackwallet/electrumx_rpc/electrumx.dart' as _i2;
import 'package:stackwallet/models/balance.dart' as _i5; import 'package:stackwallet/models/balance.dart' as _i5;
import 'package:stackwallet/models/isar/models/isar_models.dart' as _i17; import 'package:stackwallet/models/isar/models/isar_models.dart' as _i16;
import 'package:stackwallet/models/models.dart' as _i4; import 'package:stackwallet/models/models.dart' as _i4;
import 'package:stackwallet/services/coins/coin_service.dart' as _i3; import 'package:stackwallet/services/coins/coin_service.dart' as _i3;
import 'package:stackwallet/services/coins/manager.dart' as _i16; import 'package:stackwallet/services/coins/manager.dart' as _i15;
import 'package:stackwallet/services/wallets_service.dart' as _i14; import 'package:stackwallet/services/wallets_service.dart' as _i13;
import 'package:stackwallet/utilities/amount/amount.dart' as _i6; import 'package:stackwallet/utilities/amount/amount.dart' as _i6;
import 'package:stackwallet/utilities/biometrics.dart' as _i13; import 'package:stackwallet/utilities/biometrics.dart' as _i12;
import 'package:stackwallet/utilities/enums/coin_enum.dart' as _i10; import 'package:stackwallet/utilities/enums/coin_enum.dart' as _i9;
import 'package:stackwallet/utilities/prefs.dart' as _i2;
// ignore_for_file: type=lint // ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_redundant_argument_values
@ -33,8 +32,8 @@ import 'package:stackwallet/utilities/prefs.dart' as _i2;
// ignore_for_file: camel_case_types // ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class // ignore_for_file: subtype_of_sealed_class
class _FakePrefs_0 extends _i1.SmartFake implements _i2.Prefs { class _FakeElectrumX_0 extends _i1.SmartFake implements _i2.ElectrumX {
_FakePrefs_0( _FakeElectrumX_0(
Object parent, Object parent,
Invocation parentInvocation, Invocation parentInvocation,
) : super( ) : super(
@ -93,38 +92,18 @@ class MockCachedElectrumX extends _i1.Mock implements _i7.CachedElectrumX {
} }
@override @override
String get server => (super.noSuchMethod( _i2.ElectrumX get electrumXClient => (super.noSuchMethod(
Invocation.getter(#server), Invocation.getter(#electrumXClient),
returnValue: '', returnValue: _FakeElectrumX_0(
) as String);
@override
int get port => (super.noSuchMethod(
Invocation.getter(#port),
returnValue: 0,
) as int);
@override
bool get useSSL => (super.noSuchMethod(
Invocation.getter(#useSSL),
returnValue: false,
) as bool);
@override
_i2.Prefs get prefs => (super.noSuchMethod(
Invocation.getter(#prefs),
returnValue: _FakePrefs_0(
this, this,
Invocation.getter(#prefs), Invocation.getter(#electrumXClient),
), ),
) as _i2.Prefs); ) as _i2.ElectrumX);
@override @override
List<_i8.ElectrumXNode> get failovers => (super.noSuchMethod( _i8.Future<Map<String, dynamic>> getAnonymitySet({
Invocation.getter(#failovers),
returnValue: <_i8.ElectrumXNode>[],
) as List<_i8.ElectrumXNode>);
@override
_i9.Future<Map<String, dynamic>> getAnonymitySet({
required String? groupId, required String? groupId,
String? blockhash = r'', String? blockhash = r'',
required _i10.Coin? coin, required _i9.Coin? coin,
}) => }) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method( Invocation.method(
@ -137,8 +116,8 @@ class MockCachedElectrumX extends _i1.Mock implements _i7.CachedElectrumX {
}, },
), ),
returnValue: returnValue:
_i9.Future<Map<String, dynamic>>.value(<String, dynamic>{}), _i8.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
) as _i9.Future<Map<String, dynamic>>); ) as _i8.Future<Map<String, dynamic>>);
@override @override
String base64ToHex(String? source) => (super.noSuchMethod( String base64ToHex(String? source) => (super.noSuchMethod(
Invocation.method( Invocation.method(
@ -156,9 +135,9 @@ class MockCachedElectrumX extends _i1.Mock implements _i7.CachedElectrumX {
returnValue: '', returnValue: '',
) as String); ) as String);
@override @override
_i9.Future<Map<String, dynamic>> getTransaction({ _i8.Future<Map<String, dynamic>> getTransaction({
required String? txHash, required String? txHash,
required _i10.Coin? coin, required _i9.Coin? coin,
bool? verbose = true, bool? verbose = true,
}) => }) =>
(super.noSuchMethod( (super.noSuchMethod(
@ -172,11 +151,11 @@ class MockCachedElectrumX extends _i1.Mock implements _i7.CachedElectrumX {
}, },
), ),
returnValue: returnValue:
_i9.Future<Map<String, dynamic>>.value(<String, dynamic>{}), _i8.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
) as _i9.Future<Map<String, dynamic>>); ) as _i8.Future<Map<String, dynamic>>);
@override @override
_i9.Future<List<String>> getUsedCoinSerials({ _i8.Future<List<String>> getUsedCoinSerials({
required _i10.Coin? coin, required _i9.Coin? coin,
int? startNumber = 0, int? startNumber = 0,
}) => }) =>
(super.noSuchMethod( (super.noSuchMethod(
@ -188,43 +167,43 @@ class MockCachedElectrumX extends _i1.Mock implements _i7.CachedElectrumX {
#startNumber: startNumber, #startNumber: startNumber,
}, },
), ),
returnValue: _i9.Future<List<String>>.value(<String>[]), returnValue: _i8.Future<List<String>>.value(<String>[]),
) as _i9.Future<List<String>>); ) as _i8.Future<List<String>>);
@override @override
_i9.Future<void> clearSharedTransactionCache({required _i10.Coin? coin}) => _i8.Future<void> clearSharedTransactionCache({required _i9.Coin? coin}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method( Invocation.method(
#clearSharedTransactionCache, #clearSharedTransactionCache,
[], [],
{#coin: coin}, {#coin: coin},
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
} }
/// A class which mocks [LocalAuthentication]. /// A class which mocks [LocalAuthentication].
/// ///
/// See the documentation for Mockito's code generation for more information. /// See the documentation for Mockito's code generation for more information.
class MockLocalAuthentication extends _i1.Mock class MockLocalAuthentication extends _i1.Mock
implements _i11.LocalAuthentication { implements _i10.LocalAuthentication {
MockLocalAuthentication() { MockLocalAuthentication() {
_i1.throwOnMissingStub(this); _i1.throwOnMissingStub(this);
} }
@override @override
_i9.Future<bool> get canCheckBiometrics => (super.noSuchMethod( _i8.Future<bool> get canCheckBiometrics => (super.noSuchMethod(
Invocation.getter(#canCheckBiometrics), Invocation.getter(#canCheckBiometrics),
returnValue: _i9.Future<bool>.value(false), returnValue: _i8.Future<bool>.value(false),
) as _i9.Future<bool>); ) as _i8.Future<bool>);
@override @override
_i9.Future<bool> authenticateWithBiometrics({ _i8.Future<bool> authenticateWithBiometrics({
required String? localizedReason, required String? localizedReason,
bool? useErrorDialogs = true, bool? useErrorDialogs = true,
bool? stickyAuth = false, bool? stickyAuth = false,
_i12.AndroidAuthMessages? androidAuthStrings = _i11.AndroidAuthMessages? androidAuthStrings =
const _i12.AndroidAuthMessages(), const _i11.AndroidAuthMessages(),
_i12.IOSAuthMessages? iOSAuthStrings = const _i12.IOSAuthMessages(), _i11.IOSAuthMessages? iOSAuthStrings = const _i11.IOSAuthMessages(),
bool? sensitiveTransaction = true, bool? sensitiveTransaction = true,
}) => }) =>
(super.noSuchMethod( (super.noSuchMethod(
@ -240,16 +219,16 @@ class MockLocalAuthentication extends _i1.Mock
#sensitiveTransaction: sensitiveTransaction, #sensitiveTransaction: sensitiveTransaction,
}, },
), ),
returnValue: _i9.Future<bool>.value(false), returnValue: _i8.Future<bool>.value(false),
) as _i9.Future<bool>); ) as _i8.Future<bool>);
@override @override
_i9.Future<bool> authenticate({ _i8.Future<bool> authenticate({
required String? localizedReason, required String? localizedReason,
bool? useErrorDialogs = true, bool? useErrorDialogs = true,
bool? stickyAuth = false, bool? stickyAuth = false,
_i12.AndroidAuthMessages? androidAuthStrings = _i11.AndroidAuthMessages? androidAuthStrings =
const _i12.AndroidAuthMessages(), const _i11.AndroidAuthMessages(),
_i12.IOSAuthMessages? iOSAuthStrings = const _i12.IOSAuthMessages(), _i11.IOSAuthMessages? iOSAuthStrings = const _i11.IOSAuthMessages(),
bool? sensitiveTransaction = true, bool? sensitiveTransaction = true,
bool? biometricOnly = false, bool? biometricOnly = false,
}) => }) =>
@ -267,46 +246,46 @@ class MockLocalAuthentication extends _i1.Mock
#biometricOnly: biometricOnly, #biometricOnly: biometricOnly,
}, },
), ),
returnValue: _i9.Future<bool>.value(false), returnValue: _i8.Future<bool>.value(false),
) as _i9.Future<bool>); ) as _i8.Future<bool>);
@override @override
_i9.Future<bool> stopAuthentication() => (super.noSuchMethod( _i8.Future<bool> stopAuthentication() => (super.noSuchMethod(
Invocation.method( Invocation.method(
#stopAuthentication, #stopAuthentication,
[], [],
), ),
returnValue: _i9.Future<bool>.value(false), returnValue: _i8.Future<bool>.value(false),
) as _i9.Future<bool>); ) as _i8.Future<bool>);
@override @override
_i9.Future<bool> isDeviceSupported() => (super.noSuchMethod( _i8.Future<bool> isDeviceSupported() => (super.noSuchMethod(
Invocation.method( Invocation.method(
#isDeviceSupported, #isDeviceSupported,
[], [],
), ),
returnValue: _i9.Future<bool>.value(false), returnValue: _i8.Future<bool>.value(false),
) as _i9.Future<bool>); ) as _i8.Future<bool>);
@override @override
_i9.Future<List<_i11.BiometricType>> getAvailableBiometrics() => _i8.Future<List<_i10.BiometricType>> getAvailableBiometrics() =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method( Invocation.method(
#getAvailableBiometrics, #getAvailableBiometrics,
[], [],
), ),
returnValue: returnValue:
_i9.Future<List<_i11.BiometricType>>.value(<_i11.BiometricType>[]), _i8.Future<List<_i10.BiometricType>>.value(<_i10.BiometricType>[]),
) as _i9.Future<List<_i11.BiometricType>>); ) as _i8.Future<List<_i10.BiometricType>>);
} }
/// A class which mocks [Biometrics]. /// A class which mocks [Biometrics].
/// ///
/// See the documentation for Mockito's code generation for more information. /// See the documentation for Mockito's code generation for more information.
class MockBiometrics extends _i1.Mock implements _i13.Biometrics { class MockBiometrics extends _i1.Mock implements _i12.Biometrics {
MockBiometrics() { MockBiometrics() {
_i1.throwOnMissingStub(this); _i1.throwOnMissingStub(this);
} }
@override @override
_i9.Future<bool> authenticate({ _i8.Future<bool> authenticate({
required String? cancelButtonText, required String? cancelButtonText,
required String? localizedReason, required String? localizedReason,
required String? title, required String? title,
@ -321,28 +300,28 @@ class MockBiometrics extends _i1.Mock implements _i13.Biometrics {
#title: title, #title: title,
}, },
), ),
returnValue: _i9.Future<bool>.value(false), returnValue: _i8.Future<bool>.value(false),
) as _i9.Future<bool>); ) as _i8.Future<bool>);
} }
/// A class which mocks [WalletsService]. /// A class which mocks [WalletsService].
/// ///
/// See the documentation for Mockito's code generation for more information. /// See the documentation for Mockito's code generation for more information.
class MockWalletsService extends _i1.Mock implements _i14.WalletsService { class MockWalletsService extends _i1.Mock implements _i13.WalletsService {
@override @override
_i9.Future<Map<String, _i14.WalletInfo>> get walletNames => _i8.Future<Map<String, _i13.WalletInfo>> get walletNames =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.getter(#walletNames), Invocation.getter(#walletNames),
returnValue: _i9.Future<Map<String, _i14.WalletInfo>>.value( returnValue: _i8.Future<Map<String, _i13.WalletInfo>>.value(
<String, _i14.WalletInfo>{}), <String, _i13.WalletInfo>{}),
) as _i9.Future<Map<String, _i14.WalletInfo>>); ) as _i8.Future<Map<String, _i13.WalletInfo>>);
@override @override
bool get hasListeners => (super.noSuchMethod( bool get hasListeners => (super.noSuchMethod(
Invocation.getter(#hasListeners), Invocation.getter(#hasListeners),
returnValue: false, returnValue: false,
) as bool); ) as bool);
@override @override
_i9.Future<bool> renameWallet({ _i8.Future<bool> renameWallet({
required String? from, required String? from,
required String? to, required String? to,
required bool? shouldNotifyListeners, required bool? shouldNotifyListeners,
@ -357,21 +336,21 @@ class MockWalletsService extends _i1.Mock implements _i14.WalletsService {
#shouldNotifyListeners: shouldNotifyListeners, #shouldNotifyListeners: shouldNotifyListeners,
}, },
), ),
returnValue: _i9.Future<bool>.value(false), returnValue: _i8.Future<bool>.value(false),
) as _i9.Future<bool>); ) as _i8.Future<bool>);
@override @override
Map<String, _i14.WalletInfo> fetchWalletsData() => (super.noSuchMethod( Map<String, _i13.WalletInfo> fetchWalletsData() => (super.noSuchMethod(
Invocation.method( Invocation.method(
#fetchWalletsData, #fetchWalletsData,
[], [],
), ),
returnValue: <String, _i14.WalletInfo>{}, returnValue: <String, _i13.WalletInfo>{},
) as Map<String, _i14.WalletInfo>); ) as Map<String, _i13.WalletInfo>);
@override @override
_i9.Future<void> addExistingStackWallet({ _i8.Future<void> addExistingStackWallet({
required String? name, required String? name,
required String? walletId, required String? walletId,
required _i10.Coin? coin, required _i9.Coin? coin,
required bool? shouldNotifyListeners, required bool? shouldNotifyListeners,
}) => }) =>
(super.noSuchMethod( (super.noSuchMethod(
@ -385,13 +364,13 @@ class MockWalletsService extends _i1.Mock implements _i14.WalletsService {
#shouldNotifyListeners: shouldNotifyListeners, #shouldNotifyListeners: shouldNotifyListeners,
}, },
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
_i9.Future<String?> addNewWallet({ _i8.Future<String?> addNewWallet({
required String? name, required String? name,
required _i10.Coin? coin, required _i9.Coin? coin,
required bool? shouldNotifyListeners, required bool? shouldNotifyListeners,
}) => }) =>
(super.noSuchMethod( (super.noSuchMethod(
@ -404,46 +383,46 @@ class MockWalletsService extends _i1.Mock implements _i14.WalletsService {
#shouldNotifyListeners: shouldNotifyListeners, #shouldNotifyListeners: shouldNotifyListeners,
}, },
), ),
returnValue: _i9.Future<String?>.value(), returnValue: _i8.Future<String?>.value(),
) as _i9.Future<String?>); ) as _i8.Future<String?>);
@override @override
_i9.Future<List<String>> getFavoriteWalletIds() => (super.noSuchMethod( _i8.Future<List<String>> getFavoriteWalletIds() => (super.noSuchMethod(
Invocation.method( Invocation.method(
#getFavoriteWalletIds, #getFavoriteWalletIds,
[], [],
), ),
returnValue: _i9.Future<List<String>>.value(<String>[]), returnValue: _i8.Future<List<String>>.value(<String>[]),
) as _i9.Future<List<String>>); ) as _i8.Future<List<String>>);
@override @override
_i9.Future<void> saveFavoriteWalletIds(List<String>? walletIds) => _i8.Future<void> saveFavoriteWalletIds(List<String>? walletIds) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method( Invocation.method(
#saveFavoriteWalletIds, #saveFavoriteWalletIds,
[walletIds], [walletIds],
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
_i9.Future<void> addFavorite(String? walletId) => (super.noSuchMethod( _i8.Future<void> addFavorite(String? walletId) => (super.noSuchMethod(
Invocation.method( Invocation.method(
#addFavorite, #addFavorite,
[walletId], [walletId],
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
_i9.Future<void> removeFavorite(String? walletId) => (super.noSuchMethod( _i8.Future<void> removeFavorite(String? walletId) => (super.noSuchMethod(
Invocation.method( Invocation.method(
#removeFavorite, #removeFavorite,
[walletId], [walletId],
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
_i9.Future<void> moveFavorite({ _i8.Future<void> moveFavorite({
required int? fromIndex, required int? fromIndex,
required int? toIndex, required int? toIndex,
}) => }) =>
@ -456,48 +435,48 @@ class MockWalletsService extends _i1.Mock implements _i14.WalletsService {
#toIndex: toIndex, #toIndex: toIndex,
}, },
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
_i9.Future<bool> checkForDuplicate(String? name) => (super.noSuchMethod( _i8.Future<bool> checkForDuplicate(String? name) => (super.noSuchMethod(
Invocation.method( Invocation.method(
#checkForDuplicate, #checkForDuplicate,
[name], [name],
), ),
returnValue: _i9.Future<bool>.value(false), returnValue: _i8.Future<bool>.value(false),
) as _i9.Future<bool>); ) as _i8.Future<bool>);
@override @override
_i9.Future<String?> getWalletId(String? walletName) => (super.noSuchMethod( _i8.Future<String?> getWalletId(String? walletName) => (super.noSuchMethod(
Invocation.method( Invocation.method(
#getWalletId, #getWalletId,
[walletName], [walletName],
), ),
returnValue: _i9.Future<String?>.value(), returnValue: _i8.Future<String?>.value(),
) as _i9.Future<String?>); ) as _i8.Future<String?>);
@override @override
_i9.Future<bool> isMnemonicVerified({required String? walletId}) => _i8.Future<bool> isMnemonicVerified({required String? walletId}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method( Invocation.method(
#isMnemonicVerified, #isMnemonicVerified,
[], [],
{#walletId: walletId}, {#walletId: walletId},
), ),
returnValue: _i9.Future<bool>.value(false), returnValue: _i8.Future<bool>.value(false),
) as _i9.Future<bool>); ) as _i8.Future<bool>);
@override @override
_i9.Future<void> setMnemonicVerified({required String? walletId}) => _i8.Future<void> setMnemonicVerified({required String? walletId}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method( Invocation.method(
#setMnemonicVerified, #setMnemonicVerified,
[], [],
{#walletId: walletId}, {#walletId: walletId},
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
_i9.Future<int> deleteWallet( _i8.Future<int> deleteWallet(
String? name, String? name,
bool? shouldNotifyListeners, bool? shouldNotifyListeners,
) => ) =>
@ -509,20 +488,20 @@ class MockWalletsService extends _i1.Mock implements _i14.WalletsService {
shouldNotifyListeners, shouldNotifyListeners,
], ],
), ),
returnValue: _i9.Future<int>.value(0), returnValue: _i8.Future<int>.value(0),
) as _i9.Future<int>); ) as _i8.Future<int>);
@override @override
_i9.Future<void> refreshWallets(bool? shouldNotifyListeners) => _i8.Future<void> refreshWallets(bool? shouldNotifyListeners) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method( Invocation.method(
#refreshWallets, #refreshWallets,
[shouldNotifyListeners], [shouldNotifyListeners],
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( void addListener(_i14.VoidCallback? listener) => super.noSuchMethod(
Invocation.method( Invocation.method(
#addListener, #addListener,
[listener], [listener],
@ -530,7 +509,7 @@ class MockWalletsService extends _i1.Mock implements _i14.WalletsService {
returnValueForMissingStub: null, returnValueForMissingStub: null,
); );
@override @override
void removeListener(_i15.VoidCallback? listener) => super.noSuchMethod( void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod(
Invocation.method( Invocation.method(
#removeListener, #removeListener,
[listener], [listener],
@ -558,7 +537,7 @@ class MockWalletsService extends _i1.Mock implements _i14.WalletsService {
/// A class which mocks [Manager]. /// A class which mocks [Manager].
/// ///
/// See the documentation for Mockito's code generation for more information. /// See the documentation for Mockito's code generation for more information.
class MockManager extends _i1.Mock implements _i16.Manager { class MockManager extends _i1.Mock implements _i15.Manager {
@override @override
bool get isActiveWallet => (super.noSuchMethod( bool get isActiveWallet => (super.noSuchMethod(
Invocation.getter(#isActiveWallet), Invocation.getter(#isActiveWallet),
@ -586,10 +565,10 @@ class MockManager extends _i1.Mock implements _i16.Manager {
returnValue: false, returnValue: false,
) as bool); ) as bool);
@override @override
_i10.Coin get coin => (super.noSuchMethod( _i9.Coin get coin => (super.noSuchMethod(
Invocation.getter(#coin), Invocation.getter(#coin),
returnValue: _i10.Coin.bitcoin, returnValue: _i9.Coin.bitcoin,
) as _i10.Coin); ) as _i9.Coin);
@override @override
bool get isRefreshing => (super.noSuchMethod( bool get isRefreshing => (super.noSuchMethod(
Invocation.getter(#isRefreshing), Invocation.getter(#isRefreshing),
@ -622,23 +601,23 @@ class MockManager extends _i1.Mock implements _i16.Manager {
returnValueForMissingStub: null, returnValueForMissingStub: null,
); );
@override @override
_i9.Future<_i4.FeeObject> get fees => (super.noSuchMethod( _i8.Future<_i4.FeeObject> get fees => (super.noSuchMethod(
Invocation.getter(#fees), Invocation.getter(#fees),
returnValue: _i9.Future<_i4.FeeObject>.value(_FakeFeeObject_2( returnValue: _i8.Future<_i4.FeeObject>.value(_FakeFeeObject_2(
this, this,
Invocation.getter(#fees), Invocation.getter(#fees),
)), )),
) as _i9.Future<_i4.FeeObject>); ) as _i8.Future<_i4.FeeObject>);
@override @override
_i9.Future<int> get maxFee => (super.noSuchMethod( _i8.Future<int> get maxFee => (super.noSuchMethod(
Invocation.getter(#maxFee), Invocation.getter(#maxFee),
returnValue: _i9.Future<int>.value(0), returnValue: _i8.Future<int>.value(0),
) as _i9.Future<int>); ) as _i8.Future<int>);
@override @override
_i9.Future<String> get currentReceivingAddress => (super.noSuchMethod( _i8.Future<String> get currentReceivingAddress => (super.noSuchMethod(
Invocation.getter(#currentReceivingAddress), Invocation.getter(#currentReceivingAddress),
returnValue: _i9.Future<String>.value(''), returnValue: _i8.Future<String>.value(''),
) as _i9.Future<String>); ) as _i8.Future<String>);
@override @override
_i5.Balance get balance => (super.noSuchMethod( _i5.Balance get balance => (super.noSuchMethod(
Invocation.getter(#balance), Invocation.getter(#balance),
@ -648,16 +627,16 @@ class MockManager extends _i1.Mock implements _i16.Manager {
), ),
) as _i5.Balance); ) as _i5.Balance);
@override @override
_i9.Future<List<_i17.Transaction>> get transactions => (super.noSuchMethod( _i8.Future<List<_i16.Transaction>> get transactions => (super.noSuchMethod(
Invocation.getter(#transactions), Invocation.getter(#transactions),
returnValue: returnValue:
_i9.Future<List<_i17.Transaction>>.value(<_i17.Transaction>[]), _i8.Future<List<_i16.Transaction>>.value(<_i16.Transaction>[]),
) as _i9.Future<List<_i17.Transaction>>); ) as _i8.Future<List<_i16.Transaction>>);
@override @override
_i9.Future<List<_i17.UTXO>> get utxos => (super.noSuchMethod( _i8.Future<List<_i16.UTXO>> get utxos => (super.noSuchMethod(
Invocation.getter(#utxos), Invocation.getter(#utxos),
returnValue: _i9.Future<List<_i17.UTXO>>.value(<_i17.UTXO>[]), returnValue: _i8.Future<List<_i16.UTXO>>.value(<_i16.UTXO>[]),
) as _i9.Future<List<_i17.UTXO>>); ) as _i8.Future<List<_i16.UTXO>>);
@override @override
set walletName(String? newName) => super.noSuchMethod( set walletName(String? newName) => super.noSuchMethod(
Invocation.setter( Invocation.setter(
@ -677,15 +656,15 @@ class MockManager extends _i1.Mock implements _i16.Manager {
returnValue: '', returnValue: '',
) as String); ) as String);
@override @override
_i9.Future<List<String>> get mnemonic => (super.noSuchMethod( _i8.Future<List<String>> get mnemonic => (super.noSuchMethod(
Invocation.getter(#mnemonic), Invocation.getter(#mnemonic),
returnValue: _i9.Future<List<String>>.value(<String>[]), returnValue: _i8.Future<List<String>>.value(<String>[]),
) as _i9.Future<List<String>>); ) as _i8.Future<List<String>>);
@override @override
_i9.Future<String?> get mnemonicPassphrase => (super.noSuchMethod( _i8.Future<String?> get mnemonicPassphrase => (super.noSuchMethod(
Invocation.getter(#mnemonicPassphrase), Invocation.getter(#mnemonicPassphrase),
returnValue: _i9.Future<String?>.value(), returnValue: _i8.Future<String?>.value(),
) as _i9.Future<String?>); ) as _i8.Future<String?>);
@override @override
bool get isConnected => (super.noSuchMethod( bool get isConnected => (super.noSuchMethod(
Invocation.getter(#isConnected), Invocation.getter(#isConnected),
@ -727,24 +706,24 @@ class MockManager extends _i1.Mock implements _i16.Manager {
returnValue: false, returnValue: false,
) as bool); ) as bool);
@override @override
_i9.Future<String> get xpub => (super.noSuchMethod( _i8.Future<String> get xpub => (super.noSuchMethod(
Invocation.getter(#xpub), Invocation.getter(#xpub),
returnValue: _i9.Future<String>.value(''), returnValue: _i8.Future<String>.value(''),
) as _i9.Future<String>); ) as _i8.Future<String>);
@override @override
bool get hasListeners => (super.noSuchMethod( bool get hasListeners => (super.noSuchMethod(
Invocation.getter(#hasListeners), Invocation.getter(#hasListeners),
returnValue: false, returnValue: false,
) as bool); ) as bool);
@override @override
_i9.Future<void> updateNode(bool? shouldRefresh) => (super.noSuchMethod( _i8.Future<void> updateNode(bool? shouldRefresh) => (super.noSuchMethod(
Invocation.method( Invocation.method(
#updateNode, #updateNode,
[shouldRefresh], [shouldRefresh],
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
void dispose() => super.noSuchMethod( void dispose() => super.noSuchMethod(
Invocation.method( Invocation.method(
@ -754,7 +733,7 @@ class MockManager extends _i1.Mock implements _i16.Manager {
returnValueForMissingStub: null, returnValueForMissingStub: null,
); );
@override @override
_i9.Future<Map<String, dynamic>> prepareSend({ _i8.Future<Map<String, dynamic>> prepareSend({
required String? address, required String? address,
required _i6.Amount? amount, required _i6.Amount? amount,
Map<String, dynamic>? args, Map<String, dynamic>? args,
@ -770,27 +749,27 @@ class MockManager extends _i1.Mock implements _i16.Manager {
}, },
), ),
returnValue: returnValue:
_i9.Future<Map<String, dynamic>>.value(<String, dynamic>{}), _i8.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
) as _i9.Future<Map<String, dynamic>>); ) as _i8.Future<Map<String, dynamic>>);
@override @override
_i9.Future<String> confirmSend({required Map<String, dynamic>? txData}) => _i8.Future<String> confirmSend({required Map<String, dynamic>? txData}) =>
(super.noSuchMethod( (super.noSuchMethod(
Invocation.method( Invocation.method(
#confirmSend, #confirmSend,
[], [],
{#txData: txData}, {#txData: txData},
), ),
returnValue: _i9.Future<String>.value(''), returnValue: _i8.Future<String>.value(''),
) as _i9.Future<String>); ) as _i8.Future<String>);
@override @override
_i9.Future<void> refresh() => (super.noSuchMethod( _i8.Future<void> refresh() => (super.noSuchMethod(
Invocation.method( Invocation.method(
#refresh, #refresh,
[], [],
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
bool validateAddress(String? address) => (super.noSuchMethod( bool validateAddress(String? address) => (super.noSuchMethod(
Invocation.method( Invocation.method(
@ -800,33 +779,33 @@ class MockManager extends _i1.Mock implements _i16.Manager {
returnValue: false, returnValue: false,
) as bool); ) as bool);
@override @override
_i9.Future<bool> testNetworkConnection() => (super.noSuchMethod( _i8.Future<bool> testNetworkConnection() => (super.noSuchMethod(
Invocation.method( Invocation.method(
#testNetworkConnection, #testNetworkConnection,
[], [],
), ),
returnValue: _i9.Future<bool>.value(false), returnValue: _i8.Future<bool>.value(false),
) as _i9.Future<bool>); ) as _i8.Future<bool>);
@override @override
_i9.Future<void> initializeNew() => (super.noSuchMethod( _i8.Future<void> initializeNew() => (super.noSuchMethod(
Invocation.method( Invocation.method(
#initializeNew, #initializeNew,
[], [],
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
_i9.Future<void> initializeExisting() => (super.noSuchMethod( _i8.Future<void> initializeExisting() => (super.noSuchMethod(
Invocation.method( Invocation.method(
#initializeExisting, #initializeExisting,
[], [],
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
_i9.Future<void> recoverFromMnemonic({ _i8.Future<void> recoverFromMnemonic({
required String? mnemonic, required String? mnemonic,
String? mnemonicPassphrase, String? mnemonicPassphrase,
required int? maxUnusedAddressGap, required int? maxUnusedAddressGap,
@ -845,20 +824,20 @@ class MockManager extends _i1.Mock implements _i16.Manager {
#height: height, #height: height,
}, },
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
_i9.Future<void> exitCurrentWallet() => (super.noSuchMethod( _i8.Future<void> exitCurrentWallet() => (super.noSuchMethod(
Invocation.method( Invocation.method(
#exitCurrentWallet, #exitCurrentWallet,
[], [],
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
_i9.Future<void> fullRescan( _i8.Future<void> fullRescan(
int? maxUnusedAddressGap, int? maxUnusedAddressGap,
int? maxNumberOfIndexesToCheck, int? maxNumberOfIndexesToCheck,
) => ) =>
@ -870,11 +849,11 @@ class MockManager extends _i1.Mock implements _i16.Manager {
maxNumberOfIndexesToCheck, maxNumberOfIndexesToCheck,
], ],
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
_i9.Future<_i6.Amount> estimateFeeFor( _i8.Future<_i6.Amount> estimateFeeFor(
_i6.Amount? amount, _i6.Amount? amount,
int? feeRate, int? feeRate,
) => ) =>
@ -886,7 +865,7 @@ class MockManager extends _i1.Mock implements _i16.Manager {
feeRate, feeRate,
], ],
), ),
returnValue: _i9.Future<_i6.Amount>.value(_FakeAmount_4( returnValue: _i8.Future<_i6.Amount>.value(_FakeAmount_4(
this, this,
Invocation.method( Invocation.method(
#estimateFeeFor, #estimateFeeFor,
@ -896,26 +875,26 @@ class MockManager extends _i1.Mock implements _i16.Manager {
], ],
), ),
)), )),
) as _i9.Future<_i6.Amount>); ) as _i8.Future<_i6.Amount>);
@override @override
_i9.Future<bool> generateNewAddress() => (super.noSuchMethod( _i8.Future<bool> generateNewAddress() => (super.noSuchMethod(
Invocation.method( Invocation.method(
#generateNewAddress, #generateNewAddress,
[], [],
), ),
returnValue: _i9.Future<bool>.value(false), returnValue: _i8.Future<bool>.value(false),
) as _i9.Future<bool>); ) as _i8.Future<bool>);
@override @override
_i9.Future<void> resetRescanOnOpen() => (super.noSuchMethod( _i8.Future<void> resetRescanOnOpen() => (super.noSuchMethod(
Invocation.method( Invocation.method(
#resetRescanOnOpen, #resetRescanOnOpen,
[], [],
), ),
returnValue: _i9.Future<void>.value(), returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i9.Future<void>.value(), returnValueForMissingStub: _i8.Future<void>.value(),
) as _i9.Future<void>); ) as _i8.Future<void>);
@override @override
void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( void addListener(_i14.VoidCallback? listener) => super.noSuchMethod(
Invocation.method( Invocation.method(
#addListener, #addListener,
[listener], [listener],
@ -923,7 +902,7 @@ class MockManager extends _i1.Mock implements _i16.Manager {
returnValueForMissingStub: null, returnValueForMissingStub: null,
); );
@override @override
void removeListener(_i15.VoidCallback? listener) => super.noSuchMethod( void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod(
Invocation.method( Invocation.method(
#removeListener, #removeListener,
[listener], [listener],