mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 01:56:44 +00:00
handle user defined fee amount better by requiring a fee rate of 1 sat/vb for utxo selectors
This commit is contained in:
parent
2cd133bc1c
commit
db9617ee10
1 changed files with 5 additions and 0 deletions
|
@ -465,6 +465,10 @@ public class Wallet {
|
||||||
long totalPaymentAmount = payments.stream().map(Payment::getAmount).mapToLong(v -> v).sum();
|
long totalPaymentAmount = payments.stream().map(Payment::getAmount).mapToLong(v -> v).sum();
|
||||||
long totalUtxoValue = getWalletUtxos().keySet().stream().mapToLong(BlockTransactionHashIndex::getValue).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);
|
long maxSpendableAmt = getMaxSpendable(payments.stream().map(Payment::getAddress).collect(Collectors.toList()), feeRate);
|
||||||
if(maxSpendableAmt < 0) {
|
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");
|
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 insufficient fee, increase value required from inputs to include the fee and try again
|
||||||
if(differenceAmt < noChangeFeeRequiredAmt) {
|
if(differenceAmt < noChangeFeeRequiredAmt) {
|
||||||
valueRequiredAmt = totalSelectedAmt + 1;
|
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()) {
|
if(valueRequiredAmt > maxSpendableAmt && transaction.getInputs().size() < getWalletUtxos().size()) {
|
||||||
valueRequiredAmt = maxSpendableAmt;
|
valueRequiredAmt = maxSpendableAmt;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue