LCOV - code coverage report
Current view: top level - src/wallet - coincontrol.h (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 0 1 0.0 %
Date: 2023-10-05 12:38:51 Functions: 0 2 0.0 %
Branches: 0 6 0.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2011-2022 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                 :            : 
      15                 :            : #include <algorithm>
      16                 :            : #include <map>
      17                 :            : #include <optional>
      18                 :            : #include <set>
      19                 :            : 
      20                 :            : namespace wallet {
      21                 :            : const int DEFAULT_MIN_DEPTH = 0;
      22                 :            : const int DEFAULT_MAX_DEPTH = 9999999;
      23                 :            : 
      24                 :            : //! Default for -avoidpartialspends
      25                 :            : static constexpr bool DEFAULT_AVOIDPARTIALSPENDS = false;
      26                 :            : 
      27                 :            : /** Coin Control Features. */
      28   [ #  #  #  #  :          0 : class CCoinControl
                   #  # ]
      29                 :            : {
      30                 :            : public:
      31                 :            :     //! Custom change destination, if not set an address is generated
      32                 :            :     CTxDestination destChange = CNoDestination();
      33                 :            :     //! Override the default change type if set, ignored if destChange is set
      34                 :            :     std::optional<OutputType> m_change_type;
      35                 :            :     //! If false, only safe inputs will be used
      36                 :            :     bool m_include_unsafe_inputs = false;
      37                 :            :     //! If true, the selection process can add extra unselected inputs from the wallet
      38                 :            :     //! while requires all selected inputs be used
      39                 :            :     bool m_allow_other_inputs = true;
      40                 :            :     //! Includes watch only addresses which are solvable
      41                 :            :     bool fAllowWatchOnly = false;
      42                 :            :     //! Override automatic min/max checks on fee, m_feerate must be set if true
      43                 :            :     bool fOverrideFeeRate = false;
      44                 :            :     //! Override the wallet's m_pay_tx_fee if set
      45                 :            :     std::optional<CFeeRate> m_feerate;
      46                 :            :     //! Override the default confirmation target if set
      47                 :            :     std::optional<unsigned int> m_confirm_target;
      48                 :            :     //! Override the wallet's m_signal_rbf if set
      49                 :            :     std::optional<bool> m_signal_bip125_rbf;
      50                 :            :     //! Avoid partial use of funds sent to a given address
      51                 :            :     bool m_avoid_partial_spends = DEFAULT_AVOIDPARTIALSPENDS;
      52                 :            :     //! Forbids inclusion of dirty (previously used) addresses
      53                 :            :     bool m_avoid_address_reuse = false;
      54                 :            :     //! Fee estimation mode to control arguments to estimateSmartFee
      55                 :            :     FeeEstimateMode m_fee_mode = FeeEstimateMode::UNSET;
      56                 :            :     //! Minimum chain depth value for coin availability
      57                 :            :     int m_min_depth = DEFAULT_MIN_DEPTH;
      58                 :            :     //! Maximum chain depth value for coin availability
      59                 :            :     int m_max_depth = DEFAULT_MAX_DEPTH;
      60                 :            :     //! SigningProvider that has pubkeys and scripts to do spend size estimation for external inputs
      61                 :            :     FlatSigningProvider m_external_provider;
      62                 :            : 
      63                 :            :     CCoinControl();
      64                 :            : 
      65                 :            :     /**
      66                 :            :      * Returns true if there are pre-selected inputs.
      67                 :            :      */
      68                 :            :     bool HasSelected() const;
      69                 :            :     /**
      70                 :            :      * Returns true if the given output is pre-selected.
      71                 :            :      */
      72                 :            :     bool IsSelected(const COutPoint& output) const;
      73                 :            :     /**
      74                 :            :      * Returns true if the given output is selected as an external input.
      75                 :            :      */
      76                 :            :     bool IsExternalSelected(const COutPoint& output) const;
      77                 :            :     /**
      78                 :            :      * Returns the external output for the given outpoint if it exists.
      79                 :            :      */
      80                 :            :     std::optional<CTxOut> GetExternalOutput(const COutPoint& outpoint) const;
      81                 :            :     /**
      82                 :            :      * Lock-in the given output for spending.
      83                 :            :      * The output will be included in the transaction even if it's not the most optimal choice.
      84                 :            :      */
      85                 :            :     void Select(const COutPoint& output);
      86                 :            :     /**
      87                 :            :      * Lock-in the given output as an external input for spending because it is not in the wallet.
      88                 :            :      * The output will be included in the transaction even if it's not the most optimal choice.
      89                 :            :      */
      90                 :            :     void SelectExternal(const COutPoint& outpoint, const CTxOut& txout);
      91                 :            :     /**
      92                 :            :      * Unselects the given output.
      93                 :            :      */
      94                 :            :     void UnSelect(const COutPoint& output);
      95                 :            :     /**
      96                 :            :      * Unselects all outputs.
      97                 :            :      */
      98                 :            :     void UnSelectAll();
      99                 :            :     /**
     100                 :            :      * List the selected inputs.
     101                 :            :      */
     102                 :            :     std::vector<COutPoint> ListSelected() const;
     103                 :            :     /**
     104                 :            :      * Set an input's weight.
     105                 :            :      */
     106                 :            :     void SetInputWeight(const COutPoint& outpoint, int64_t weight);
     107                 :            :     /**
     108                 :            :      * Returns true if the input weight is set.
     109                 :            :      */
     110                 :            :     bool HasInputWeight(const COutPoint& outpoint) const;
     111                 :            :     /**
     112                 :            :      * Returns the input weight.
     113                 :            :      */
     114                 :            :     int64_t GetInputWeight(const COutPoint& outpoint) const;
     115                 :            : 
     116                 :            : private:
     117                 :            :     //! Selected inputs (inputs that will be used, regardless of whether they're optimal or not)
     118                 :            :     std::set<COutPoint> m_selected_inputs;
     119                 :            :     //! Map of external inputs to include in the transaction
     120                 :            :     //! These are not in the wallet, so we need to track them separately
     121                 :            :     std::map<COutPoint, CTxOut> m_external_txouts;
     122                 :            :     //! Map of COutPoints to the maximum weight for that input
     123                 :            :     std::map<COutPoint, int64_t> m_input_weights;
     124                 :            : };
     125                 :            : } // namespace wallet
     126                 :            : 
     127                 :            : #endif // BITCOIN_WALLET_COINCONTROL_H

Generated by: LCOV version 1.14