Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,640 Lines • ▼ Show 20 Lines | bool CWallet::SelectCoinsMinConf( | ||||
setCoinsRet.clear(); | setCoinsRet.clear(); | ||||
nValueRet = Amount::zero(); | nValueRet = Amount::zero(); | ||||
std::vector<OutputGroup> utxo_pool; | std::vector<OutputGroup> utxo_pool; | ||||
if (coin_selection_params.use_bnb) { | if (coin_selection_params.use_bnb) { | ||||
// Get long term estimate | // Get long term estimate | ||||
CCoinControl temp; | CCoinControl temp; | ||||
temp.m_confirm_target = 1008; | temp.m_confirm_target = 1008; | ||||
CFeeRate long_term_feerate = GetMinimumFeeRate(*this, temp, g_mempool); | CFeeRate long_term_feerate = GetMinimumFeeRate(*this, temp); | ||||
// Calculate cost of change | // Calculate cost of change | ||||
Amount cost_of_change = | Amount cost_of_change = | ||||
dustRelayFee.GetFee(coin_selection_params.change_spend_size) + | dustRelayFee.GetFee(coin_selection_params.change_spend_size) + | ||||
coin_selection_params.effective_fee.GetFee( | coin_selection_params.effective_fee.GetFee( | ||||
coin_selection_params.change_output_size); | coin_selection_params.change_output_size); | ||||
// Filter by the min conf specs and add to utxo_pool and calculate | // Filter by the min conf specs and add to utxo_pool and calculate | ||||
▲ Show 20 Lines • Show All 448 Lines • ▼ Show 20 Lines | txNew.nLockTime = GetLocktimeForNewTransaction(chain(), locked_chainIn); | ||||
scriptChange = GetScriptForDestination( | scriptChange = GetScriptForDestination( | ||||
GetDestinationForKey(vchPubKey, change_type)); | GetDestinationForKey(vchPubKey, change_type)); | ||||
} | } | ||||
CTxOut change_prototype_txout(Amount::zero(), scriptChange); | CTxOut change_prototype_txout(Amount::zero(), scriptChange); | ||||
coin_selection_params.change_output_size = | coin_selection_params.change_output_size = | ||||
GetSerializeSize(change_prototype_txout); | GetSerializeSize(change_prototype_txout); | ||||
// Get the fee rate to use effective values in coin selection | // Get the fee rate to use effective values in coin selection | ||||
CFeeRate nFeeRateNeeded = | CFeeRate nFeeRateNeeded = GetMinimumFeeRate(*this, coinControl); | ||||
GetMinimumFeeRate(*this, coinControl, g_mempool); | |||||
nFeeRet = Amount::zero(); | nFeeRet = Amount::zero(); | ||||
bool pick_new_inputs = true; | bool pick_new_inputs = true; | ||||
Amount nValueIn = Amount::zero(); | Amount nValueIn = Amount::zero(); | ||||
// BnB selector is the only selector used when this is true. | // BnB selector is the only selector used when this is true. | ||||
// That should only happen on the first pass through the loop. | // That should only happen on the first pass through the loop. | ||||
// If we are doing subtract fee from recipient, then don't use BnB | // If we are doing subtract fee from recipient, then don't use BnB | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | txNew.nLockTime = GetLocktimeForNewTransaction(chain(), locked_chainIn); | ||||
CTransaction txNewConst(txNew); | CTransaction txNewConst(txNew); | ||||
int nBytes = CalculateMaximumSignedTxSize( | int nBytes = CalculateMaximumSignedTxSize( | ||||
txNewConst, this, coinControl.fAllowWatchOnly); | txNewConst, this, coinControl.fAllowWatchOnly); | ||||
if (nBytes < 0) { | if (nBytes < 0) { | ||||
strFailReason = _("Signing transaction failed"); | strFailReason = _("Signing transaction failed"); | ||||
return false; | return false; | ||||
} | } | ||||
Amount nFeeNeeded = | Amount nFeeNeeded = GetMinimumFee(*this, nBytes, coinControl); | ||||
GetMinimumFee(*this, nBytes, coinControl, g_mempool); | |||||
// If we made it here and we aren't even able to meet the relay fee | // If we made it here and we aren't even able to meet the relay fee | ||||
// on the next pass, give up because we must be at the maximum | // on the next pass, give up because we must be at the maximum | ||||
// allowed fee. | // allowed fee. | ||||
if (nFeeNeeded < chain().relayMinFee().GetFee(nBytes)) { | if (nFeeNeeded < chain().relayMinFee().GetFee(nBytes)) { | ||||
strFailReason = _("Transaction too large for fee policy"); | strFailReason = _("Transaction too large for fee policy"); | ||||
return false; | return false; | ||||
} | } | ||||
Show All 10 Lines | txNew.nLockTime = GetLocktimeForNewTransaction(chain(), locked_chainIn); | ||||
// tx size) and so we should add a change output. Only try this | // tx size) and so we should add a change output. Only try this | ||||
// once. | // once. | ||||
if (nChangePosInOut == -1 && nSubtractFeeFromAmount == 0 && | if (nChangePosInOut == -1 && nSubtractFeeFromAmount == 0 && | ||||
pick_new_inputs) { | pick_new_inputs) { | ||||
// Add 2 as a buffer in case increasing # of outputs changes | // Add 2 as a buffer in case increasing # of outputs changes | ||||
// compact size | // compact size | ||||
unsigned int tx_size_with_change = | unsigned int tx_size_with_change = | ||||
nBytes + coin_selection_params.change_output_size + 2; | nBytes + coin_selection_params.change_output_size + 2; | ||||
Amount fee_needed_with_change = GetMinimumFee( | Amount fee_needed_with_change = | ||||
*this, tx_size_with_change, coinControl, g_mempool); | GetMinimumFee(*this, tx_size_with_change, coinControl); | ||||
Amount minimum_value_for_change = | Amount minimum_value_for_change = | ||||
GetDustThreshold(change_prototype_txout, dustRelayFee); | GetDustThreshold(change_prototype_txout, dustRelayFee); | ||||
if (nFeeRet >= | if (nFeeRet >= | ||||
fee_needed_with_change + minimum_value_for_change) { | fee_needed_with_change + minimum_value_for_change) { | ||||
pick_new_inputs = false; | pick_new_inputs = false; | ||||
nFeeRet = fee_needed_with_change; | nFeeRet = fee_needed_with_change; | ||||
continue; | continue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,665 Lines • Show Last 20 Lines |