LCOV - code coverage report
Current view: top level - src/wallet - coincontrol.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 96.4 % 84 81
Test Date: 2024-07-04 04:02:30 Functions: 96.3 % 27 26
Branches: 69.2 % 26 18

             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                 :      200137 : CCoinControl::CCoinControl()
      11                 :             : {
      12   [ +  -  +  - ]:      200137 :     m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS);
      13                 :           0 : }
      14                 :             : 
      15                 :    24112439 : bool CCoinControl::HasSelected() const
      16                 :             : {
      17                 :    24112439 :     return !m_selected.empty();
      18                 :             : }
      19                 :             : 
      20                 :    23992792 : bool CCoinControl::IsSelected(const COutPoint& outpoint) const
      21                 :             : {
      22                 :    23992792 :     return m_selected.count(outpoint) > 0;
      23                 :             : }
      24                 :             : 
      25                 :       75665 : bool CCoinControl::IsExternalSelected(const COutPoint& outpoint) const
      26                 :             : {
      27                 :       75665 :     const auto it = m_selected.find(outpoint);
      28         [ +  + ]:       75665 :     return it != m_selected.end() && it->second.HasTxOut();
      29                 :       75665 : }
      30                 :             : 
      31                 :       27860 : std::optional<CTxOut> CCoinControl::GetExternalOutput(const COutPoint& outpoint) const
      32                 :             : {
      33                 :       27860 :     const auto it = m_selected.find(outpoint);
      34   [ +  +  +  + ]:       27860 :     if (it == m_selected.end() || !it->second.HasTxOut()) {
      35                 :       10023 :         return std::nullopt;
      36                 :             :     }
      37                 :       17837 :     return it->second.GetTxOut();
      38                 :       27860 : }
      39                 :             : 
      40                 :      416837 : PreselectedInput& CCoinControl::Select(const COutPoint& outpoint)
      41                 :             : {
      42                 :      416837 :     auto& input = m_selected[outpoint];
      43                 :      416837 :     input.SetPosition(m_selection_pos);
      44                 :      416837 :     ++m_selection_pos;
      45                 :      833674 :     return input;
      46                 :      416837 : }
      47                 :       71554 : void CCoinControl::UnSelect(const COutPoint& outpoint)
      48                 :             : {
      49                 :       71554 :     m_selected.erase(outpoint);
      50                 :       71554 : }
      51                 :             : 
      52                 :        2104 : void CCoinControl::UnSelectAll()
      53                 :             : {
      54                 :        2104 :     m_selected.clear();
      55                 :        2104 : }
      56                 :             : 
      57                 :      166784 : std::vector<COutPoint> CCoinControl::ListSelected() const
      58                 :             : {
      59                 :      166784 :     std::vector<COutPoint> outpoints;
      60   [ +  -  +  - ]:      166784 :     std::transform(m_selected.begin(), m_selected.end(), std::back_inserter(outpoints),
      61                 :     1436572 :         [](const std::map<COutPoint, PreselectedInput>::value_type& pair) {
      62                 :     1436572 :             return pair.first;
      63                 :             :         });
      64                 :      166784 :     return outpoints;
      65         [ +  - ]:      166784 : }
      66                 :             : 
      67                 :        5787 : void CCoinControl::SetInputWeight(const COutPoint& outpoint, int64_t weight)
      68                 :             : {
      69                 :        5787 :     m_selected[outpoint].SetInputWeight(weight);
      70                 :        5787 : }
      71                 :             : 
      72                 :      353250 : std::optional<int64_t> CCoinControl::GetInputWeight(const COutPoint& outpoint) const
      73                 :             : {
      74                 :      353250 :     const auto it = m_selected.find(outpoint);
      75         [ +  + ]:      353250 :     return it != m_selected.end() ? it->second.GetInputWeight() : std::nullopt;
      76                 :      353250 : }
      77                 :             : 
      78                 :      167336 : std::optional<uint32_t> CCoinControl::GetSequence(const COutPoint& outpoint) const
      79                 :             : {
      80                 :      167336 :     const auto it = m_selected.find(outpoint);
      81         [ +  + ]:      167336 :     return it != m_selected.end() ? it->second.GetSequence() : std::nullopt;
      82                 :      167336 : }
      83                 :             : 
      84                 :      167336 : std::pair<std::optional<CScript>, std::optional<CScriptWitness>> CCoinControl::GetScripts(const COutPoint& outpoint) const
      85                 :             : {
      86                 :      167336 :     const auto it = m_selected.find(outpoint);
      87         [ +  + ]:      167336 :     return it != m_selected.end() ? m_selected.at(outpoint).GetScripts() : std::make_pair(std::nullopt, std::nullopt);
      88                 :      167336 : }
      89                 :             : 
      90                 :       44129 : void PreselectedInput::SetTxOut(const CTxOut& txout)
      91                 :             : {
      92                 :       44129 :     m_txout = txout;
      93                 :       44129 : }
      94                 :             : 
      95                 :       17837 : CTxOut PreselectedInput::GetTxOut() const
      96                 :             : {
      97         [ +  - ]:       17837 :     assert(m_txout.has_value());
      98                 :       17837 :     return m_txout.value();
      99                 :             : }
     100                 :             : 
     101                 :       66212 : bool PreselectedInput::HasTxOut() const
     102                 :             : {
     103                 :       66212 :     return m_txout.has_value();
     104                 :             : }
     105                 :             : 
     106                 :        5787 : void PreselectedInput::SetInputWeight(int64_t weight)
     107                 :             : {
     108                 :        5787 :     m_weight = weight;
     109                 :        5787 : }
     110                 :             : 
     111                 :      305568 : std::optional<int64_t> PreselectedInput::GetInputWeight() const
     112                 :             : {
     113                 :      305568 :     return m_weight;
     114                 :             : }
     115                 :             : 
     116                 :      230042 : void PreselectedInput::SetSequence(uint32_t sequence)
     117                 :             : {
     118                 :      230042 :     m_sequence = sequence;
     119                 :      230042 : }
     120                 :             : 
     121                 :      124381 : std::optional<uint32_t> PreselectedInput::GetSequence() const
     122                 :             : {
     123                 :      124381 :     return m_sequence;
     124                 :             : }
     125                 :             : 
     126                 :      230042 : void PreselectedInput::SetScriptSig(const CScript& script)
     127                 :             : {
     128                 :      230042 :     m_script_sig = script;
     129                 :      230042 : }
     130                 :             : 
     131                 :      230042 : void PreselectedInput::SetScriptWitness(const CScriptWitness& script_wit)
     132                 :             : {
     133                 :      230042 :     m_script_witness = script_wit;
     134                 :      230042 : }
     135                 :             : 
     136                 :           0 : bool PreselectedInput::HasScripts() const
     137                 :             : {
     138         [ #  # ]:           0 :     return m_script_sig.has_value() || m_script_witness.has_value();
     139                 :             : }
     140                 :             : 
     141                 :      124381 : std::pair<std::optional<CScript>, std::optional<CScriptWitness>> PreselectedInput::GetScripts() const
     142                 :             : {
     143                 :      124381 :     return {m_script_sig, m_script_witness};
     144                 :             : }
     145                 :             : 
     146                 :      416837 : void PreselectedInput::SetPosition(unsigned int pos)
     147                 :             : {
     148                 :      416837 :     m_pos = pos;
     149                 :      416837 : }
     150                 :             : 
     151                 :      534975 : std::optional<unsigned int> PreselectedInput::GetPosition() const
     152                 :             : {
     153                 :      534975 :     return m_pos;
     154                 :             : }
     155                 :             : } // namespace wallet
        

Generated by: LCOV version 2.0-1