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