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, only selected inputs are used
30     bool m_add_inputs;
31     //! If false, allows unselected inputs, but requires all selected inputs be used
32     bool fAllowOtherInputs;
33     //! Includes watch only addresses which are solvable
34     bool fAllowWatchOnly;
35     //! Override automatic min/max checks on fee, m_feerate must be set if true
36     bool fOverrideFeeRate;
37     //! Override the wallet's m_pay_tx_fee if set
38     Optional<CFeeRate> m_feerate;
39     //! Override the default confirmation target if set
40     Optional<unsigned int> m_confirm_target;
41     //! Override the wallet's m_signal_rbf if set
42     Optional<bool> m_signal_bip125_rbf;
43     //! Avoid partial use of funds sent to a given address
44     bool m_avoid_partial_spends;
45     //! Forbids inclusion of dirty (previously used) addresses
46     bool m_avoid_address_reuse;
47     //! Fee estimation mode to control arguments to estimateSmartFee
48     FeeEstimateMode m_fee_mode;
49     //! Minimum chain depth value for coin availability
50     int m_min_depth = DEFAULT_MIN_DEPTH;
51     //! Maximum chain depth value for coin availability
52     int m_max_depth = DEFAULT_MAX_DEPTH;
53 
CCoinControl()54     CCoinControl()
55     {
56         SetNull();
57     }
58 
59     void SetNull();
60 
HasSelected()61     bool HasSelected() const
62     {
63         return (setSelected.size() > 0);
64     }
65 
IsSelected(const COutPoint & output)66     bool IsSelected(const COutPoint& output) const
67     {
68         return (setSelected.count(output) > 0);
69     }
70 
Select(const COutPoint & output)71     void Select(const COutPoint& output)
72     {
73         setSelected.insert(output);
74     }
75 
UnSelect(const COutPoint & output)76     void UnSelect(const COutPoint& output)
77     {
78         setSelected.erase(output);
79     }
80 
UnSelectAll()81     void UnSelectAll()
82     {
83         setSelected.clear();
84     }
85 
ListSelected(std::vector<COutPoint> & vOutpoints)86     void ListSelected(std::vector<COutPoint>& vOutpoints) const
87     {
88         vOutpoints.assign(setSelected.begin(), setSelected.end());
89     }
90 
91 private:
92     std::set<COutPoint> setSelected;
93 };
94 
95 #endif // BITCOIN_WALLET_COINCONTROL_H
96