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

This commit is contained in:
julian 2023-09-22 15:59:07 -06:00
parent 5527678b94
commit a4f8c52148
2 changed files with 8 additions and 6 deletions

View file

@ -140,7 +140,7 @@ class BitcoinCashWallet extends CoinServiceAPI
coin: coin,
db: db,
generateAddressForChain: _generateAddressForChain,
cachedElectrumX: cachedElectrumXClient,
getWalletCachedElectrumX: () => cachedElectrumXClient,
);
initCoinControlInterface(
walletId: walletId,

View file

@ -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<String, dynamic> tx = await _cachedElectrumX.getTransaction(
Map<String, dynamic> tx =
await _getWalletCachedElectrumX().getTransaction(
coin: _coin,
txHash: e.txid,
verbose: true,