Line data Source code
1 : // Copyright (c) 2018-2021 The Bitcoin Core developers 2 : // Distributed under the MIT software license, see the accompanying 3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 : 5 : #include <wallet/coincontrol.h> 6 : 7 : #include <util/system.h> 8 : 9 : namespace wallet { 10 258 : CCoinControl::CCoinControl(CoinType coinType) 11 : : nCoinType{coinType} 12 129 : { 13 : m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS); 14 129 : } 15 : 16 4356 : bool CCoinControl::HasSelected() const 17 : { 18 4356 : return !m_selected_inputs.empty(); 19 : } 20 : 21 1778 : bool CCoinControl::IsSelected(const COutPoint& output) const 22 : { 23 1778 : return m_selected_inputs.count(output) > 0; 24 : } 25 : 26 3202 : bool CCoinControl::IsExternalSelected(const COutPoint& output) const 27 : { 28 3202 : return m_external_txouts.count(output) > 0; 29 : } 30 : 31 0 : std::optional<CTxOut> CCoinControl::GetExternalOutput(const COutPoint& outpoint) const 32 : { 33 0 : const auto ext_it = m_external_txouts.find(outpoint); 34 0 : if (ext_it == m_external_txouts.end()) { 35 0 : return std::nullopt; 36 : } 37 : 38 0 : return std::make_optional(ext_it->second); 39 0 : } 40 : 41 28 : void CCoinControl::Select(const COutPoint& output) 42 : { 43 28 : m_selected_inputs.insert(output); 44 28 : } 45 : 46 0 : void CCoinControl::SelectExternal(const COutPoint& outpoint, const CTxOut& txout) 47 : { 48 0 : m_selected_inputs.insert(outpoint); 49 0 : m_external_txouts.emplace(outpoint, txout); 50 0 : } 51 : 52 0 : void CCoinControl::UnSelect(const COutPoint& output) 53 : { 54 0 : m_selected_inputs.erase(output); 55 0 : } 56 : 57 0 : void CCoinControl::UnSelectAll() 58 : { 59 0 : m_selected_inputs.clear(); 60 0 : } 61 : 62 330 : std::vector<COutPoint> CCoinControl::ListSelected() const 63 : { 64 330 : return {m_selected_inputs.begin(), m_selected_inputs.end()}; 65 : } 66 : 67 0 : void CCoinControl::SetInputWeight(const COutPoint& outpoint, int64_t weight) 68 : { 69 0 : m_input_weights[outpoint] = weight; 70 0 : } 71 : 72 1687 : bool CCoinControl::HasInputWeight(const COutPoint& outpoint) const 73 : { 74 1687 : return m_input_weights.count(outpoint) > 0; 75 : } 76 : 77 0 : int64_t CCoinControl::GetInputWeight(const COutPoint& outpoint) const 78 : { 79 0 : auto it = m_input_weights.find(outpoint); 80 0 : assert(it != m_input_weights.end()); 81 0 : return it->second; 82 : } 83 : } // namespace wallet