LCOV - code coverage report
Current view: top level - src/wallet - coincontrol.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 30 47 63.8 %
Date: 2023-11-10 23:46:46 Functions: 8 15 53.3 %
Branches: 6 14 42.9 %

           Branch data     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 <common/args.h>
       8                 :            : 
       9                 :            : namespace wallet {
      10                 :       6112 : CCoinControl::CCoinControl()
      11                 :            : {
      12 [ +  - ][ -  + ]:       1528 :     m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS);
      13                 :       1528 : }
      14                 :            : 
      15                 :     261001 : bool CCoinControl::HasSelected() const
      16                 :            : {
      17         [ +  - ]:     261003 :     return !m_selected_inputs.empty();
      18         [ +  - ]:          2 : }
      19                 :            : 
      20                 :     194204 : bool CCoinControl::IsSelected(const COutPoint& output) const
      21                 :            : {
      22                 :     194204 :     return m_selected_inputs.count(output) > 0;
      23                 :            : }
      24                 :            : 
      25                 :      48108 : bool CCoinControl::IsExternalSelected(const COutPoint& output) const
      26                 :            : {
      27                 :      48108 :     return m_external_txouts.count(output) > 0;
      28                 :            : }
      29                 :            : 
      30                 :        428 : std::optional<CTxOut> CCoinControl::GetExternalOutput(const COutPoint& outpoint) const
      31                 :            : {
      32                 :       1956 :     const auto ext_it = m_external_txouts.find(outpoint);
      33         [ +  - ]:        428 :     if (ext_it == m_external_txouts.end()) {
      34                 :        428 :         return std::nullopt;
      35                 :            :     }
      36                 :       1528 : 
      37                 :          0 :     return std::make_optional(ext_it->second);
      38                 :        428 : }
      39                 :       1528 : 
      40                 :      41336 : void CCoinControl::Select(const COutPoint& output)
      41                 :       1528 : {
      42                 :      41336 :     m_selected_inputs.insert(output);
      43                 :      42864 : }
      44                 :            : 
      45                 :          0 : void CCoinControl::SelectExternal(const COutPoint& outpoint, const CTxOut& txout)
      46                 :            : {
      47                 :          0 :     m_selected_inputs.insert(outpoint);
      48                 :          0 :     m_external_txouts.emplace(outpoint, txout);
      49                 :          0 : }
      50                 :            : 
      51                 :       1528 : void CCoinControl::UnSelect(const COutPoint& output)
      52                 :            : {
      53                 :       1528 :     m_selected_inputs.erase(output);
      54                 :          0 : }
      55                 :       1528 : 
      56                 :          0 : void CCoinControl::UnSelectAll()
      57                 :       1528 : {
      58                 :          0 :     m_selected_inputs.clear();
      59                 :       1528 : }
      60                 :            : 
      61                 :      13996 : std::vector<COutPoint> CCoinControl::ListSelected() const
      62                 :            : {
      63         [ +  - ]:      13996 :     return {m_selected_inputs.begin(), m_selected_inputs.end()};
      64                 :          0 : }
      65                 :            : 
      66                 :          0 : void CCoinControl::SetInputWeight(const COutPoint& outpoint, int64_t weight)
      67                 :            : {
      68                 :          0 :     m_input_weights[outpoint] = weight;
      69                 :          0 : }
      70                 :            : 
      71                 :     145740 : bool CCoinControl::HasInputWeight(const COutPoint& outpoint) const
      72                 :            : {
      73                 :     145740 :     return m_input_weights.count(outpoint) > 0;
      74                 :            : }
      75                 :            : 
      76                 :          0 : int64_t CCoinControl::GetInputWeight(const COutPoint& outpoint) const
      77                 :            : {
      78                 :          0 :     auto it = m_input_weights.find(outpoint);
      79         [ #  # ]:          0 :     assert(it != m_input_weights.end());
      80                 :          0 :     return it->second;
      81                 :            : }
      82                 :            : } // namespace wallet

Generated by: LCOV version 1.14