Inside Bitcoin
Opening the selected file…
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.
1// Copyright (c) 2018-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <wallet/coincontrol.h>7#include <common/args.h>9namespace wallet {10CCoinControl::CCoinControl()11{12m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS);13}15bool CCoinControl::HasSelected() const16{17return !m_selected.empty();18}20bool CCoinControl::IsSelected(const COutPoint& outpoint) const21{22return m_selected.contains(outpoint);23}25bool CCoinControl::IsExternalSelected(const COutPoint& outpoint) const26{27const auto it = m_selected.find(outpoint);28return it != m_selected.end() && it->second.HasTxOut();29}31std::optional<CTxOut> CCoinControl::GetExternalOutput(const COutPoint& outpoint) const32{33const auto it = m_selected.find(outpoint);34if (it == m_selected.end() || !it->second.HasTxOut()) {35return std::nullopt;36}37return it->second.GetTxOut();38}40PreselectedInput& CCoinControl::Select(const COutPoint& outpoint)41{42auto& input = m_selected[outpoint];43input.SetPosition(m_selection_pos);44++m_selection_pos;45return input;46}47void CCoinControl::UnSelect(const COutPoint& outpoint)48{49m_selected.erase(outpoint);50}52void CCoinControl::UnSelectAll()53{54m_selected.clear();55}57std::vector<COutPoint> CCoinControl::ListSelected() const58{59std::vector<COutPoint> outpoints;60std::transform(m_selected.begin(), m_selected.end(), std::back_inserter(outpoints),61[](const std::map<COutPoint, PreselectedInput>::value_type& pair) {62return pair.first;63});64return outpoints;65}67void CCoinControl::SetInputWeight(const COutPoint& outpoint, int64_t weight)68{69m_selected[outpoint].SetInputWeight(weight);70}72std::optional<int64_t> CCoinControl::GetInputWeight(const COutPoint& outpoint) const73{74const auto it = m_selected.find(outpoint);75return it != m_selected.end() ? it->second.GetInputWeight() : std::nullopt;76}78std::optional<uint32_t> CCoinControl::GetSequence(const COutPoint& outpoint) const79{80const auto it = m_selected.find(outpoint);81return it != m_selected.end() ? it->second.GetSequence() : std::nullopt;82}84std::pair<std::optional<CScript>, std::optional<CScriptWitness>> CCoinControl::GetScripts(const COutPoint& outpoint) const85{86const auto it = m_selected.find(outpoint);87return it != m_selected.end() ? m_selected.at(outpoint).GetScripts() : std::make_pair(std::nullopt, std::nullopt);88}90void PreselectedInput::SetTxOut(const CTxOut& txout)91{92m_txout = txout;93}95CTxOut PreselectedInput::GetTxOut() const96{97assert(m_txout.has_value());98return m_txout.value();99}101bool PreselectedInput::HasTxOut() const102{103return m_txout.has_value();104}106void PreselectedInput::SetInputWeight(int64_t weight)107{108m_weight = weight;109}111std::optional<int64_t> PreselectedInput::GetInputWeight() const112{113return m_weight;114}116void PreselectedInput::SetSequence(uint32_t sequence)117{118m_sequence = sequence;119}121std::optional<uint32_t> PreselectedInput::GetSequence() const122{123return m_sequence;124}126void PreselectedInput::SetScriptSig(const CScript& script)127{128m_script_sig = script;129}131void PreselectedInput::SetScriptWitness(const CScriptWitness& script_wit)132{133m_script_witness = script_wit;134}136bool PreselectedInput::HasScripts() const137{138return m_script_sig.has_value() || m_script_witness.has_value();139}141std::pair<std::optional<CScript>, std::optional<CScriptWitness>> PreselectedInput::GetScripts() const142{143return {m_script_sig, m_script_witness};144}146void PreselectedInput::SetPosition(unsigned int pos)147{148m_pos = pos;149}151std::optional<unsigned int> PreselectedInput::GetPosition() const152{153return m_pos;154}155} // namespace wallet