From dac21c793f8fbb4d5debc55ac97c406c7c93ff48 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 17 May 2021 16:20:40 -0400 Subject: [PATCH] Rename nValue and nValueToSelect nValue is the sum of the intended recipient amounts, so name it that for clarity. nValueToSelect is the coin selection target value, so name it selection_target for clarity. --- src/wallet/spend.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index e8bbdc454b..3e69703788 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -580,18 +580,18 @@ bool CWallet::CreateTransactionInternal( { AssertLockHeld(cs_wallet); - CAmount nValue = 0; + CAmount recipients_sum = 0; const OutputType change_type = TransactionChangeType(coin_control.m_change_type ? *coin_control.m_change_type : m_default_change_type, vecSend); ReserveDestination reservedest(this, change_type); unsigned int nSubtractFeeFromAmount = 0; for (const auto& recipient : vecSend) { - if (nValue < 0 || recipient.nAmount < 0) + if (recipients_sum < 0 || recipient.nAmount < 0) { error = _("Transaction amounts must not be negative"); return false; } - nValue += recipient.nAmount; + recipients_sum += recipient.nAmount; if (recipient.fSubtractFeeFromAmount) nSubtractFeeFromAmount++; @@ -709,12 +709,12 @@ bool CWallet::CreateTransactionInternal( // Include the fees for things that aren't inputs, excluding the change output const CAmount not_input_fees = coin_selection_params.m_effective_feerate.GetFee(coin_selection_params.tx_noinputs_size); - CAmount nValueToSelect = nValue + not_input_fees; + CAmount selection_target = recipients_sum + not_input_fees; // Choose coins to use CAmount inputs_sum = 0; setCoins.clear(); - if (!SelectCoins(vAvailableCoins, /* nTargetValue */ nValueToSelect, setCoins, inputs_sum, coin_control, coin_selection_params)) + if (!SelectCoins(vAvailableCoins, /* nTargetValue */ selection_target, setCoins, inputs_sum, coin_control, coin_selection_params)) { error = _("Insufficient funds"); return false; @@ -722,7 +722,7 @@ bool CWallet::CreateTransactionInternal( // Always make a change output // We will reduce the fee from this change output later, and remove the output if it is too small. - const CAmount change_and_fee = inputs_sum - nValue; + const CAmount change_and_fee = inputs_sum - recipients_sum; assert(change_and_fee >= 0); CTxOut newTxOut(change_and_fee, scriptChange);