mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-27 02:26:44 +00:00
dont allow negative values to enter tx when send max true
This commit is contained in:
parent
b84aa2e7cb
commit
c084a0de7e
1 changed files with 5 additions and 1 deletions
|
@ -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
|
//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;
|
long maxSendAmt = totalSelectedAmt - noChangeFeeRequiredAmt;
|
||||||
|
if(maxSendAmt < 0) {
|
||||||
|
throw new InsufficientFundsException("Not enough combined value in selected UTXOs for fee of " + noChangeFeeRequiredAmt);
|
||||||
|
}
|
||||||
|
|
||||||
Optional<Payment> optMaxPayment = payments.stream().filter(payment -> payment.isSendMax()).findFirst();
|
Optional<Payment> optMaxPayment = payments.stream().filter(payment -> payment.isSendMax()).findFirst();
|
||||||
if(optMaxPayment.isPresent()) {
|
if(optMaxPayment.isPresent()) {
|
||||||
Payment maxPayment = optMaxPayment.get();
|
Payment maxPayment = optMaxPayment.get();
|
||||||
maxSendAmt = maxSendAmt - payments.stream().filter(payment -> !maxPayment.equals(payment)).map(Payment::getAmount).mapToLong(v -> v).sum();
|
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);
|
maxPayment.setAmount(maxSendAmt);
|
||||||
totalPaymentAmount = payments.stream().map(Payment::getAmount).mapToLong(v -> v).sum();
|
totalPaymentAmount = payments.stream().map(Payment::getAmount).mapToLong(v -> v).sum();
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue