Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 3,034 Lines • ▼ Show 20 Lines | assert(txNew.nLockTime < LOCKTIME_THRESHOLD); | ||||
} | } | ||||
} | } | ||||
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 | |||||
// end up paying more than requested. This would be against the | |||||
// purpose of the all-inclusive feature. So instead we raise the | |||||
// change and deduct from the recipient. | |||||
if (nSubtractFeeFromAmount > 0 && | |||||
IsDust(newTxOut, dustRelayFee)) { | |||||
Amount nDust = GetDustThreshold(newTxOut, dustRelayFee) - | |||||
newTxOut.nValue; | |||||
// Raise change until no more dust. | |||||
newTxOut.nValue += nDust; | |||||
// Subtract from first recipient. | |||||
for (unsigned int i = 0; i < vecSend.size(); i++) { | |||||
if (vecSend[i].fSubtractFeeFromAmount) { | |||||
txNew.vout[i].nValue -= nDust; | |||||
if (IsDust(txNew.vout[i], dustRelayFee)) { | |||||
strFailReason = | |||||
_("The transaction amount is too small " | |||||
"to send after the fee has been " | |||||
"deducted"); | |||||
return false; | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
// Never create dust outputs; if we would, just add the dust to | // Never create dust outputs; if we would, just add the dust to | ||||
// the fee. | // the fee. | ||||
if (IsDust(newTxOut, dustRelayFee)) { | if (IsDust(newTxOut, dustRelayFee)) { | ||||
nChangePosInOut = -1; | nChangePosInOut = -1; | ||||
nFeeRet += nChange; | nFeeRet += nChange; | ||||
} else { | } else { | ||||
if (nChangePosInOut == -1) { | if (nChangePosInOut == -1) { | ||||
// Insert change txn at random position: | // Insert change txn at random position: | ||||
▲ Show 20 Lines • Show All 1,488 Lines • Show Last 20 Lines |