check chain height subscription validity with ping

This commit is contained in:
sneurlax 2024-02-05 12:38:40 -06:00
parent 0d8f1c2b95
commit 0d5a8f25a1

View file

@ -809,6 +809,26 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
// Don't set a stream subscription if one already exists. // Don't set a stream subscription if one already exists.
if (ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] != if (ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] !=
null) { null) {
// Check if the stream subscription is paused.
if (ElectrumxChainHeightService
.subscriptions[cryptoCurrency.coin]!.isPaused) {
// If it's paused, resume it.
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin]!
.resume();
}
// Check if the stream subscription is active by pinging it.
if (!(await subscribableElectrumXClient.ping())) {
// If it's not active, reconnect it.
final node = await getCurrentElectrumXNode();
await subscribableElectrumXClient.connect(
host: node.address, port: node.port);
// Wait for first response.
return completer.future;
}
if (_latestHeight != null) { if (_latestHeight != null) {
return _latestHeight!; return _latestHeight!;
} else { } else {