Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1001m_target += other.m_target;1002m_use_effective |= other.m_use_effective;1003if (m_algo == SelectionAlgorithm::MANUAL) {1004m_algo = other.m_algo;1005}1007m_weight += other.m_weight;1008}1010const OutputSet& SelectionResult::GetInputSet() const1011{1012return m_selected_inputs;1013}1015std::vector<std::shared_ptr<COutput>> SelectionResult::GetShuffledInputVector() const1016{1017std::vector<std::shared_ptr<COutput>> coins(m_selected_inputs.begin(), m_selected_inputs.end());1018std::shuffle(coins.begin(), coins.end(), FastRandomContext());1019return coins;1020}1022bool SelectionResult::operator<(SelectionResult other) const1023{1024Assert(m_waste.has_value());1025Assert(other.m_waste.has_value());1026// As this operator is only used in std::min_element, we want the result that has more inputs when waste are equal.1027return *m_waste < *other.m_waste || (*m_waste == *other.m_waste && m_selected_inputs.size() > other.m_selected_inputs.size());1028}1030std::string GetAlgorithmName(const SelectionAlgorithm algo)1031{1032switch (algo)1033{1034case SelectionAlgorithm::BNB: return "bnb";1035case SelectionAlgorithm::KNAPSACK: return "knapsack";1036case SelectionAlgorithm::SRD: return "srd";1037case SelectionAlgorithm::CG: return "cg";1038case SelectionAlgorithm::MANUAL: return "manual";1039} // no default case, so the compiler can warn about missing cases1040assert(false);1041}1043CAmount SelectionResult::GetChange(const CAmount min_viable_change, const CAmount change_fee) const1044{1045// change = SUM(inputs) - SUM(outputs) - fees1046// 1) With SFFO we don't pay any fees1047// 2) Otherwise we pay all the fees:1048// - input fees are covered by GetSelectedEffectiveValue()1049// - non_input_fee is included in m_target1050// - change_fee1051const CAmount change = m_use_effective1052? GetSelectedEffectiveValue() - m_target - change_fee1053: GetSelectedValue() - m_target;1055if (change < min_viable_change) {1056return 0;1057}1059return change;1060}1062} // namespace wallet