Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 3,104 Lines • ▼ Show 20 Lines | assert(txNew.nLockTime < LOCKTIME_THRESHOLD); | ||||
// to meet nFeeNeeded result in a transaction that requires less | // to meet nFeeNeeded result in a transaction that requires less | ||||
// fee than the prior iteration. | // fee than the prior iteration. | ||||
// If we have no change and a big enough excess fee, then try to | // If we have no change and a big enough excess fee, then try to | ||||
// construct transaction again only without picking new inputs. | // construct transaction again only without picking new inputs. | ||||
// We now know we only need the smaller fee (because of reduced | // We now know we only need the smaller fee (because of reduced | ||||
// 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. | ||||
Amount fee_needed_for_change = GetMinimumFee( | if (nChangePosInOut == -1 && nSubtractFeeFromAmount == 0 && | ||||
change_prototype_size, coinControl, g_mempool); | pick_new_inputs) { | ||||
// Add 2 as a buffer in case increasing # of outputs changes | |||||
// compact size | |||||
unsigned int tx_size_with_change = | |||||
nBytes + change_prototype_size + 2; | |||||
Amount fee_needed_with_change = GetMinimumFee( | |||||
tx_size_with_change, coinControl, g_mempool); | |||||
Amount minimum_value_for_change = | Amount minimum_value_for_change = | ||||
GetDustThreshold(change_prototype_txout, dustRelayFee); | GetDustThreshold(change_prototype_txout, dustRelayFee); | ||||
Amount max_excess_fee = | if (nFeeRet >= | ||||
fee_needed_for_change + minimum_value_for_change; | fee_needed_with_change + minimum_value_for_change) { | ||||
if (nFeeRet > nFeeNeeded + max_excess_fee && | |||||
nChangePosInOut == -1 && nSubtractFeeFromAmount == 0 && | |||||
pick_new_inputs) { | |||||
pick_new_inputs = false; | pick_new_inputs = false; | ||||
nFeeRet = nFeeNeeded + fee_needed_for_change; | nFeeRet = fee_needed_with_change; | ||||
continue; | continue; | ||||
} | } | ||||
} | |||||
// If we have change output already, just increase it | // If we have change output already, just increase it | ||||
if (nFeeRet > nFeeNeeded && nChangePosInOut != -1 && | if (nFeeRet > nFeeNeeded && nChangePosInOut != -1 && | ||||
nSubtractFeeFromAmount == 0) { | nSubtractFeeFromAmount == 0) { | ||||
Amount extraFeePaid = nFeeRet - nFeeNeeded; | Amount extraFeePaid = nFeeRet - nFeeNeeded; | ||||
std::vector<CTxOut>::iterator change_position = | std::vector<CTxOut>::iterator change_position = | ||||
txNew.vout.begin() + nChangePosInOut; | txNew.vout.begin() + nChangePosInOut; | ||||
change_position->nValue += extraFeePaid; | change_position->nValue += extraFeePaid; | ||||
▲ Show 20 Lines • Show All 1,405 Lines • Show Last 20 Lines |