Skip to content

Commit 32ab430

Browse files
committed
Move recipients vector checks to beginning of CreateTransaction
Ensuring that the recipients vector is not empty and that the amounts are non-negative can be done in CreateTransaction rather than CreateTransactionInternal. Additionally, these checks should happen as soon as possible, so they are done at the beginning of CreateTransaction.
1 parent cd1d6d3 commit 32ab430

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/wallet/spend.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -586,21 +586,11 @@ bool CWallet::CreateTransactionInternal(
586586
unsigned int outputs_to_subtract_fee_from = 0; // The number of outputs which we are subtracting the fee from
587587
for (const auto& recipient : vecSend)
588588
{
589-
if (recipients_sum < 0 || recipient.nAmount < 0)
590-
{
591-
error = _("Transaction amounts must not be negative");
592-
return false;
593-
}
594589
recipients_sum += recipient.nAmount;
595590

596591
if (recipient.fSubtractFeeFromAmount)
597592
outputs_to_subtract_fee_from++;
598593
}
599-
if (vecSend.empty())
600-
{
601-
error = _("Transaction must have at least one recipient");
602-
return false;
603-
}
604594

605595
CMutableTransaction txNew;
606596
FeeCalculation feeCalc;
@@ -897,6 +887,16 @@ bool CWallet::CreateTransaction(
897887
FeeCalculation& fee_calc_out,
898888
bool sign)
899889
{
890+
if (vecSend.empty()) {
891+
error = _("Transaction must have at least one recipient");
892+
return false;
893+
}
894+
895+
if (std::any_of(vecSend.cbegin(), vecSend.cend(), [](const auto& recipient){ return recipient.nAmount < 0; })) {
896+
error = _("Transaction amounts must not be negative");
897+
return false;
898+
}
899+
900900
LOCK(cs_wallet);
901901

902902
int nChangePosIn = nChangePosInOut;

0 commit comments

Comments
 (0)