no need to fetch address if it already exists

This commit is contained in:
julian 2023-10-27 11:16:25 -06:00
parent c0389d2da7
commit 86c33d4cb5

View file

@ -2668,28 +2668,30 @@ class BitcoinCashWallet extends CoinServiceAPI
try { try {
// Populating the addresses to check // Populating the addresses to check
for (var i = 0; i < utxosToUse.length; i++) { for (var i = 0; i < utxosToUse.length; i++) {
final txid = utxosToUse[i].txid; if (utxosToUse[i].address == null) {
final tx = await _cachedElectrumXClient.getTransaction( final txid = utxosToUse[i].txid;
txHash: txid, final tx = await _cachedElectrumXClient.getTransaction(
coin: coin, txHash: txid,
); coin: coin,
);
for (final output in tx["vout"] as List) { for (final output in tx["vout"] as List) {
final n = output["n"]; final n = output["n"];
if (n != null && n == utxosToUse[i].vout) { if (n != null && n == utxosToUse[i].vout) {
String address = String address =
output["scriptPubKey"]?["addresses"]?[0] as String? ?? output["scriptPubKey"]?["addresses"]?[0] as String? ??
output["scriptPubKey"]["address"] as String; output["scriptPubKey"]["address"] as String;
if (bitbox.Address.detectFormat(address) != if (bitbox.Address.detectFormat(address) !=
bitbox.Address.formatCashAddr) { bitbox.Address.formatCashAddr) {
try { try {
address = bitbox.Address.toCashAddress(address); address = bitbox.Address.toCashAddress(address);
} catch (_) { } catch (_) {
rethrow; rethrow;
}
} }
}
utxosToUse[i] = utxosToUse[i].copyWith(address: address); utxosToUse[i] = utxosToUse[i].copyWith(address: address);
}
} }
} }