diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2011-01-28 14:39:31 -0500 |
---|---|---|
committer | tcatm <tcatm@gawab.com> | 2011-03-01 02:10:07 +0100 |
commit | a14bf1946dfade7c615cd41924c7cd41abdbc119 (patch) | |
tree | adf370cae99e129f777d46e8cf38fca22964664a /main.cpp | |
parent | 6665aca02421e62c194dd8291b4ab7c91eea72c7 (diff) |
Bugfix: avoid sub-cent change (lost in fees) whenever possible
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -3750,16 +3750,16 @@ bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, set< int64 n = pcoin->GetCredit(); if (n <= 0) continue; - if (n < nTargetValue) - { - vValue.push_back(make_pair(n, pcoin)); - nTotalLower += n; - } - else 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 < nLowestLarger) { nLowestLarger = n; @@ -3768,7 +3768,14 @@ bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, set< } } - 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 @@ bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, set< return true; } + if (nTotalLower >= nTargetValue + CENT) + nTargetValue += CENT; + // Solve subset sum by stochastic approximation sort(vValue.rbegin(), vValue.rend()); vector<char> vfIncluded; |