1 // Copyright (c) 2011-2019 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 <optional.h>
9 #include <outputtype.h>
10 #include <policy/feerate.h>
11 #include <policy/fees.h>
12 #include <primitives/transaction.h>
13 #include <script/standard.h>
14 
15 const int DEFAULT_MIN_DEPTH = 0;
16 const int DEFAULT_MAX_DEPTH = 9999999;
17 
18 //! Default for -avoidpartialspends
19 static constexpr bool DEFAULT_AVOIDPARTIALSPENDS = false;
20 
21 /** Coin Control Features. */
22 class CCoinControl
23 {
24 public:
25     //! Custom change destination, if not set an address is generated
26     CTxDestination destChange;
27     //! Override the default change type if set, ignored if destChange is set
28     Optional<OutputType> m_change_type;
29     //! If false, allows unselected inputs, but requires all selected inputs be used
30     bool fAllowOtherInputs;
31     //! Includes watch only addresses which are solvable
32     bool fAllowWatchOnly;
33     //! Override automatic min/max checks on fee, m_feerate must be set if true
34     bool fOverrideFeeRate;
35     //! Override the wallet's m_pay_tx_fee if set
36     Optional<CFeeRate> m_feerate;
37     //! Override the default confirmation target if set
38     Optional<unsigned int> m_confirm_target;
39     //! Override the wallet's m_signal_rbf if set
40     Optional<bool> m_signal_bip125_rbf;
41     //! Avoid partial use of funds sent to a given address
42     bool m_avoid_partial_spends;
43     //! Forbids inclusion of dirty (previously used) addresses
44     bool m_avoid_address_reuse;
45     //! Fee estimation mode to control arguments to estimateSmartFee
46     FeeEstimateMode m_fee_mode;
47     //! Minimum chain depth value for coin availability
48     int m_min_depth = DEFAULT_MIN_DEPTH;
49     //! Maximum chain depth value for coin availability
50     int m_max_depth = DEFAULT_MAX_DEPTH;
51 
CCoinControl()52     CCoinControl()
53     {
54         SetNull();
55     }
56 
57     void SetNull();
58 
HasSelected()59     bool HasSelected() const
60     {
61         return (setSelected.size() > 0);
62     }
63 
IsSelected(const COutPoint & output)64     bool IsSelected(const COutPoint& output) const
65     {
66         return (setSelected.count(output) > 0);
67     }
68 
Select(const COutPoint & output)69     void Select(const COutPoint& output)
70     {
71         setSelected.insert(output);
72     }
73 
UnSelect(const COutPoint & output)74     void UnSelect(const COutPoint& output)
75     {
76         setSelected.erase(output);
77     }
78 
UnSelectAll()79     void UnSelectAll()
80     {
81         setSelected.clear();
82     }
83 
ListSelected(std::vector<COutPoint> & vOutpoints)84     void ListSelected(std::vector<COutPoint>& vOutpoints) const
85     {
86         vOutpoints.assign(setSelected.begin(), setSelected.end());
87     }
88 
89 private:
90     std::set<COutPoint> setSelected;
91 };
92 
93 #endif // BITCOIN_WALLET_COINCONTROL_H
94