From a4f8c52148e8003bb191c9f571399d88aa8d56a4 Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 22 Sep 2023 15:59:07 -0600 Subject: [PATCH] pass in getter function for electrumx instance instead of keeping an old reference if the node connection info has changed. This ensures the electrumx calls done from the fusion interface use the updated node info --- .../coins/bitcoincash/bitcoincash_wallet.dart | 2 +- lib/services/mixins/fusion_wallet_interface.dart | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index f96c1b54a..b52614ed8 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -140,7 +140,7 @@ class BitcoinCashWallet extends CoinServiceAPI coin: coin, db: db, generateAddressForChain: _generateAddressForChain, - cachedElectrumX: cachedElectrumXClient, + getWalletCachedElectrumX: () => cachedElectrumXClient, ); initCoinControlInterface( walletId: walletId, diff --git a/lib/services/mixins/fusion_wallet_interface.dart b/lib/services/mixins/fusion_wallet_interface.dart index 73d771845..40aa8529d 100644 --- a/lib/services/mixins/fusion_wallet_interface.dart +++ b/lib/services/mixins/fusion_wallet_interface.dart @@ -27,7 +27,6 @@ mixin FusionWalletInterface { late final String _walletId; late final Coin _coin; late final MainDB _db; - late final CachedElectrumX _cachedElectrumX; late final FusionTorService _torService; // Passed in wallet functions. @@ -37,6 +36,8 @@ mixin FusionWalletInterface { DerivePathType derivePathType, ) _generateAddressForChain; + late final CachedElectrumX Function() _getWalletCachedElectrumX; + /// Initializes the FusionWalletInterface mixin. /// /// This function must be called before any other functions in this mixin. @@ -51,7 +52,7 @@ mixin FusionWalletInterface { int, DerivePathType, ) generateAddressForChain, - required CachedElectrumX cachedElectrumX, + required CachedElectrumX Function() getWalletCachedElectrumX, }) async { // Set passed in wallet data. _walletId = walletId; @@ -59,7 +60,7 @@ mixin FusionWalletInterface { _db = db; _generateAddressForChain = generateAddressForChain; _torService = FusionTorService.sharedInstance; - _cachedElectrumX = cachedElectrumX; + _getWalletCachedElectrumX = getWalletCachedElectrumX; } /// Returns a list of all addresses in the wallet. @@ -78,7 +79,7 @@ mixin FusionWalletInterface { _txs.map( (tx) => tx.toFusionTransaction( dbInstance: _db, - cachedElectrumX: _cachedElectrumX, + cachedElectrumX: _getWalletCachedElectrumX(), ), ), ); @@ -258,7 +259,8 @@ mixin FusionWalletInterface { } // Find public key. - Map tx = await _cachedElectrumX.getTransaction( + Map tx = + await _getWalletCachedElectrumX().getTransaction( coin: _coin, txHash: e.txid, verbose: true,