From f28af937ecc9d176cf4c9330338b4a64d98e7f7c Mon Sep 17 00:00:00 2001 From: Omar Hatem Date: Tue, 4 Mar 2025 19:12:19 +0200 Subject: [PATCH] Fix edge case of sending amount that will leave near dust amount as a change (#2044) --- cw_bitcoin/lib/electrum_wallet.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index e7b8be156..64595b253 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -915,6 +915,10 @@ abstract class ElectrumWalletBase } } + // if the amount left for change is less than dust, but not less than 0 + // then add it to the fees + fee += amountLeftForChange; + return EstimatedTxResult( utxos: utxoDetails.utxos, inputPrivKeyInfos: utxoDetails.inputPrivKeyInfos, @@ -1366,7 +1370,7 @@ abstract class ElectrumWalletBase List updatedUnspentCoins = []; final previousUnspentCoins = List.from(unspentCoins.where((utxo) => - utxo.bitcoinAddressRecord.type != SegwitAddresType.mweb && + utxo.bitcoinAddressRecord.type != SegwitAddresType.mweb && utxo.bitcoinAddressRecord is! BitcoinSilentPaymentAddressRecord)); if (hasSilentPaymentsScanning) { @@ -1424,7 +1428,6 @@ abstract class ElectrumWalletBase required List updatedUnspentCoins, required List?> results, }) { - if (failedCount == results.length) { printV("All UTXOs failed to fetch, falling back to previous UTXOs"); return previousUnspentCoins;