diff --git a/lib/electrumx_rpc/electrumx_client.dart b/lib/electrumx_rpc/electrumx_client.dart index dff2b68fd..39e27ee81 100644 --- a/lib/electrumx_rpc/electrumx_client.dart +++ b/lib/electrumx_rpc/electrumx_client.dart @@ -108,7 +108,7 @@ class ElectrumXClient { late Prefs _prefs; late TorService _torService; - List? failovers; + late final List _failovers; int currentFailoverIndex = -1; final Duration connectionTimeoutForSpecialCaseJsonRPCClients; @@ -145,6 +145,7 @@ class ElectrumXClient { _host = host; _port = port; _useSSL = useSSL; + _failovers = failovers; final bus = globalEventBusForTesting ?? GlobalEventBus.instance; @@ -284,9 +285,11 @@ class ElectrumXClient { usePort = port; useUseSSL = useSSL; } else { - useHost = failovers![currentFailoverIndex].address; - usePort = failovers![currentFailoverIndex].port; - useUseSSL = failovers![currentFailoverIndex].useSSL; + _electrumAdapterChannel = null; + await ClientManager.sharedInstance.remove(cryptoCurrency: cryptoCurrency); + useHost = _failovers[currentFailoverIndex].address; + usePort = _failovers[currentFailoverIndex].port; + useUseSSL = _failovers[currentFailoverIndex].useSSL; } _electrumAdapterChannel ??= await electrum_adapter.connect( @@ -402,7 +405,7 @@ class ElectrumXClient { rethrow; } } catch (e) { - if (failovers != null && currentFailoverIndex < failovers!.length - 1) { + if (currentFailoverIndex < _failovers.length - 1) { currentFailoverIndex++; return request( command: command, @@ -495,7 +498,7 @@ class ElectrumXClient { rethrow; } } catch (e) { - if (failovers != null && currentFailoverIndex < failovers!.length - 1) { + if (currentFailoverIndex < _failovers.length - 1) { currentFailoverIndex++; return batchRequest( command: command, diff --git a/lib/services/node_service.dart b/lib/services/node_service.dart index e55e2218b..db4a25a1b 100644 --- a/lib/services/node_service.dart +++ b/lib/services/node_service.dart @@ -32,6 +32,49 @@ class NodeService extends ChangeNotifier { }); Future updateDefaults() async { + // hack + if (AppConfig.coins.where((e) => e.identifier == "firo").isNotEmpty) { + final others = [ + "electrumx01.firo.org", + "electrumx02.firo.org", + "electrumx03.firo.org", + "electrumx.firo.org", + ]; + const port = 50002; + const idPrefix = "not_a_real_default_but_temp"; + + for (final host in others) { + final _id = "${idPrefix}_$host"; + + NodeModel? node = DB.instance.get( + boxName: DB.boxNameNodeModels, + key: _id, + ); + + if (node == null) { + node = NodeModel( + host: host, + port: port, + name: host, + id: _id, + useSSL: true, + enabled: true, + coinName: "firo", + isFailover: true, + isDown: false, + torEnabled: true, + clearnetEnabled: true, + ); + + await DB.instance.put( + boxName: DB.boxNameNodeModels, + key: _id, + value: node, + ); + } + } + } + for (final defaultNode in AppConfig.coins.map( (e) => e.defaultNode, )) { diff --git a/lib/wallets/wallet/wallet.dart b/lib/wallets/wallet/wallet.dart index 0beaf2a80..bb2d2df56 100644 --- a/lib/wallets/wallet/wallet.dart +++ b/lib/wallets/wallet/wallet.dart @@ -569,16 +569,19 @@ abstract class Wallet { final start = DateTime.now(); bool tAlive = true; - final t = Timer.periodic(const Duration(seconds: 1), (timer) async { - if (tAlive) { - final pingSuccess = await pingCheck(); - if (!pingSuccess) { - tAlive = false; + Timer? t; + if (this is! SparkInterface) { + t = Timer.periodic(const Duration(seconds: 1), (timer) async { + if (tAlive) { + final pingSuccess = await pingCheck(); + if (!pingSuccess) { + tAlive = false; + } + } else { + timer.cancel(); } - } else { - timer.cancel(); - } - }); + }); + } void _checkAlive() { if (!tAlive) throw Exception("refresh alive ping failure"); @@ -717,13 +720,15 @@ abstract class Wallet { _checkAlive(); GlobalEventBus.instance.fire(RefreshPercentChangedEvent(1.0, walletId)); - tAlive = false; // interrupt timer as its not needed anymore + if (this is! SparkInterface) { + tAlive = false; // interrupt timer as its not needed anymore + } completer.complete(); } catch (error, strace) { completer.completeError(error, strace); } finally { - t.cancel(); + t?.cancel(); refreshMutex.release(); if (!completer.isCompleted) { completer.completeError( diff --git a/test/cached_electrumx_test.mocks.dart b/test/cached_electrumx_test.mocks.dart index 993f73f69..25324b805 100644 --- a/test/cached_electrumx_test.mocks.dart +++ b/test/cached_electrumx_test.mocks.dart @@ -90,15 +90,6 @@ class MockElectrumXClient extends _i1.Mock implements _i5.ElectrumXClient { ), ) as _i2.CryptoCurrency); - @override - set failovers(List<_i5.ElectrumXNode>? _failovers) => super.noSuchMethod( - Invocation.setter( - #failovers, - _failovers, - ), - returnValueForMissingStub: null, - ); - @override int get currentFailoverIndex => (super.noSuchMethod( Invocation.getter(#currentFailoverIndex), diff --git a/test/services/coins/bitcoin/bitcoin_wallet_test.mocks.dart b/test/services/coins/bitcoin/bitcoin_wallet_test.mocks.dart index e38af7ce9..75fc2228a 100644 --- a/test/services/coins/bitcoin/bitcoin_wallet_test.mocks.dart +++ b/test/services/coins/bitcoin/bitcoin_wallet_test.mocks.dart @@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient { ), ) as _i2.CryptoCurrency); - @override - set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod( - Invocation.setter( - #failovers, - _failovers, - ), - returnValueForMissingStub: null, - ); - @override int get currentFailoverIndex => (super.noSuchMethod( Invocation.getter(#currentFailoverIndex), diff --git a/test/services/coins/bitcoincash/bitcoincash_wallet_test.mocks.dart b/test/services/coins/bitcoincash/bitcoincash_wallet_test.mocks.dart index edbb3c632..c6eadd8f6 100644 --- a/test/services/coins/bitcoincash/bitcoincash_wallet_test.mocks.dart +++ b/test/services/coins/bitcoincash/bitcoincash_wallet_test.mocks.dart @@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient { ), ) as _i2.CryptoCurrency); - @override - set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod( - Invocation.setter( - #failovers, - _failovers, - ), - returnValueForMissingStub: null, - ); - @override int get currentFailoverIndex => (super.noSuchMethod( Invocation.getter(#currentFailoverIndex), diff --git a/test/services/coins/dogecoin/dogecoin_wallet_test.mocks.dart b/test/services/coins/dogecoin/dogecoin_wallet_test.mocks.dart index c5c167366..344647a50 100644 --- a/test/services/coins/dogecoin/dogecoin_wallet_test.mocks.dart +++ b/test/services/coins/dogecoin/dogecoin_wallet_test.mocks.dart @@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient { ), ) as _i2.CryptoCurrency); - @override - set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod( - Invocation.setter( - #failovers, - _failovers, - ), - returnValueForMissingStub: null, - ); - @override int get currentFailoverIndex => (super.noSuchMethod( Invocation.getter(#currentFailoverIndex), diff --git a/test/services/coins/namecoin/namecoin_wallet_test.mocks.dart b/test/services/coins/namecoin/namecoin_wallet_test.mocks.dart index 80e8c8922..851a2855c 100644 --- a/test/services/coins/namecoin/namecoin_wallet_test.mocks.dart +++ b/test/services/coins/namecoin/namecoin_wallet_test.mocks.dart @@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient { ), ) as _i2.CryptoCurrency); - @override - set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod( - Invocation.setter( - #failovers, - _failovers, - ), - returnValueForMissingStub: null, - ); - @override int get currentFailoverIndex => (super.noSuchMethod( Invocation.getter(#currentFailoverIndex), diff --git a/test/services/coins/particl/particl_wallet_test.mocks.dart b/test/services/coins/particl/particl_wallet_test.mocks.dart index 0fde0b645..ccd74b4d7 100644 --- a/test/services/coins/particl/particl_wallet_test.mocks.dart +++ b/test/services/coins/particl/particl_wallet_test.mocks.dart @@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient { ), ) as _i2.CryptoCurrency); - @override - set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod( - Invocation.setter( - #failovers, - _failovers, - ), - returnValueForMissingStub: null, - ); - @override int get currentFailoverIndex => (super.noSuchMethod( Invocation.getter(#currentFailoverIndex),