Fix edge case of sending amount that will leave near dust amount as a change (#2044)
Omar Hatem committed
Mar 4, 2025 at 19:12 UTC
f28af937ecc9d176cf4c9330338b4a64d98e7f7c
1 file changed
+5
-2
cw_bitcoin/lib/electrum_wallet.dart
+5
-2
@@ -915,6 +915,10 @@ abstract class ElectrumWalletBase
915
}
916
}
917
918
+ // if the amount left for change is less than dust, but not less than 0
919
+ // then add it to the fees
920
+ fee += amountLeftForChange;
921
+
922
return EstimatedTxResult(
923
utxos: utxoDetails.utxos,
924
inputPrivKeyInfos: utxoDetails.inputPrivKeyInfos,
@@ -1366,7 +1370,7 @@ abstract class ElectrumWalletBase
1370
List<BitcoinUnspent> updatedUnspentCoins = [];
1371
1372
final previousUnspentCoins = List<BitcoinUnspent>.from(unspentCoins.where((utxo) =>
1369
- utxo.bitcoinAddressRecord.type != SegwitAddresType.mweb &&
1373
+ utxo.bitcoinAddressRecord.type != SegwitAddresType.mweb &&
1374
utxo.bitcoinAddressRecord is! BitcoinSilentPaymentAddressRecord));
1375
1376
if (hasSilentPaymentsScanning) {
@@ -1424,7 +1428,6 @@ abstract class ElectrumWalletBase
1428
required List<BitcoinUnspent> updatedUnspentCoins,
1429
required List<List<BitcoinUnspent>?> results,
1430
}) {
1427
-
1431
if (failedCount == results.length) {
1432
printV("All UTXOs failed to fetch, falling back to previous UTXOs");
1433
return previousUnspentCoins;