From db9617ee10383bb78e71ec2252d92bb7fe639440 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 26 Apr 2021 14:39:13 +0200 Subject: [PATCH] handle user defined fee amount better by requiring a fee rate of 1 sat/vb for utxo selectors --- src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java index 41760e8..be96a5e 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java @@ -465,6 +465,10 @@ public class Wallet { long totalPaymentAmount = payments.stream().map(Payment::getAmount).mapToLong(v -> v).sum(); long totalUtxoValue = getWalletUtxos().keySet().stream().mapToLong(BlockTransactionHashIndex::getValue).sum(); + if(fee != null && feeRate != Transaction.DEFAULT_MIN_RELAY_FEE) { + 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); 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"); @@ -528,6 +532,7 @@ public class Wallet { //If insufficient fee, increase value required from inputs to include the fee and try again if(differenceAmt < noChangeFeeRequiredAmt) { valueRequiredAmt = totalSelectedAmt + 1; + //If we haven't selected all UTXOs yet, don't require more than the max spendable amount if(valueRequiredAmt > maxSpendableAmt && transaction.getInputs().size() < getWalletUtxos().size()) { valueRequiredAmt = maxSpendableAmt; }