aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/spend.cpp
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2021-05-17 16:29:31 -0400
committerAndrew Chow <achow101-github@achow101.com>2021-05-30 14:06:40 -0400
commitd39cac0547c960df0a890e89f43b458147b4b07a (patch)
treea66c10ff2b818bdf113d4d1cff42f8f9f713f6d7 /src/wallet/spend.cpp
parent364e0698a543a19e81ae407cc523970e6ed924e8 (diff)
downloadbitcoin-d39cac0547c960df0a890e89f43b458147b4b07a.tar.xz
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
Diffstat (limited to 'src/wallet/spend.cpp')
-rw-r--r--src/wallet/spend.cpp13
1 files changed, 6 insertions, 7 deletions
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;