From 86c33d4cb561c47a79f99b45f14c03833f62fca6 Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 27 Oct 2023 11:16:25 -0600 Subject: [PATCH] no need to fetch address if it already exists --- .../coins/bitcoincash/bitcoincash_wallet.dart | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index 4b42c16dc..875aed471 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -2668,28 +2668,30 @@ class BitcoinCashWallet extends CoinServiceAPI try { // Populating the addresses to check for (var i = 0; i < utxosToUse.length; i++) { - final txid = utxosToUse[i].txid; - final tx = await _cachedElectrumXClient.getTransaction( - txHash: txid, - coin: coin, - ); + if (utxosToUse[i].address == null) { + final txid = utxosToUse[i].txid; + final tx = await _cachedElectrumXClient.getTransaction( + txHash: txid, + coin: coin, + ); - for (final output in tx["vout"] as List) { - final n = output["n"]; - if (n != null && n == utxosToUse[i].vout) { - String address = - output["scriptPubKey"]?["addresses"]?[0] as String? ?? - output["scriptPubKey"]["address"] as String; - if (bitbox.Address.detectFormat(address) != - bitbox.Address.formatCashAddr) { - try { - address = bitbox.Address.toCashAddress(address); - } catch (_) { - rethrow; + for (final output in tx["vout"] as List) { + final n = output["n"]; + if (n != null && n == utxosToUse[i].vout) { + String address = + output["scriptPubKey"]?["addresses"]?[0] as String? ?? + output["scriptPubKey"]["address"] as String; + if (bitbox.Address.detectFormat(address) != + bitbox.Address.formatCashAddr) { + try { + address = bitbox.Address.toCashAddress(address); + } catch (_) { + rethrow; + } } - } - utxosToUse[i] = utxosToUse[i].copyWith(address: address); + utxosToUse[i] = utxosToUse[i].copyWith(address: address); + } } }