@@ -590,12 +590,13 @@ bool CWallet::CreateTransactionInternal(
590
590
const OutputType change_type = TransactionChangeType (coin_control.m_change_type ? *coin_control.m_change_type : m_default_change_type, vecSend);
591
591
ReserveDestination reservedest (this , change_type);
592
592
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) {
595
594
recipients_sum += recipient.nAmount ;
596
595
597
- if (recipient.fSubtractFeeFromAmount )
596
+ if (recipient.fSubtractFeeFromAmount ) {
598
597
outputs_to_subtract_fee_from++;
598
+ coin_selection_params.m_subtract_fee_outputs = true ;
599
+ }
599
600
}
600
601
601
602
// Create change script that will be used if we need change
@@ -670,8 +671,6 @@ bool CWallet::CreateTransactionInternal(
670
671
coin_selection_params.m_change_fee = coin_selection_params.m_effective_feerate .GetFee (coin_selection_params.change_output_size );
671
672
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 ;
672
673
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
-
675
674
// vouts to the payees
676
675
if (!coin_selection_params.m_subtract_fee_outputs ) {
677
676
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(
747
746
748
747
// Subtract fee from the change output if not subtracting it from recipient outputs
749
748
CAmount fee_needed = nFeeRet;
750
- if (outputs_to_subtract_fee_from == 0 ) {
749
+ if (!coin_selection_params. m_subtract_fee_outputs ) {
751
750
change_position->nValue -= fee_needed;
752
751
}
753
752
@@ -773,7 +772,7 @@ bool CWallet::CreateTransactionInternal(
773
772
}
774
773
775
774
// Reduce output values for subtractFeeFromAmount
776
- if (outputs_to_subtract_fee_from != 0 ) {
775
+ if (coin_selection_params. m_subtract_fee_outputs ) {
777
776
CAmount to_reduce = fee_needed + change_amount - change_and_fee;
778
777
int i = 0 ;
779
778
bool fFirst = true ;
0 commit comments