mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
add chain height service in order to hold one subscription per coin
This commit is contained in:
parent
9b93dc78d2
commit
0d8f1c2b95
2 changed files with 14 additions and 3 deletions
10
lib/electrumx_rpc/electrumx_chain_height_service.dart
Normal file
10
lib/electrumx_rpc/electrumx_chain_height_service.dart
Normal file
|
@ -0,0 +1,10 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
||||
/// Store chain height subscriptions for each coin.
|
||||
abstract class ElectrumxChainHeightService {
|
||||
static Map<Coin, StreamSubscription<dynamic>?> subscriptions = {};
|
||||
// Used to hold chain height subscriptions for each coin as in:
|
||||
// ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] = sub;
|
||||
}
|
|
@ -6,6 +6,7 @@ import 'package:bitcoindart/bitcoindart.dart' as bitcoindart;
|
|||
import 'package:coinlib_flutter/coinlib_flutter.dart' as coinlib;
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/cached_electrumx_client.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/electrumx_chain_height_service.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/electrumx_client.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/subscribable_electrumx_client.dart';
|
||||
import 'package:stackwallet/models/isar/models/blockchain_data/v2/input_v2.dart';
|
||||
|
@ -36,7 +37,6 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
|||
int? get maximumFeerate => null;
|
||||
|
||||
int? _latestHeight;
|
||||
StreamSubscription<dynamic>? _heightSubscription;
|
||||
|
||||
static const _kServerBatchCutoffVersion = [1, 6];
|
||||
List<int>? _serverVersion;
|
||||
|
@ -807,7 +807,8 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
|||
|
||||
try {
|
||||
// Don't set a stream subscription if one already exists.
|
||||
if (_heightSubscription != null) {
|
||||
if (ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] !=
|
||||
null) {
|
||||
if (_latestHeight != null) {
|
||||
return _latestHeight!;
|
||||
} else {
|
||||
|
@ -824,7 +825,7 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
|||
subscribableElectrumXClient.subscribeToBlockHeaders();
|
||||
|
||||
// set stream subscription
|
||||
_heightSubscription =
|
||||
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] =
|
||||
subscription.responseStream.asBroadcastStream().listen((event) {
|
||||
final response = event;
|
||||
if (response != null &&
|
||||
|
|
Loading…
Reference in a new issue