Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,770 Lines • ▼ Show 20 Lines | bool CWallet::FundTransaction(CMutableTransaction &tx, Amount &nFeeRet, | ||||
coinControl.fAllowOtherInputs = true; | coinControl.fAllowOtherInputs = true; | ||||
for (const CTxIn &txin : tx.vin) { | for (const CTxIn &txin : tx.vin) { | ||||
coinControl.Select(txin.prevout); | coinControl.Select(txin.prevout); | ||||
} | } | ||||
CReserveKey reservekey(this); | CReserveKey reservekey(this); | ||||
CTransactionRef tx_new; | CTransactionRef tx_new; | ||||
if (!CreateTransaction(vecSend, tx_new, reservekey, nFeeRet, nChangePosInOut, | if (!CreateTransaction(vecSend, tx_new, reservekey, nFeeRet, | ||||
strFailReason, coinControl, false)) { | nChangePosInOut, strFailReason, coinControl, | ||||
false)) { | |||||
return false; | return false; | ||||
} | } | ||||
if (nChangePosInOut != -1) { | if (nChangePosInOut != -1) { | ||||
tx.vout.insert(tx.vout.begin() + nChangePosInOut, | tx.vout.insert(tx.vout.begin() + nChangePosInOut, | ||||
tx_new->vout[nChangePosInOut]); | tx_new->vout[nChangePosInOut]); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 283 Lines • ▼ Show 20 Lines | assert(txNew.nLockTime < LOCKTIME_THRESHOLD); | ||||
dPriority = txNewConst.ComputePriority(dPriority, nBytes); | dPriority = txNewConst.ComputePriority(dPriority, nBytes); | ||||
// Remove scriptSigs to eliminate the fee calculation dummy | // Remove scriptSigs to eliminate the fee calculation dummy | ||||
// signatures. | // signatures. | ||||
for (auto &vin : txNew.vin) { | for (auto &vin : txNew.vin) { | ||||
vin.scriptSig = CScript(); | vin.scriptSig = CScript(); | ||||
} | } | ||||
Amount nFeeNeeded = GetMinimumFee(nBytes, g_mempool); | Amount nFeeNeeded = GetMinimumFee(nBytes, g_mempool, coinControl); | ||||
// 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. | ||||
Amount minFee = GetConfig().GetMinFeePerKB().GetFeeCeiling(nBytes); | Amount minFee = GetConfig().GetMinFeePerKB().GetFeeCeiling(nBytes); | ||||
if (nFeeNeeded < minFee) { | if (nFeeNeeded < minFee) { | ||||
strFailReason = _("Transaction too large for fee policy"); | strFailReason = _("Transaction too large for fee policy"); | ||||
return false; | return false; | ||||
Show All 9 Lines | assert(txNew.nLockTime < LOCKTIME_THRESHOLD); | ||||
// addressed because it requires returning the fee to the payees | // addressed because it requires returning the fee to the payees | ||||
// and not the change output. | // and not the change output. | ||||
// 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 = | Amount fee_needed_for_change = GetMinimumFee( | ||||
GetMinimumFee(change_prototype_size, g_mempool); | change_prototype_size, g_mempool, coinControl); | ||||
Amount minimum_value_for_change = | Amount minimum_value_for_change = | ||||
change_prototype_txout.GetDustThreshold(dustRelayFee); | change_prototype_txout.GetDustThreshold(dustRelayFee); | ||||
Amount max_excess_fee = | Amount max_excess_fee = | ||||
fee_needed_for_change + minimum_value_for_change; | fee_needed_for_change + minimum_value_for_change; | ||||
if (nFeeRet > nFeeNeeded + max_excess_fee && | if (nFeeRet > nFeeNeeded + max_excess_fee && | ||||
nChangePosInOut == -1 && nSubtractFeeFromAmount == 0 && | nChangePosInOut == -1 && nSubtractFeeFromAmount == 0 && | ||||
pick_new_inputs) { | pick_new_inputs) { | ||||
pick_new_inputs = false; | pick_new_inputs = false; | ||||
▲ Show 20 Lines • Show All 1,346 Lines • Show Last 20 Lines |