Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/coinselection.cpp
Show First 20 Lines • Show All 344 Lines • ▼ Show 20 Lines | |||||
OutputGroup | OutputGroup | ||||
******************************************************************************/ | ******************************************************************************/ | ||||
void OutputGroup::Insert(const CInputCoin &output, int depth, bool from_me, | void OutputGroup::Insert(const CInputCoin &output, int depth, bool from_me, | ||||
size_t ancestors, size_t descendants) { | size_t ancestors, size_t descendants) { | ||||
m_outputs.push_back(output); | m_outputs.push_back(output); | ||||
m_from_me &= from_me; | m_from_me &= from_me; | ||||
m_value += output.effective_value; | m_value += output.txout.nValue; | ||||
m_depth = std::min(m_depth, depth); | m_depth = std::min(m_depth, depth); | ||||
// ancestors here express the number of ancestors the new coin will end up | // ancestors here express the number of ancestors the new coin will end up | ||||
// having, which is the sum, rather than the max; this will overestimate in | // having, which is the sum, rather than the max; this will overestimate in | ||||
// the cases where multiple inputs have common ancestors | // the cases where multiple inputs have common ancestors | ||||
m_ancestors += ancestors; | m_ancestors += ancestors; | ||||
// descendants is the count as seen from the top ancestor, not the | // descendants is the count as seen from the top ancestor, not the | ||||
// descendants as seen from the coin itself; thus, this value is counted as | // descendants as seen from the coin itself; thus, this value is counted as | ||||
// the max, not the sum | // the max, not the sum | ||||
m_descendants = std::max(m_descendants, descendants); | m_descendants = std::max(m_descendants, descendants); | ||||
effective_value = m_value; | effective_value = m_value; | ||||
} | } | ||||
std::vector<CInputCoin>::iterator | std::vector<CInputCoin>::iterator | ||||
OutputGroup::Discard(const CInputCoin &output) { | OutputGroup::Discard(const CInputCoin &output) { | ||||
auto it = m_outputs.begin(); | auto it = m_outputs.begin(); | ||||
while (it != m_outputs.end() && it->outpoint != output.outpoint) { | while (it != m_outputs.end() && it->outpoint != output.outpoint) { | ||||
++it; | ++it; | ||||
} | } | ||||
if (it == m_outputs.end()) { | if (it == m_outputs.end()) { | ||||
return it; | return it; | ||||
} | } | ||||
m_value -= output.effective_value; | m_value -= output.txout.nValue; | ||||
effective_value -= output.effective_value; | effective_value -= output.effective_value; | ||||
return m_outputs.erase(it); | return m_outputs.erase(it); | ||||
} | } | ||||
bool OutputGroup::EligibleForSpending( | bool OutputGroup::EligibleForSpending( | ||||
const CoinEligibilityFilter &eligibility_filter) const { | const CoinEligibilityFilter &eligibility_filter) const { | ||||
return m_depth >= (m_from_me ? eligibility_filter.conf_mine | return m_depth >= (m_from_me ? eligibility_filter.conf_mine | ||||
: eligibility_filter.conf_theirs) && | : eligibility_filter.conf_theirs) && | ||||
m_ancestors <= eligibility_filter.max_ancestors && | m_ancestors <= eligibility_filter.max_ancestors && | ||||
m_descendants <= eligibility_filter.max_descendants; | m_descendants <= eligibility_filter.max_descendants; | ||||
} | } |