diff options
author | Andrew Chow <achow101-github@achow101.com> | 2021-05-17 16:26:40 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2021-05-30 14:06:13 -0400 |
commit | 364e0698a543a19e81ae407cc523970e6ed924e8 (patch) | |
tree | a09efcbe22968510110756540c6ca52f92551b66 /src | |
parent | 32ab430651594ed3d10a6ed75f19de5197f0e9b0 (diff) |
Move variable initializations to where they are used
- txNew nLockTime setting to txNew init
- FeeCalc to the fee estimation fetching
- setCoins to prior to SelectCoins
- nBytes to CalculateMaximumSignedTxSize call
- tx_sizes to CalculateMaximumSignedTxSize call
- coin_selection_params.m_avoid_partial_spends to params init
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/spend.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 374d361976..af56ce06d2 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -580,6 +580,12 @@ bool CWallet::CreateTransactionInternal( { AssertLockHeld(cs_wallet); + CMutableTransaction txNew; // The resulting transaction that we make + txNew.nLockTime = GetLocktimeForNewTransaction(chain(), GetLastBlockHash(), GetLastBlockHeight()); + + CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy + coin_selection_params.m_avoid_partial_spends = coin_control.m_avoid_partial_spends; + CAmount recipients_sum = 0; 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); @@ -592,17 +598,6 @@ bool CWallet::CreateTransactionInternal( outputs_to_subtract_fee_from++; } - CMutableTransaction txNew; - FeeCalculation feeCalc; - TxSize tx_sizes; - int nBytes; - std::set<CInputCoin> setCoins; - txNew.nLockTime = GetLocktimeForNewTransaction(chain(), GetLastBlockHash(), GetLastBlockHeight()); - std::vector<COutput> vAvailableCoins; - AvailableCoins(vAvailableCoins, &coin_control, 1, MAX_MONEY, MAX_MONEY, 0); - CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy - coin_selection_params.m_avoid_partial_spends = coin_control.m_avoid_partial_spends; - // Create change script that will be used if we need change // TODO: pass in scriptChange instead of reservedest so // change transaction isn't always pay-to-bitcoin-address @@ -648,6 +643,7 @@ bool CWallet::CreateTransactionInternal( coin_selection_params.m_discard_feerate = GetDiscardRate(*this); // Get the fee rate to use effective values in coin selection + FeeCalculation feeCalc; coin_selection_params.m_effective_feerate = GetMinimumFeeRate(*this, coin_control, &feeCalc); // Do not, ever, assume that it's fine to change the fee rate if the user has explicitly // provided one @@ -701,9 +697,13 @@ bool CWallet::CreateTransactionInternal( const CAmount not_input_fees = coin_selection_params.m_effective_feerate.GetFee(coin_selection_params.tx_noinputs_size); CAmount selection_target = recipients_sum + not_input_fees; + // Get available coins + std::vector<COutput> vAvailableCoins; + AvailableCoins(vAvailableCoins, &coin_control, 1, MAX_MONEY, MAX_MONEY, 0); + // Choose coins to use CAmount inputs_sum = 0; - setCoins.clear(); + std::set<CInputCoin> setCoins; if (!SelectCoins(vAvailableCoins, /* nTargetValue */ selection_target, setCoins, inputs_sum, coin_control, coin_selection_params)) { error = _("Insufficient funds"); @@ -737,8 +737,8 @@ bool CWallet::CreateTransactionInternal( } // Calculate the transaction fee - tx_sizes = CalculateMaximumSignedTxSize(CTransaction(txNew), this, coin_control.fAllowWatchOnly); - nBytes = tx_sizes.vsize; + TxSize tx_sizes = CalculateMaximumSignedTxSize(CTransaction(txNew), this, coin_control.fAllowWatchOnly); + int nBytes = tx_sizes.vsize; if (nBytes < 0) { error = _("Signing transaction failed"); return false; |