mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-24 19:25:52 +00:00
WIP: fix electrumx failovers, add some "default" firo nodes, and tweak firo pings
This commit is contained in:
parent
34ad1d9022
commit
744f273862
9 changed files with 68 additions and 71 deletions
|
@ -108,7 +108,7 @@ class ElectrumXClient {
|
||||||
late Prefs _prefs;
|
late Prefs _prefs;
|
||||||
late TorService _torService;
|
late TorService _torService;
|
||||||
|
|
||||||
List<ElectrumXNode>? failovers;
|
late final List<ElectrumXNode> _failovers;
|
||||||
int currentFailoverIndex = -1;
|
int currentFailoverIndex = -1;
|
||||||
|
|
||||||
final Duration connectionTimeoutForSpecialCaseJsonRPCClients;
|
final Duration connectionTimeoutForSpecialCaseJsonRPCClients;
|
||||||
|
@ -145,6 +145,7 @@ class ElectrumXClient {
|
||||||
_host = host;
|
_host = host;
|
||||||
_port = port;
|
_port = port;
|
||||||
_useSSL = useSSL;
|
_useSSL = useSSL;
|
||||||
|
_failovers = failovers;
|
||||||
|
|
||||||
final bus = globalEventBusForTesting ?? GlobalEventBus.instance;
|
final bus = globalEventBusForTesting ?? GlobalEventBus.instance;
|
||||||
|
|
||||||
|
@ -284,9 +285,11 @@ class ElectrumXClient {
|
||||||
usePort = port;
|
usePort = port;
|
||||||
useUseSSL = useSSL;
|
useUseSSL = useSSL;
|
||||||
} else {
|
} else {
|
||||||
useHost = failovers![currentFailoverIndex].address;
|
_electrumAdapterChannel = null;
|
||||||
usePort = failovers![currentFailoverIndex].port;
|
await ClientManager.sharedInstance.remove(cryptoCurrency: cryptoCurrency);
|
||||||
useUseSSL = failovers![currentFailoverIndex].useSSL;
|
useHost = _failovers[currentFailoverIndex].address;
|
||||||
|
usePort = _failovers[currentFailoverIndex].port;
|
||||||
|
useUseSSL = _failovers[currentFailoverIndex].useSSL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_electrumAdapterChannel ??= await electrum_adapter.connect(
|
_electrumAdapterChannel ??= await electrum_adapter.connect(
|
||||||
|
@ -402,7 +405,7 @@ class ElectrumXClient {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (failovers != null && currentFailoverIndex < failovers!.length - 1) {
|
if (currentFailoverIndex < _failovers.length - 1) {
|
||||||
currentFailoverIndex++;
|
currentFailoverIndex++;
|
||||||
return request(
|
return request(
|
||||||
command: command,
|
command: command,
|
||||||
|
@ -495,7 +498,7 @@ class ElectrumXClient {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (failovers != null && currentFailoverIndex < failovers!.length - 1) {
|
if (currentFailoverIndex < _failovers.length - 1) {
|
||||||
currentFailoverIndex++;
|
currentFailoverIndex++;
|
||||||
return batchRequest(
|
return batchRequest(
|
||||||
command: command,
|
command: command,
|
||||||
|
|
|
@ -32,6 +32,49 @@ class NodeService extends ChangeNotifier {
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<void> updateDefaults() async {
|
Future<void> 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<NodeModel>(
|
||||||
|
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<NodeModel>(
|
||||||
|
boxName: DB.boxNameNodeModels,
|
||||||
|
key: _id,
|
||||||
|
value: node,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (final defaultNode in AppConfig.coins.map(
|
for (final defaultNode in AppConfig.coins.map(
|
||||||
(e) => e.defaultNode,
|
(e) => e.defaultNode,
|
||||||
)) {
|
)) {
|
||||||
|
|
|
@ -569,7 +569,9 @@ abstract class Wallet<T extends CryptoCurrency> {
|
||||||
final start = DateTime.now();
|
final start = DateTime.now();
|
||||||
|
|
||||||
bool tAlive = true;
|
bool tAlive = true;
|
||||||
final t = Timer.periodic(const Duration(seconds: 1), (timer) async {
|
Timer? t;
|
||||||
|
if (this is! SparkInterface) {
|
||||||
|
t = Timer.periodic(const Duration(seconds: 1), (timer) async {
|
||||||
if (tAlive) {
|
if (tAlive) {
|
||||||
final pingSuccess = await pingCheck();
|
final pingSuccess = await pingCheck();
|
||||||
if (!pingSuccess) {
|
if (!pingSuccess) {
|
||||||
|
@ -579,6 +581,7 @@ abstract class Wallet<T extends CryptoCurrency> {
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void _checkAlive() {
|
void _checkAlive() {
|
||||||
if (!tAlive) throw Exception("refresh alive ping failure");
|
if (!tAlive) throw Exception("refresh alive ping failure");
|
||||||
|
@ -717,13 +720,15 @@ abstract class Wallet<T extends CryptoCurrency> {
|
||||||
_checkAlive();
|
_checkAlive();
|
||||||
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(1.0, walletId));
|
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(1.0, walletId));
|
||||||
|
|
||||||
|
if (this is! SparkInterface) {
|
||||||
tAlive = false; // interrupt timer as its not needed anymore
|
tAlive = false; // interrupt timer as its not needed anymore
|
||||||
|
}
|
||||||
|
|
||||||
completer.complete();
|
completer.complete();
|
||||||
} catch (error, strace) {
|
} catch (error, strace) {
|
||||||
completer.completeError(error, strace);
|
completer.completeError(error, strace);
|
||||||
} finally {
|
} finally {
|
||||||
t.cancel();
|
t?.cancel();
|
||||||
refreshMutex.release();
|
refreshMutex.release();
|
||||||
if (!completer.isCompleted) {
|
if (!completer.isCompleted) {
|
||||||
completer.completeError(
|
completer.completeError(
|
||||||
|
|
|
@ -90,15 +90,6 @@ class MockElectrumXClient extends _i1.Mock implements _i5.ElectrumXClient {
|
||||||
),
|
),
|
||||||
) as _i2.CryptoCurrency);
|
) as _i2.CryptoCurrency);
|
||||||
|
|
||||||
@override
|
|
||||||
set failovers(List<_i5.ElectrumXNode>? _failovers) => super.noSuchMethod(
|
|
||||||
Invocation.setter(
|
|
||||||
#failovers,
|
|
||||||
_failovers,
|
|
||||||
),
|
|
||||||
returnValueForMissingStub: null,
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get currentFailoverIndex => (super.noSuchMethod(
|
int get currentFailoverIndex => (super.noSuchMethod(
|
||||||
Invocation.getter(#currentFailoverIndex),
|
Invocation.getter(#currentFailoverIndex),
|
||||||
|
|
|
@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient {
|
||||||
),
|
),
|
||||||
) as _i2.CryptoCurrency);
|
) as _i2.CryptoCurrency);
|
||||||
|
|
||||||
@override
|
|
||||||
set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod(
|
|
||||||
Invocation.setter(
|
|
||||||
#failovers,
|
|
||||||
_failovers,
|
|
||||||
),
|
|
||||||
returnValueForMissingStub: null,
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get currentFailoverIndex => (super.noSuchMethod(
|
int get currentFailoverIndex => (super.noSuchMethod(
|
||||||
Invocation.getter(#currentFailoverIndex),
|
Invocation.getter(#currentFailoverIndex),
|
||||||
|
|
|
@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient {
|
||||||
),
|
),
|
||||||
) as _i2.CryptoCurrency);
|
) as _i2.CryptoCurrency);
|
||||||
|
|
||||||
@override
|
|
||||||
set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod(
|
|
||||||
Invocation.setter(
|
|
||||||
#failovers,
|
|
||||||
_failovers,
|
|
||||||
),
|
|
||||||
returnValueForMissingStub: null,
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get currentFailoverIndex => (super.noSuchMethod(
|
int get currentFailoverIndex => (super.noSuchMethod(
|
||||||
Invocation.getter(#currentFailoverIndex),
|
Invocation.getter(#currentFailoverIndex),
|
||||||
|
|
|
@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient {
|
||||||
),
|
),
|
||||||
) as _i2.CryptoCurrency);
|
) as _i2.CryptoCurrency);
|
||||||
|
|
||||||
@override
|
|
||||||
set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod(
|
|
||||||
Invocation.setter(
|
|
||||||
#failovers,
|
|
||||||
_failovers,
|
|
||||||
),
|
|
||||||
returnValueForMissingStub: null,
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get currentFailoverIndex => (super.noSuchMethod(
|
int get currentFailoverIndex => (super.noSuchMethod(
|
||||||
Invocation.getter(#currentFailoverIndex),
|
Invocation.getter(#currentFailoverIndex),
|
||||||
|
|
|
@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient {
|
||||||
),
|
),
|
||||||
) as _i2.CryptoCurrency);
|
) as _i2.CryptoCurrency);
|
||||||
|
|
||||||
@override
|
|
||||||
set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod(
|
|
||||||
Invocation.setter(
|
|
||||||
#failovers,
|
|
||||||
_failovers,
|
|
||||||
),
|
|
||||||
returnValueForMissingStub: null,
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get currentFailoverIndex => (super.noSuchMethod(
|
int get currentFailoverIndex => (super.noSuchMethod(
|
||||||
Invocation.getter(#currentFailoverIndex),
|
Invocation.getter(#currentFailoverIndex),
|
||||||
|
|
|
@ -87,15 +87,6 @@ class MockElectrumXClient extends _i1.Mock implements _i4.ElectrumXClient {
|
||||||
),
|
),
|
||||||
) as _i2.CryptoCurrency);
|
) as _i2.CryptoCurrency);
|
||||||
|
|
||||||
@override
|
|
||||||
set failovers(List<_i4.ElectrumXNode>? _failovers) => super.noSuchMethod(
|
|
||||||
Invocation.setter(
|
|
||||||
#failovers,
|
|
||||||
_failovers,
|
|
||||||
),
|
|
||||||
returnValueForMissingStub: null,
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get currentFailoverIndex => (super.noSuchMethod(
|
int get currentFailoverIndex => (super.noSuchMethod(
|
||||||
Invocation.getter(#currentFailoverIndex),
|
Invocation.getter(#currentFailoverIndex),
|
||||||
|
|
Loading…
Reference in a new issue