Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,591 Lines • ▼ Show 20 Lines | bool CWallet::SelectCoinsMinConf( | ||||
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 (!OutputEligibleForSpending(output, eligibility_filter)) { | if (!OutputEligibleForSpending(output, eligibility_filter)) { | ||||
continue; | continue; | ||||
} | } | ||||
CInputCoin coin = CInputCoin(output.tx, output.i); | CInputCoin coin = CInputCoin(output.tx->tx, output.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 76 Lines • ▼ Show 20 Lines | bool CWallet::SelectCoins(const std::vector<COutput> &vAvailableCoins, | ||||
if (coinControl && coinControl->HasSelected() && | if (coinControl && coinControl->HasSelected() && | ||||
!coinControl->fAllowOtherInputs) { | !coinControl->fAllowOtherInputs) { | ||||
for (const COutput &out : vCoins) { | for (const COutput &out : vCoins) { | ||||
if (!out.fSpendable) { | if (!out.fSpendable) { | ||||
continue; | continue; | ||||
} | } | ||||
nValueRet += out.tx->tx->vout[out.i].nValue; | nValueRet += out.tx->tx->vout[out.i].nValue; | ||||
setCoinsRet.insert(CInputCoin(out.tx, out.i)); | setCoinsRet.insert(CInputCoin(out.tx->tx, out.i)); | ||||
} | } | ||||
return (nValueRet >= nTargetValue); | return (nValueRet >= nTargetValue); | ||||
} | } | ||||
// Calculate value from preset inputs and store them. | // Calculate value from preset inputs and store them. | ||||
std::set<CInputCoin> setPresetCoins; | std::set<CInputCoin> setPresetCoins; | ||||
Amount nValueFromPresetInputs = Amount::zero(); | Amount nValueFromPresetInputs = Amount::zero(); | ||||
Show All 13 Lines | for (const COutPoint &outpoint : vPresetInputs) { | ||||
const CWalletTx *pcoin = &it->second; | const CWalletTx *pcoin = &it->second; | ||||
// Clearly invalid input, fail. | // Clearly invalid input, fail. | ||||
if (pcoin->tx->vout.size() <= outpoint.GetN()) { | if (pcoin->tx->vout.size() <= outpoint.GetN()) { | ||||
return false; | return false; | ||||
} | } | ||||
nValueFromPresetInputs += pcoin->tx->vout[outpoint.GetN()].nValue; | nValueFromPresetInputs += pcoin->tx->vout[outpoint.GetN()].nValue; | ||||
setPresetCoins.insert(CInputCoin(pcoin, outpoint.GetN())); | setPresetCoins.insert(CInputCoin(pcoin->tx, outpoint.GetN())); | ||||
} | } | ||||
// Remove preset inputs from vCoins. | // Remove preset inputs from vCoins. | ||||
for (std::vector<COutput>::iterator it = vCoins.begin(); | for (std::vector<COutput>::iterator it = vCoins.begin(); | ||||
it != vCoins.end() && coinControl && coinControl->HasSelected();) { | it != vCoins.end() && coinControl && coinControl->HasSelected();) { | ||||
if (setPresetCoins.count(CInputCoin(it->tx, it->i))) { | if (setPresetCoins.count(CInputCoin(it->tx->tx, it->i))) { | ||||
it = vCoins.erase(it); | it = vCoins.erase(it); | ||||
} else { | } else { | ||||
++it; | ++it; | ||||
} | } | ||||
} | } | ||||
size_t nMaxChainLength = std::min( | size_t nMaxChainLength = std::min( | ||||
gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT), | gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT), | ||||
▲ Show 20 Lines • Show All 1,818 Lines • Show Last 20 Lines |