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 18978 : CCoinControl::CCoinControl(CoinType coinType) 11 : : nCoinType{coinType} 12 9489 : { 13 : m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS); 14 9489 : } 15 : 16 1006944 : bool CCoinControl::HasSelected() const 17 : { 18 1006944 : return !m_selected_inputs.empty(); 19 : } 20 : 21 104287 : bool CCoinControl::IsSelected(const COutPoint& output) const 22 : { 23 104287 : return m_selected_inputs.count(output) > 0; 24 : } 25 : 26 583634 : bool CCoinControl::IsExternalSelected(const COutPoint& output) const 27 : { 28 583634 : return m_external_txouts.count(output) > 0; 29 : } 30 : 31 485 : std::optional<CTxOut> CCoinControl::GetExternalOutput(const COutPoint& outpoint) const 32 : { 33 485 : const auto ext_it = m_external_txouts.find(outpoint); 34 485 : if (ext_it == m_external_txouts.end()) { 35 0 : return std::nullopt; 36 : } 37 : 38 485 : return std::make_optional(ext_it->second); 39 485 : } 40 : 41 1642 : void CCoinControl::Select(const COutPoint& output) 42 : { 43 1642 : m_selected_inputs.insert(output); 44 1642 : } 45 : 46 134 : void CCoinControl::SelectExternal(const COutPoint& outpoint, const CTxOut& txout) 47 : { 48 134 : m_selected_inputs.insert(outpoint); 49 134 : m_external_txouts.emplace(outpoint, txout); 50 134 : } 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 14265 : std::vector<COutPoint> CCoinControl::ListSelected() const 63 : { 64 14265 : return {m_selected_inputs.begin(), m_selected_inputs.end()}; 65 : } 66 : 67 87 : void CCoinControl::SetInputWeight(const COutPoint& outpoint, int64_t weight) 68 : { 69 87 : m_input_weights[outpoint] = weight; 70 87 : } 71 : 72 57735 : bool CCoinControl::HasInputWeight(const COutPoint& outpoint) const 73 : { 74 57735 : return m_input_weights.count(outpoint) > 0; 75 : } 76 : 77 348 : int64_t CCoinControl::GetInputWeight(const COutPoint& outpoint) const 78 : { 79 348 : auto it = m_input_weights.find(outpoint); 80 348 : assert(it != m_input_weights.end()); 81 348 : return it->second; 82 : } 83 : } // namespace wallet