@@ -580,6 +580,12 @@ bool CWallet::CreateTransactionInternal(
580
580
{
581
581
AssertLockHeld (cs_wallet);
582
582
583
+ CMutableTransaction txNew; // The resulting transaction that we make
584
+ txNew.nLockTime = GetLocktimeForNewTransaction (chain (), GetLastBlockHash (), GetLastBlockHeight ());
585
+
586
+ CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy
587
+ coin_selection_params.m_avoid_partial_spends = coin_control.m_avoid_partial_spends ;
588
+
583
589
CAmount recipients_sum = 0 ;
584
590
const OutputType change_type = TransactionChangeType (coin_control.m_change_type ? *coin_control.m_change_type : m_default_change_type, vecSend);
585
591
ReserveDestination reservedest (this , change_type);
@@ -592,17 +598,6 @@ bool CWallet::CreateTransactionInternal(
592
598
outputs_to_subtract_fee_from++;
593
599
}
594
600
595
- CMutableTransaction txNew;
596
- FeeCalculation feeCalc;
597
- TxSize tx_sizes;
598
- int nBytes;
599
- std::set<CInputCoin> setCoins;
600
- txNew.nLockTime = GetLocktimeForNewTransaction (chain (), GetLastBlockHash (), GetLastBlockHeight ());
601
- std::vector<COutput> vAvailableCoins;
602
- AvailableCoins (vAvailableCoins, &coin_control, 1 , MAX_MONEY, MAX_MONEY, 0 );
603
- CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy
604
- coin_selection_params.m_avoid_partial_spends = coin_control.m_avoid_partial_spends ;
605
-
606
601
// Create change script that will be used if we need change
607
602
// TODO: pass in scriptChange instead of reservedest so
608
603
// change transaction isn't always pay-to-bitcoin-address
@@ -648,6 +643,7 @@ bool CWallet::CreateTransactionInternal(
648
643
coin_selection_params.m_discard_feerate = GetDiscardRate (*this );
649
644
650
645
// Get the fee rate to use effective values in coin selection
646
+ FeeCalculation feeCalc;
651
647
coin_selection_params.m_effective_feerate = GetMinimumFeeRate (*this , coin_control, &feeCalc);
652
648
// Do not, ever, assume that it's fine to change the fee rate if the user has explicitly
653
649
// provided one
@@ -701,9 +697,13 @@ bool CWallet::CreateTransactionInternal(
701
697
const CAmount not_input_fees = coin_selection_params.m_effective_feerate .GetFee (coin_selection_params.tx_noinputs_size );
702
698
CAmount selection_target = recipients_sum + not_input_fees;
703
699
700
+ // Get available coins
701
+ std::vector<COutput> vAvailableCoins;
702
+ AvailableCoins (vAvailableCoins, &coin_control, 1 , MAX_MONEY, MAX_MONEY, 0 );
703
+
704
704
// Choose coins to use
705
705
CAmount inputs_sum = 0 ;
706
- setCoins. clear () ;
706
+ std::set<CInputCoin> setCoins;
707
707
if (!SelectCoins (vAvailableCoins, /* nTargetValue */ selection_target, setCoins, inputs_sum, coin_control, coin_selection_params))
708
708
{
709
709
error = _ (" Insufficient funds" );
@@ -737,8 +737,8 @@ bool CWallet::CreateTransactionInternal(
737
737
}
738
738
739
739
// Calculate the transaction fee
740
- tx_sizes = CalculateMaximumSignedTxSize (CTransaction (txNew), this , coin_control.fAllowWatchOnly );
741
- nBytes = tx_sizes.vsize ;
740
+ TxSize tx_sizes = CalculateMaximumSignedTxSize (CTransaction (txNew), this , coin_control.fAllowWatchOnly );
741
+ int nBytes = tx_sizes.vsize ;
742
742
if (nBytes < 0 ) {
743
743
error = _ (" Signing transaction failed" );
744
744
return false ;
0 commit comments