aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/spend.cpp
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2021-05-17 16:23:08 -0400
committerAndrew Chow <achow101-github@achow101.com>2021-05-30 14:05:42 -0400
commit32ab430651594ed3d10a6ed75f19de5197f0e9b0 (patch)
treef658b8a102786669ff0021a944c4f7ebee99216f /src/wallet/spend.cpp
parentcd1d6d3324a841087f6d5da723394e8d7df07ec7 (diff)
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.
Diffstat (limited to 'src/wallet/spend.cpp')
-rw-r--r--src/wallet/spend.cpp20
1 files changed, 10 insertions, 10 deletions
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;