mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-02-02 11:16:36 +00:00
don't subscribeBlockHeaders if subscription exists
This commit is contained in:
parent
3d42967c8b
commit
46285d44ea
1 changed files with 28 additions and 28 deletions
|
@ -833,39 +833,39 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
||||||
if (_latestHeight != null) {
|
if (_latestHeight != null) {
|
||||||
return _latestHeight!;
|
return _latestHeight!;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
// Make sure we only complete once.
|
||||||
|
bool isFirstResponse = true;
|
||||||
|
|
||||||
// Make sure we only complete once.
|
// Subscribe to block headers.
|
||||||
bool isFirstResponse = true;
|
final subscription =
|
||||||
|
subscribableElectrumXClient.subscribeToBlockHeaders();
|
||||||
|
|
||||||
// Subscribe to block headers.
|
// set stream subscription
|
||||||
final subscription =
|
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] =
|
||||||
subscribableElectrumXClient.subscribeToBlockHeaders();
|
subscription.responseStream.asBroadcastStream().listen((event) {
|
||||||
|
final response = event;
|
||||||
|
if (response != null &&
|
||||||
|
response is Map &&
|
||||||
|
response.containsKey('height')) {
|
||||||
|
final int chainHeight = response['height'] as int;
|
||||||
|
// print("Current chain height: $chainHeight");
|
||||||
|
_latestHeight = chainHeight;
|
||||||
|
|
||||||
// set stream subscription
|
if (isFirstResponse) {
|
||||||
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] ??=
|
isFirstResponse = false;
|
||||||
subscription.responseStream.asBroadcastStream().listen((event) {
|
|
||||||
final response = event;
|
|
||||||
if (response != null &&
|
|
||||||
response is Map &&
|
|
||||||
response.containsKey('height')) {
|
|
||||||
final int chainHeight = response['height'] as int;
|
|
||||||
// print("Current chain height: $chainHeight");
|
|
||||||
_latestHeight = chainHeight;
|
|
||||||
|
|
||||||
if (isFirstResponse) {
|
// Return the chain height.
|
||||||
isFirstResponse = false;
|
completer.complete(chainHeight);
|
||||||
|
}
|
||||||
// Return the chain height.
|
} else {
|
||||||
completer.complete(chainHeight);
|
Logging.instance.log(
|
||||||
|
"blockchain.headers.subscribe returned malformed response\n"
|
||||||
|
"Response: $response",
|
||||||
|
level: LogLevel.Error);
|
||||||
}
|
}
|
||||||
} else {
|
});
|
||||||
Logging.instance.log(
|
}
|
||||||
"blockchain.headers.subscribe returned malformed response\n"
|
|
||||||
"Response: $response",
|
|
||||||
level: LogLevel.Error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Wait for first response.
|
// Wait for first response.
|
||||||
return completer.future;
|
return completer.future;
|
||||||
|
|
Loading…
Reference in a new issue