diff options
author | Jeff Garzik <jgarzik@exmulti.com> | 2011-06-05 07:32:58 -0700 |
---|---|---|
committer | Jeff Garzik <jgarzik@exmulti.com> | 2011-06-05 07:32:58 -0700 |
commit | 09d1484b2293c9e1619fff29a9a41d520cda294b (patch) | |
tree | 5b9753f0c3de650ce4fc5d67aed8eda0fff354b1 /src | |
parent | e3d884479abcaf52ba6155755ce970998ce0622f (diff) | |
parent | ca253d591190255227e8c649b271503fdd1caf42 (diff) |
Merge pull request #264 from sipa/mintxfeefix
Fix for small change outputs
Diffstat (limited to 'src')
-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 6f3ef62deb..0456041ee5 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 |