Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,550 Lines • ▼ Show 20 Lines | for (int nRep = 0; nRep < iterations && nBest != nTargetValue; nRep++) { | ||||
vfIncluded[i] = false; | vfIncluded[i] = false; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
bool CWallet::OutputEligibleForSpending(const COutput &output, | |||||
const int nConfMine, | |||||
const int nConfTheirs, | |||||
const uint64_t nMaxAncestors) const { | |||||
if (!output.fSpendable) { | |||||
return false; | |||||
} | |||||
if (output.nDepth < | |||||
(output.tx->IsFromMe(ISMINE_ALL) ? nConfMine : nConfTheirs)) { | |||||
return false; | |||||
} | |||||
if (!g_mempool.TransactionWithinChainLimit(output.tx->GetId(), | |||||
nMaxAncestors)) { | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
bool CWallet::SelectCoinsMinConf(const Amount nTargetValue, const int nConfMine, | bool CWallet::SelectCoinsMinConf(const Amount nTargetValue, const int nConfMine, | ||||
const int nConfTheirs, | const int nConfTheirs, | ||||
const uint64_t nMaxAncestors, | const uint64_t nMaxAncestors, | ||||
std::vector<COutput> vCoins, | std::vector<COutput> vCoins, | ||||
std::set<CInputCoin> &setCoinsRet, | std::set<CInputCoin> &setCoinsRet, | ||||
Amount &nValueRet) const { | Amount &nValueRet) const { | ||||
setCoinsRet.clear(); | setCoinsRet.clear(); | ||||
nValueRet = Amount::zero(); | nValueRet = Amount::zero(); | ||||
// List of values less than target | // List of values less than target | ||||
boost::optional<CInputCoin> coinLowestLarger; | boost::optional<CInputCoin> coinLowestLarger; | ||||
std::vector<CInputCoin> vValue; | std::vector<CInputCoin> vValue; | ||||
Amount nTotalLower = Amount::zero(); | Amount nTotalLower = Amount::zero(); | ||||
random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt); | random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt); | ||||
for (const COutput &output : vCoins) { | for (const COutput &output : vCoins) { | ||||
if (!output.fSpendable) { | if (!OutputEligibleForSpending(output, nConfMine, nConfTheirs, | ||||
continue; | |||||
} | |||||
const CWalletTx *pcoin = output.tx; | |||||
if (output.nDepth < | |||||
(pcoin->IsFromMe(ISMINE_ALL) ? nConfMine : nConfTheirs)) { | |||||
continue; | |||||
} | |||||
if (!g_mempool.TransactionWithinChainLimit(pcoin->GetId(), | |||||
nMaxAncestors)) { | nMaxAncestors)) { | ||||
continue; | continue; | ||||
} | } | ||||
int i = output.i; | CInputCoin coin = CInputCoin(output.tx, output.i); | ||||
CInputCoin coin = CInputCoin(pcoin, i); | |||||
if (coin.txout.nValue == nTargetValue) { | if (coin.txout.nValue == nTargetValue) { | ||||
setCoinsRet.insert(coin); | setCoinsRet.insert(coin); | ||||
nValueRet += coin.txout.nValue; | nValueRet += coin.txout.nValue; | ||||
return true; | return true; | ||||
} else if (coin.txout.nValue < nTargetValue + MIN_CHANGE) { | } else if (coin.txout.nValue < nTargetValue + MIN_CHANGE) { | ||||
vValue.push_back(coin); | vValue.push_back(coin); | ||||
nTotalLower += coin.txout.nValue; | nTotalLower += coin.txout.nValue; | ||||
▲ Show 20 Lines • Show All 1,941 Lines • Show Last 20 Lines |