From d39cac0547c960df0a890e89f43b458147b4b07a Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 17 May 2021 16:29:31 -0400 Subject: Set m_subtract_fee_outputs during recipients vector loop Instead of setting this afterwards based on the results from the loop, just do it inside of the loop itself. Fixed some styling nearby --- src/wallet/spend.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index af56ce06d2..dbe5d165c8 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -590,12 +590,13 @@ bool CWallet::CreateTransactionInternal( 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 outputs_to_subtract_fee_from = 0; // The number of outputs which we are subtracting the fee from - for (const auto& recipient : vecSend) - { + for (const auto& recipient : vecSend) { recipients_sum += recipient.nAmount; - if (recipient.fSubtractFeeFromAmount) + if (recipient.fSubtractFeeFromAmount) { outputs_to_subtract_fee_from++; + coin_selection_params.m_subtract_fee_outputs = true; + } } // Create change script that will be used if we need change @@ -670,8 +671,6 @@ bool CWallet::CreateTransactionInternal( coin_selection_params.m_change_fee = coin_selection_params.m_effective_feerate.GetFee(coin_selection_params.change_output_size); coin_selection_params.m_cost_of_change = coin_selection_params.m_discard_feerate.GetFee(coin_selection_params.change_spend_size) + coin_selection_params.m_change_fee; - coin_selection_params.m_subtract_fee_outputs = outputs_to_subtract_fee_from != 0; // If we are doing subtract fee from recipient, don't use effective values - // vouts to the payees if (!coin_selection_params.m_subtract_fee_outputs) { coin_selection_params.tx_noinputs_size = 11; // Static vsize overhead + outputs vsize. 4 nVersion, 4 nLocktime, 1 input count, 1 output count, 1 witness overhead (dummy, flag, stack size) @@ -747,7 +746,7 @@ bool CWallet::CreateTransactionInternal( // Subtract fee from the change output if not subtracting it from recipient outputs CAmount fee_needed = nFeeRet; - if (outputs_to_subtract_fee_from == 0) { + if (!coin_selection_params.m_subtract_fee_outputs) { change_position->nValue -= fee_needed; } @@ -773,7 +772,7 @@ bool CWallet::CreateTransactionInternal( } // Reduce output values for subtractFeeFromAmount - if (outputs_to_subtract_fee_from != 0) { + if (coin_selection_params.m_subtract_fee_outputs) { CAmount to_reduce = fee_needed + change_amount - change_and_fee; int i = 0; bool fFirst = true; -- cgit v1.2.3