mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
when Darksend is unchecked select nondenom inputs first - for v11
This commit is contained in:
parent
692ec7c328
commit
f77b2d5943
124
src/wallet.cpp
124
src/wallet.cpp
@ -1249,6 +1249,23 @@ static void ApproximateBestSubset(vector<pair<int64_t, pair<const CWalletTx*,uns
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: find appropriate place for this sort function
|
||||||
|
// move denoms down
|
||||||
|
bool less_then_denom (const COutput& out1, const COutput& out2)
|
||||||
|
{
|
||||||
|
const CWalletTx *pcoin1 = out1.tx;
|
||||||
|
const CWalletTx *pcoin2 = out2.tx;
|
||||||
|
|
||||||
|
bool found1 = false;
|
||||||
|
bool found2 = false;
|
||||||
|
BOOST_FOREACH(int64_t d, darkSendDenominations) // loop through predefined denoms
|
||||||
|
{
|
||||||
|
if(pcoin1->vout[out1.i].nValue == d) found1 = true;
|
||||||
|
if(pcoin2->vout[out2.i].nValue == d) found2 = true;
|
||||||
|
}
|
||||||
|
return (!found1 && found2);
|
||||||
|
}
|
||||||
|
|
||||||
bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfTheirs, vector<COutput> vCoins,
|
bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfTheirs, vector<COutput> vCoins,
|
||||||
set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const
|
set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const
|
||||||
{
|
{
|
||||||
@ -1264,52 +1281,85 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfT
|
|||||||
|
|
||||||
random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt);
|
random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt);
|
||||||
|
|
||||||
BOOST_FOREACH(COutput output, vCoins)
|
// move denoms down on the list
|
||||||
|
sort(vCoins.begin(), vCoins.end(), less_then_denom);
|
||||||
|
|
||||||
|
// try to find nondenom first to prevent unneeded spending of mixed coins
|
||||||
|
for (unsigned int tryDenom = 0; tryDenom < 2; tryDenom++)
|
||||||
{
|
{
|
||||||
const CWalletTx *pcoin = output.tx;
|
if (fDebug) LogPrint("selectcoins", "tryDenom: %d\n", tryDenom);
|
||||||
|
setCoinsRet.clear();
|
||||||
|
nValueRet = 0;
|
||||||
|
nTotalLower = 0;
|
||||||
|
|
||||||
if (output.nDepth < (pcoin->IsFromMe() ? nConfMine : nConfTheirs))
|
BOOST_FOREACH(COutput output, vCoins)
|
||||||
continue;
|
|
||||||
|
|
||||||
int i = output.i;
|
|
||||||
int64_t n = pcoin->vout[i].nValue;
|
|
||||||
|
|
||||||
pair<int64_t,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin, i));
|
|
||||||
|
|
||||||
if (n == nTargetValue)
|
|
||||||
{
|
{
|
||||||
setCoinsRet.insert(coin.second);
|
const CWalletTx *pcoin = output.tx;
|
||||||
nValueRet += coin.first;
|
|
||||||
|
// if (fDebug) LogPrint("selectcoins", "value %s confirms %d\n", FormatMoney(pcoin->vout[output.i].nValue), output.nDepth);
|
||||||
|
if (output.nDepth < (pcoin->IsFromMe() ? nConfMine : nConfTheirs))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int i = output.i;
|
||||||
|
int64_t n = pcoin->vout[i].nValue;
|
||||||
|
|
||||||
|
if (tryDenom == 0) // first run?
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
BOOST_FOREACH(int64_t d, darkSendDenominations) // loop through predefined denoms
|
||||||
|
if(n == d)
|
||||||
|
found = true;
|
||||||
|
if (found) continue; // we don't want denom values on first run
|
||||||
|
}
|
||||||
|
|
||||||
|
pair<int64_t,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin, i));
|
||||||
|
|
||||||
|
if (n == nTargetValue)
|
||||||
|
{
|
||||||
|
setCoinsRet.insert(coin.second);
|
||||||
|
nValueRet += coin.first;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (n < nTargetValue + CENT)
|
||||||
|
{
|
||||||
|
vValue.push_back(coin);
|
||||||
|
nTotalLower += n;
|
||||||
|
}
|
||||||
|
else if (n < coinLowestLarger.first)
|
||||||
|
{
|
||||||
|
coinLowestLarger = coin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nTotalLower == nTargetValue)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < vValue.size(); ++i)
|
||||||
|
{
|
||||||
|
setCoinsRet.insert(vValue[i].second);
|
||||||
|
nValueRet += vValue[i].first;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (n < nTargetValue + CENT)
|
|
||||||
{
|
|
||||||
vValue.push_back(coin);
|
|
||||||
nTotalLower += n;
|
|
||||||
}
|
|
||||||
else if (n < coinLowestLarger.first)
|
|
||||||
{
|
|
||||||
coinLowestLarger = coin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nTotalLower == nTargetValue)
|
if (nTotalLower < nTargetValue)
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < vValue.size(); ++i)
|
|
||||||
{
|
{
|
||||||
setCoinsRet.insert(vValue[i].second);
|
if (coinLowestLarger.second.first == NULL) // there is no input larger than nTargetValue
|
||||||
nValueRet += vValue[i].first;
|
{
|
||||||
|
if (tryDenom == 0)
|
||||||
|
// we didn't look at denom yet, let's do it
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
// we looked at everything possible and didn't find anything, no luck
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
setCoinsRet.insert(coinLowestLarger.second);
|
||||||
|
nValueRet += coinLowestLarger.first;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nTotalLower < nTargetValue)
|
// nTotalLower > nTargetValue
|
||||||
{
|
break;
|
||||||
if (coinLowestLarger.second.first == NULL)
|
|
||||||
return false;
|
|
||||||
setCoinsRet.insert(coinLowestLarger.second);
|
|
||||||
nValueRet += coinLowestLarger.first;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Solve subset sum by stochastic approximation
|
// Solve subset sum by stochastic approximation
|
||||||
|
Loading…
Reference in New Issue
Block a user