Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,981 Lines • ▼ Show 20 Lines | assert(txNew.nLockTime < LOCKTIME_THRESHOLD); | ||||
txNew.vout.clear(); | txNew.vout.clear(); | ||||
bool fFirst = true; | bool fFirst = true; | ||||
Amount nValueToSelect = nValue; | Amount nValueToSelect = nValue; | ||||
if (nSubtractFeeFromAmount == 0) { | if (nSubtractFeeFromAmount == 0) { | ||||
nValueToSelect += nFeeRet; | nValueToSelect += nFeeRet; | ||||
} | } | ||||
double dPriority = 0; | |||||
// vouts to the payees | // vouts to the payees | ||||
for (const auto &recipient : vecSend) { | for (const auto &recipient : vecSend) { | ||||
CTxOut txout(recipient.nAmount, recipient.scriptPubKey); | CTxOut txout(recipient.nAmount, recipient.scriptPubKey); | ||||
if (recipient.fSubtractFeeFromAmount) { | if (recipient.fSubtractFeeFromAmount) { | ||||
// Subtract fee equally from each selected recipient. | // Subtract fee equally from each selected recipient. | ||||
txout.nValue -= nFeeRet / int(nSubtractFeeFromAmount); | txout.nValue -= nFeeRet / int(nSubtractFeeFromAmount); | ||||
Show All 32 Lines | assert(txNew.nLockTime < LOCKTIME_THRESHOLD); | ||||
setCoins.clear(); | setCoins.clear(); | ||||
if (!SelectCoins(vAvailableCoins, nValueToSelect, setCoins, | if (!SelectCoins(vAvailableCoins, nValueToSelect, setCoins, | ||||
nValueIn, &coinControl)) { | nValueIn, &coinControl)) { | ||||
strFailReason = _("Insufficient funds"); | strFailReason = _("Insufficient funds"); | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
for (const auto &pcoin : setCoins) { | |||||
Amount nCredit = pcoin.txout.nValue; | |||||
// The coin age after the next block (depth+1) is used instead | |||||
// of the current, reflecting an assumption the user would | |||||
// accept a bit more delay for a chance at a free transaction. | |||||
// But mempool inputs might still be in the mempool, so their | |||||
// age stays 0. | |||||
int age = pcoin.wtx->GetDepthInMainChain(); | |||||
assert(age >= 0); | |||||
if (age != 0) { | |||||
age += 1; | |||||
} | |||||
dPriority += (age * nCredit) / SATOSHI; | |||||
} | |||||
const Amount nChange = nValueIn - nValueToSelect; | const Amount nChange = nValueIn - nValueToSelect; | ||||
if (nChange > Amount::zero()) { | if (nChange > Amount::zero()) { | ||||
// Fill a vout to ourself. | // Fill a vout to ourself. | ||||
CTxOut newTxOut(nChange, scriptChange); | CTxOut newTxOut(nChange, scriptChange); | ||||
// We do not move dust-change to fees, because the sender would | // We do not move dust-change to fees, because the sender would | ||||
// end up paying more than requested. This would be against the | // end up paying more than requested. This would be against the | ||||
// purpose of the all-inclusive feature. So instead we raise the | // purpose of the all-inclusive feature. So instead we raise the | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | assert(txNew.nLockTime < LOCKTIME_THRESHOLD); | ||||
// Fill in dummy signatures for fee calculation. | // Fill in dummy signatures for fee calculation. | ||||
if (!DummySignTx(txNew, setCoins)) { | if (!DummySignTx(txNew, setCoins)) { | ||||
strFailReason = _("Signing transaction failed"); | strFailReason = _("Signing transaction failed"); | ||||
return false; | return false; | ||||
} | } | ||||
CTransaction txNewConst(txNew); | CTransaction txNewConst(txNew); | ||||
unsigned int nBytes = txNewConst.GetTotalSize(); | unsigned int nBytes = txNewConst.GetTotalSize(); | ||||
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, coinControl); | Amount nFeeNeeded = GetMinimumFee(nBytes, g_mempool, coinControl); | ||||
▲ Show 20 Lines • Show All 1,443 Lines • Show Last 20 Lines |