Skip to content

Commit

Permalink
Merge pull request #428 from sipa/mintxfeefix
Browse files Browse the repository at this point in the history
Fix for small change outputs
  • Loading branch information
sipa committed Jul 24, 2011
2 parents c2da353 + a7dd11c commit b6d19ae
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b6d19ae

Please sign in to comment.