diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2011-05-25 18:40:27 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2011-05-25 21:30:14 +0200 |
commit | ca253d591190255227e8c649b271503fdd1caf42 (patch) | |
tree | 2c07a63e8cf8b7648d9337bf16a5dc6809364f95 | |
parent | 69a27a4ec68e7a2ea6e481b950d11f5aea42c814 (diff) |
Fix for small change outputs
With the separation of CENT and MIN_TX_FEE, it is now reasonable
to create change outputs between 0.01 and 0.0005, as these are
spendable according to the policy, even though they require a fee
to be paid.
Also, when enough fee was already present, everything can go into
a change output, without further increasing the fee.
-rw-r--r-- | src/main.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp index 68b6b4ee1b..bd8f29c09b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3854,9 +3854,18 @@ bool CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CWalletTx& 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 |