Browse Source

Merge #9343: Don't create change at dust limit

6171826 Don't create change at the dust limit, even if it means paying more than expected (Alex Morcos)

Tree-SHA512: d4cf939b97a92d63d4703ad152093c9dc60e74af590697bc21adbcdf17fc9e6ffb37d46d5eefafbd69327d1bcb79911f1b826ce1d960d895d464c4408c4995c3
0.15
Wladimir J. van der Laan 8 years ago
parent
commit
209eef60a9
No known key found for this signature in database
GPG Key ID: 1E4AED62986CD25D
  1. 7
      src/qt/coincontroldialog.cpp
  2. 22
      src/wallet/wallet.cpp

7
src/qt/coincontroldialog.cpp

@ -523,14 +523,11 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) @@ -523,14 +523,11 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
{
CTxOut txout(nChange, (CScript)std::vector<unsigned char>(24, 0));
if (IsDust(txout, ::dustRelayFee))
{
if (CoinControlDialog::fSubtractFeeFromAmount) // dust-change will be raised until no dust
nChange = GetDustThreshold(txout, ::dustRelayFee);
else
{
nPayFee += nChange;
nChange = 0;
}
if (CoinControlDialog::fSubtractFeeFromAmount)
nBytes -= 34; // we didn't detect lack of change above
}
}

22
src/wallet/wallet.cpp

@ -2633,28 +2633,6 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT @@ -2633,28 +2633,6 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
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))
{
CAmount nDust = GetDustThreshold(newTxOut, ::dustRelayFee) - newTxOut.nValue;
newTxOut.nValue += nDust; // raise change until no more dust
for (unsigned int i = 0; i < vecSend.size(); i++) // subtract from first recipient
{
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 the fee.
if (IsDust(newTxOut, ::dustRelayFee))

Loading…
Cancel
Save