diff --git a/lib/electrumx_rpc/cached_electrumx_client.dart b/lib/electrumx_rpc/cached_electrumx_client.dart index 00dc90521..5b5ec6c99 100644 --- a/lib/electrumx_rpc/cached_electrumx_client.dart +++ b/lib/electrumx_rpc/cached_electrumx_client.dart @@ -22,12 +22,12 @@ import 'package:string_validator/string_validator.dart'; class CachedElectrumXClient { final ElectrumXClient electrumXClient; - final ElectrumClient electrumAdapterClient; - final Future Function() electrumAdapterUpdateCallback; + ElectrumClient electrumAdapterClient; + final Future Function() electrumAdapterUpdateCallback; static const minCacheConfirms = 30; - const CachedElectrumXClient({ + CachedElectrumXClient({ required this.electrumXClient, required this.electrumAdapterClient, required this.electrumAdapterUpdateCallback, @@ -36,7 +36,7 @@ class CachedElectrumXClient { factory CachedElectrumXClient.from({ required ElectrumXClient electrumXClient, required ElectrumClient electrumAdapterClient, - required Future Function() electrumAdapterUpdateCallback, + required Future Function() electrumAdapterUpdateCallback, }) => CachedElectrumXClient( electrumXClient: electrumXClient, @@ -47,8 +47,13 @@ class CachedElectrumXClient { /// If the client is closed, use the callback to update it. _checkElectrumAdapterClient() async { if (electrumAdapterClient.peer.isClosed) { - await electrumAdapterUpdateCallback?.call(); - // throw Exception("ElectrumAdapterClient is closed"); + ElectrumClient? _electrumAdapterClient = + await electrumAdapterUpdateCallback?.call(); + if (_electrumAdapterClient != null) { + electrumAdapterClient = _electrumAdapterClient; + } else { + throw Exception("ElectrumAdapterClient is closed"); + } } } @@ -215,6 +220,8 @@ class CachedElectrumXClient { if (cachedTx == null) { await _checkElectrumAdapterClient(); + print(121212); + print(electrumAdapterClient.peer.isClosed); final Map result = await electrumAdapterClient.getTransaction(txHash); diff --git a/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart b/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart index cf67d5ba5..c881cb9d7 100644 --- a/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart +++ b/lib/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart @@ -983,7 +983,7 @@ mixin ElectrumXInterface on Bip39HDWallet { electrumXCachedClient = CachedElectrumXClient.from( electrumXClient: electrumXClient, electrumAdapterClient: electrumAdapterClient, - electrumAdapterUpdateCallback: updateNode, + electrumAdapterUpdateCallback: updateClient, ); subscribableElectrumXClient = SubscribableElectrumXClient.from( node: newNode, @@ -1295,6 +1295,11 @@ mixin ElectrumXInterface on Bip39HDWallet { await updateElectrumX(newNode: node); } + Future updateClient() async { + await updateNode(); + return electrumAdapterClient; + } + FeeObject? _cachedFees; @override