Skip to content

Commit

Permalink
Clean up change computation in CreateTransaction.
Browse files Browse the repository at this point in the history
Compute the change directly as difference between the "requested" and
the actual value returned by SelectCoins.  This removes a duplication of
the fee logic code.
  • Loading branch information
domob1812 committed May 3, 2015
1 parent 90c37bc commit 835c122
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1757,9 +1757,9 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend,
nChangePosRet = -1;
bool fFirst = true;

CAmount nTotalValue = nValue;
CAmount nValueToSelect = nValue;
if (nSubtractFeeFromAmount == 0)
nTotalValue += nFeeRet;
nValueToSelect += nFeeRet;
double dPriority = 0;
// vouts to the payees
BOOST_FOREACH (const CRecipient& recipient, vecSend)
Expand Down Expand Up @@ -1796,7 +1796,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend,
// Choose coins to use
set<pair<const CWalletTx*,unsigned int> > setCoins;
CAmount nValueIn = 0;
if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl))
if (!SelectCoins(nValueToSelect, setCoins, nValueIn, coinControl))
{
strFailReason = _("Insufficient funds");
return false;
Expand All @@ -1814,10 +1814,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend,
dPriority += (double)nCredit * age;
}

CAmount nChange = nValueIn - nValue;
if (nSubtractFeeFromAmount == 0)
nChange -= nFeeRet;

const CAmount nChange = nValueIn - nValueToSelect;
if (nChange > 0)
{
// Fill a vout to ourself
Expand Down

0 comments on commit 835c122

Please sign in to comment.