From eddd6406efc20b83e659d59faa16189417b0f5ed Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 12 May 2022 10:56:00 +0200 Subject: [PATCH] consider spent mempool outputs when checking max spendable amount for rbf txes --- src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java index b21d0b3..cfde89e 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java @@ -967,7 +967,7 @@ public class Wallet extends Persistable implements Comparable { throw new IllegalArgumentException("Use an input fee rate of 1 sat/vB when using a defined fee amount so UTXO selectors overestimate effective value"); } - long maxSpendableAmt = getMaxSpendable(payments.stream().map(Payment::getAddress).collect(Collectors.toList()), feeRate); + long maxSpendableAmt = getMaxSpendable(payments.stream().map(Payment::getAddress).collect(Collectors.toList()), feeRate, includeSpentMempoolOutputs); if(maxSpendableAmt < 0) { throw new InsufficientFundsException("Not enough combined value in all available UTXOs to send a transaction to the provided addresses at this fee rate"); } @@ -1282,11 +1282,11 @@ public class Wallet extends Persistable implements Comparable { * @param feeRate the fee rate in sats/vB * @return the maximum spendable amount (can be negative if the fee is higher than the combined UTXO value) */ - public long getMaxSpendable(List
paymentAddresses, double feeRate) { + public long getMaxSpendable(List
paymentAddresses, double feeRate, boolean includeSpentMempoolOutputs) { long maxInputValue = 0; Transaction transaction = new Transaction(); - for(Map.Entry utxo : getWalletUtxos().entrySet()) { + for(Map.Entry utxo : getWalletUtxos(includeSpentMempoolOutputs).entrySet()) { int inputWeightUnits = utxo.getValue().getWallet().getInputWeightUnits(); long minInputValue = (long)Math.ceil(feeRate * inputWeightUnits / WITNESS_SCALE_FACTOR); if(utxo.getKey().getValue() > minInputValue) {