From 32ab430651594ed3d10a6ed75f19de5197f0e9b0 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 17 May 2021 16:23:08 -0400 Subject: 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. --- src/wallet/spend.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/wallet') diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 70f29001d0..374d361976 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -586,21 +586,11 @@ bool CWallet::CreateTransactionInternal( unsigned int outputs_to_subtract_fee_from = 0; // The number of outputs which we are subtracting the fee from for (const auto& recipient : vecSend) { - if (recipients_sum < 0 || recipient.nAmount < 0) - { - error = _("Transaction amounts must not be negative"); - return false; - } recipients_sum += recipient.nAmount; if (recipient.fSubtractFeeFromAmount) outputs_to_subtract_fee_from++; } - if (vecSend.empty()) - { - error = _("Transaction must have at least one recipient"); - return false; - } CMutableTransaction txNew; FeeCalculation feeCalc; @@ -897,6 +887,16 @@ bool CWallet::CreateTransaction( FeeCalculation& fee_calc_out, bool sign) { + if (vecSend.empty()) { + error = _("Transaction must have at least one recipient"); + return false; + } + + if (std::any_of(vecSend.cbegin(), vecSend.cend(), [](const auto& recipient){ return recipient.nAmount < 0; })) { + error = _("Transaction amounts must not be negative"); + return false; + } + LOCK(cs_wallet); int nChangePosIn = nChangePosInOut; -- cgit v1.2.3