@@ -590,12 +590,13 @@ bool CWallet::CreateTransactionInternal(
590590 const OutputType change_type = TransactionChangeType (coin_control.m_change_type ? *coin_control.m_change_type : m_default_change_type, vecSend);
591591 ReserveDestination reservedest (this , change_type);
592592 unsigned int outputs_to_subtract_fee_from = 0 ; // The number of outputs which we are subtracting the fee from
593- for (const auto & recipient : vecSend)
594- {
593+ for (const auto & recipient : vecSend) {
595594 recipients_sum += recipient.nAmount ;
596595
597- if (recipient.fSubtractFeeFromAmount )
596+ if (recipient.fSubtractFeeFromAmount ) {
598597 outputs_to_subtract_fee_from++;
598+ coin_selection_params.m_subtract_fee_outputs = true ;
599+ }
599600 }
600601
601602 // Create change script that will be used if we need change
@@ -670,8 +671,6 @@ bool CWallet::CreateTransactionInternal(
670671 coin_selection_params.m_change_fee = coin_selection_params.m_effective_feerate .GetFee (coin_selection_params.change_output_size );
671672 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 ;
672673
673- 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
674-
675674 // vouts to the payees
676675 if (!coin_selection_params.m_subtract_fee_outputs ) {
677676 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(
747746
748747 // Subtract fee from the change output if not subtracting it from recipient outputs
749748 CAmount fee_needed = nFeeRet;
750- if (outputs_to_subtract_fee_from == 0 ) {
749+ if (!coin_selection_params. m_subtract_fee_outputs ) {
751750 change_position->nValue -= fee_needed;
752751 }
753752
@@ -773,7 +772,7 @@ bool CWallet::CreateTransactionInternal(
773772 }
774773
775774 // Reduce output values for subtractFeeFromAmount
776- if (outputs_to_subtract_fee_from != 0 ) {
775+ if (coin_selection_params. m_subtract_fee_outputs ) {
777776 CAmount to_reduce = fee_needed + change_amount - change_and_fee;
778777 int i = 0 ;
779778 bool fFirst = true ;
0 commit comments