aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
diff options
context:
space:
mode:
authorDaniel Kraft <d@domob.eu>2015-03-18 19:22:49 +0100
committerDaniel Kraft <d@domob.eu>2015-05-03 10:56:48 +0200
commit835c12291efc2ca03017622fe970218fdeb63727 (patch)
treea88e65ce9d66f515d54c2a0329e55d46f841877f /src/wallet/wallet.cpp
parent90c37bc16c3416f133fb15b726873960e00f2262 (diff)
downloadbitcoin-835c12291efc2ca03017622fe970218fdeb63727.tar.xz
Clean up change computation in CreateTransaction.
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.
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r--src/wallet/wallet.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index bb73038b97..75337d4a7d 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -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)
@@ -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;
@@ -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