Mercurial > hg > bitcoin
changeset 457:d506e7ed9b6b draft
Bugfix: avoid sub-cent change (lost in fees) whenever possible
author | Luke Dashjr <luke-jr+git@utopios.org> |
---|---|
date | Fri, 28 Jan 2011 14:39:31 -0500 |
parents | 489d0c2d7a7c |
children | 217a626c9a82 |
files | main.cpp |
diffstat | 1 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/main.cpp +++ b/main.cpp @@ -3750,16 +3750,16 @@ int64 n = pcoin->GetCredit(); if (n <= 0) continue; - if (n < nTargetValue) + if (n == nTargetValue) + { + setCoinsRet.insert(pcoin); + return true; + } + else if (n < nTargetValue + CENT) { vValue.push_back(make_pair(n, pcoin)); nTotalLower += n; } - else if (n == nTargetValue) - { - setCoinsRet.insert(pcoin); - return true; - } else if (n < nLowestLarger) { nLowestLarger = n; @@ -3768,7 +3768,14 @@ } } - if (nTotalLower < nTargetValue) + if (nTotalLower == nTargetValue || nTotalLower == nTargetValue + CENT) + { + for (int i = 0; i < vValue.size(); ++i) + setCoinsRet.insert(vValue[i].second); + return true; + } + + if (nTotalLower < nTargetValue + (pcoinLowestLarger ? CENT : 0)) { if (pcoinLowestLarger == NULL) return false; @@ -3776,6 +3783,9 @@ return true; } + if (nTotalLower >= nTargetValue + CENT) + nTargetValue += CENT; + // Solve subset sum by stochastic approximation sort(vValue.rbegin(), vValue.rend()); vector<char> vfIncluded;