From c084a0de7e92bbc500234e66dcec690475ac9121 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 4 Mar 2021 12:59:49 +0200 Subject: [PATCH] dont allow negative values to enter tx when send max true --- src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java index e17f7c7..d772166 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java @@ -497,11 +497,15 @@ public class Wallet { //If sending all selected utxos, set the recipient amount to equal to total of those utxos less the no change fee long maxSendAmt = totalSelectedAmt - noChangeFeeRequiredAmt; + if(maxSendAmt < 0) { + throw new InsufficientFundsException("Not enough combined value in selected UTXOs for fee of " + noChangeFeeRequiredAmt); + } + Optional optMaxPayment = payments.stream().filter(payment -> payment.isSendMax()).findFirst(); if(optMaxPayment.isPresent()) { Payment maxPayment = optMaxPayment.get(); maxSendAmt = maxSendAmt - payments.stream().filter(payment -> !maxPayment.equals(payment)).map(Payment::getAmount).mapToLong(v -> v).sum(); - if(maxPayment.getAmount() != maxSendAmt) { + if(maxSendAmt > 0 && maxPayment.getAmount() != maxSendAmt) { maxPayment.setAmount(maxSendAmt); totalPaymentAmount = payments.stream().map(Payment::getAmount).mapToLong(v -> v).sum(); continue;