aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2011-07-24 08:08:33 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2011-07-24 08:08:33 -0700
commitb6d19aefa0cf455dca57ca74eeb75e158a9390d0 (patch)
treedab1d118e95d63a66438959d20f48a8cfec5cf18
parentc2da35319d7d9c2a28a2299d09176a0459cf7e00 (diff)
parenta7dd11c6dadeb17cf5444dd29f3a63d80ef4b159 (diff)
Merge pull request #428 from sipa/mintxfeefix
Fix for small change outputs
-rw-r--r--src/wallet.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 2ee918fdab..e9fa5a5207 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -941,9 +941,17 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CW
dPriority += (double)nCredit * pcoin.first->GetDepthInMainChain();
}
- // Fill a vout back to self with any change
- int64 nChange = nValueIn - nTotalValue;
- if (nChange >= CENT)
+ int64 nChange = nValueIn - nValue - nFeeRet;
+ // if sub-cent change is required, the fee must be raised to at least MIN_TX_FEE
+ // or until nChange becomes zero
+ if (nFeeRet < MIN_TX_FEE && nChange > 0 && nChange < CENT)
+ {
+ int64 nMoveToFee = min(nChange, MIN_TX_FEE - nFeeRet);
+ nChange -= nMoveToFee;
+ nFeeRet += nMoveToFee;
+ }
+
+ if (nChange > 0)
{
// Note: We use a new key here to keep it from being obvious which side is the change.
// The drawback is that by not reusing a previous key, the change may be lost if a