LCOV - code coverage report
Current view: top level - src/wallet - coincontrol.h (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 37 41 90.2 %
Date: 2022-04-21 14:51:19 Functions: 10 11 90.9 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 2 2 100.0 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2011-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                 :            : #ifndef BITCOIN_WALLET_COINCONTROL_H
#       6                 :            : #define BITCOIN_WALLET_COINCONTROL_H
#       7                 :            : 
#       8                 :            : #include <outputtype.h>
#       9                 :            : #include <policy/feerate.h>
#      10                 :            : #include <policy/fees.h>
#      11                 :            : #include <primitives/transaction.h>
#      12                 :            : #include <script/keyorigin.h>
#      13                 :            : #include <script/signingprovider.h>
#      14                 :            : #include <script/standard.h>
#      15                 :            : 
#      16                 :            : #include <optional>
#      17                 :            : #include <algorithm>
#      18                 :            : #include <map>
#      19                 :            : #include <set>
#      20                 :            : 
#      21                 :            : namespace wallet {
#      22                 :            : const int DEFAULT_MIN_DEPTH = 0;
#      23                 :            : const int DEFAULT_MAX_DEPTH = 9999999;
#      24                 :            : 
#      25                 :            : //! Default for -avoidpartialspends
#      26                 :            : static constexpr bool DEFAULT_AVOIDPARTIALSPENDS = false;
#      27                 :            : 
#      28                 :            : /** Coin Control Features. */
#      29                 :            : class CCoinControl
#      30                 :            : {
#      31                 :            : public:
#      32                 :            :     //! Custom change destination, if not set an address is generated
#      33                 :            :     CTxDestination destChange = CNoDestination();
#      34                 :            :     //! Override the default change type if set, ignored if destChange is set
#      35                 :            :     std::optional<OutputType> m_change_type;
#      36                 :            :     //! If false, only selected inputs are used
#      37                 :            :     bool m_add_inputs = true;
#      38                 :            :     //! If false, only safe inputs will be used
#      39                 :            :     bool m_include_unsafe_inputs = false;
#      40                 :            :     //! If false, allows unselected inputs, but requires all selected inputs be used
#      41                 :            :     bool fAllowOtherInputs = false;
#      42                 :            :     //! Includes watch only addresses which are solvable
#      43                 :            :     bool fAllowWatchOnly = false;
#      44                 :            :     //! Override automatic min/max checks on fee, m_feerate must be set if true
#      45                 :            :     bool fOverrideFeeRate = false;
#      46                 :            :     //! Override the wallet's m_pay_tx_fee if set
#      47                 :            :     std::optional<CFeeRate> m_feerate;
#      48                 :            :     //! Override the default confirmation target if set
#      49                 :            :     std::optional<unsigned int> m_confirm_target;
#      50                 :            :     //! Override the wallet's m_signal_rbf if set
#      51                 :            :     std::optional<bool> m_signal_bip125_rbf;
#      52                 :            :     //! Avoid partial use of funds sent to a given address
#      53                 :            :     bool m_avoid_partial_spends = DEFAULT_AVOIDPARTIALSPENDS;
#      54                 :            :     //! Forbids inclusion of dirty (previously used) addresses
#      55                 :            :     bool m_avoid_address_reuse = false;
#      56                 :            :     //! Fee estimation mode to control arguments to estimateSmartFee
#      57                 :            :     FeeEstimateMode m_fee_mode = FeeEstimateMode::UNSET;
#      58                 :            :     //! Minimum chain depth value for coin availability
#      59                 :            :     int m_min_depth = DEFAULT_MIN_DEPTH;
#      60                 :            :     //! Maximum chain depth value for coin availability
#      61                 :            :     int m_max_depth = DEFAULT_MAX_DEPTH;
#      62                 :            :     //! SigningProvider that has pubkeys and scripts to do spend size estimation for external inputs
#      63                 :            :     FlatSigningProvider m_external_provider;
#      64                 :            : 
#      65                 :            :     CCoinControl();
#      66                 :            : 
#      67                 :            :     bool HasSelected() const
#      68                 :    1659822 :     {
#      69                 :    1659822 :         return (setSelected.size() > 0);
#      70                 :    1659822 :     }
#      71                 :            : 
#      72                 :            :     bool IsSelected(const COutPoint& output) const
#      73                 :       2621 :     {
#      74                 :       2621 :         return (setSelected.count(output) > 0);
#      75                 :       2621 :     }
#      76                 :            : 
#      77                 :            :     bool IsExternalSelected(const COutPoint& output) const
#      78                 :      23162 :     {
#      79                 :      23162 :         return (m_external_txouts.count(output) > 0);
#      80                 :      23162 :     }
#      81                 :            : 
#      82                 :            :     bool GetExternalOutput(const COutPoint& outpoint, CTxOut& txout) const
#      83                 :        152 :     {
#      84                 :        152 :         const auto ext_it = m_external_txouts.find(outpoint);
#      85         [ +  + ]:        152 :         if (ext_it == m_external_txouts.end()) {
#      86                 :          2 :             return false;
#      87                 :          2 :         }
#      88                 :        150 :         txout = ext_it->second;
#      89                 :        150 :         return true;
#      90                 :        152 :     }
#      91                 :            : 
#      92                 :            :     void Select(const COutPoint& output)
#      93                 :        715 :     {
#      94                 :        715 :         setSelected.insert(output);
#      95                 :        715 :     }
#      96                 :            : 
#      97                 :            :     void SelectExternal(const COutPoint& outpoint, const CTxOut& txout)
#      98                 :        272 :     {
#      99                 :        272 :         setSelected.insert(outpoint);
#     100                 :        272 :         m_external_txouts.emplace(outpoint, txout);
#     101                 :        272 :     }
#     102                 :            : 
#     103                 :            :     void UnSelect(const COutPoint& output)
#     104                 :          0 :     {
#     105                 :          0 :         setSelected.erase(output);
#     106                 :          0 :     }
#     107                 :            : 
#     108                 :            :     void UnSelectAll()
#     109                 :            :     {
#     110                 :            :         setSelected.clear();
#     111                 :            :     }
#     112                 :            : 
#     113                 :            :     void ListSelected(std::vector<COutPoint>& vOutpoints) const
#     114                 :       5493 :     {
#     115                 :       5493 :         vOutpoints.assign(setSelected.begin(), setSelected.end());
#     116                 :       5493 :     }
#     117                 :            : 
#     118                 :            :     void SetInputWeight(const COutPoint& outpoint, int64_t weight)
#     119                 :         26 :     {
#     120                 :         26 :         m_input_weights[outpoint] = weight;
#     121                 :         26 :     }
#     122                 :            : 
#     123                 :            :     bool HasInputWeight(const COutPoint& outpoint) const
#     124                 :      24631 :     {
#     125                 :      24631 :         return m_input_weights.count(outpoint) > 0;
#     126                 :      24631 :     }
#     127                 :            : 
#     128                 :            :     int64_t GetInputWeight(const COutPoint& outpoint) const
#     129                 :        104 :     {
#     130                 :        104 :         auto it = m_input_weights.find(outpoint);
#     131                 :        104 :         assert(it != m_input_weights.end());
#     132                 :          0 :         return it->second;
#     133                 :        104 :     }
#     134                 :            : 
#     135                 :            : private:
#     136                 :            :     std::set<COutPoint> setSelected;
#     137                 :            :     std::map<COutPoint, CTxOut> m_external_txouts;
#     138                 :            :     //! Map of COutPoints to the maximum weight for that input
#     139                 :            :     std::map<COutPoint, int64_t> m_input_weights;
#     140                 :            : };
#     141                 :            : } // namespace wallet
#     142                 :            : 
#     143                 :            : #endif // BITCOIN_WALLET_COINCONTROL_H

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a