Bitcoin Core  26.1.0
P2P Digital Currency
coincontrol.h
Go to the documentation of this file.
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 
25 static constexpr bool DEFAULT_AVOIDPARTIALSPENDS = false;
26 
29 {
30 public:
34  std::optional<OutputType> m_change_type;
39  bool m_allow_other_inputs = true;
41  bool fAllowWatchOnly = false;
43  bool fOverrideFeeRate = false;
45  std::optional<CFeeRate> m_feerate;
47  std::optional<unsigned int> m_confirm_target;
49  std::optional<bool> m_signal_bip125_rbf;
53  bool m_avoid_address_reuse = false;
62 
63  CCoinControl();
64 
68  bool HasSelected() const;
72  bool IsSelected(const COutPoint& output) const;
76  bool IsExternalSelected(const COutPoint& output) const;
80  std::optional<CTxOut> GetExternalOutput(const COutPoint& outpoint) const;
85  void Select(const COutPoint& output);
90  void SelectExternal(const COutPoint& outpoint, const CTxOut& txout);
94  void UnSelect(const COutPoint& output);
98  void UnSelectAll();
102  std::vector<COutPoint> ListSelected() const;
106  void SetInputWeight(const COutPoint& outpoint, int64_t weight);
110  bool HasInputWeight(const COutPoint& outpoint) const;
114  int64_t GetInputWeight(const COutPoint& outpoint) const;
115 
116 private:
118  std::set<COutPoint> m_selected_inputs;
121  std::map<COutPoint, CTxOut> m_external_txouts;
123  std::map<COutPoint, int64_t> m_input_weights;
124 };
125 } // namespace wallet
126 
127 #endif // BITCOIN_WALLET_COINCONTROL_H
std::optional< CTxOut > GetExternalOutput(const COutPoint &outpoint) const
Returns the external output for the given outpoint if it exists.
Definition: coincontrol.cpp:30
bool m_avoid_partial_spends
Avoid partial use of funds sent to a given address.
Definition: coincontrol.h:51
std::optional< unsigned int > m_confirm_target
Override the default confirmation target if set.
Definition: coincontrol.h:47
CTxDestination destChange
Custom change destination, if not set an address is generated.
Definition: coincontrol.h:32
bool fAllowWatchOnly
Includes watch only addresses which are solvable.
Definition: coincontrol.h:41
FlatSigningProvider m_external_provider
SigningProvider that has pubkeys and scripts to do spend size estimation for external inputs...
Definition: coincontrol.h:61
std::map< COutPoint, int64_t > m_input_weights
Map of COutPoints to the maximum weight for that input.
Definition: coincontrol.h:123
void SelectExternal(const COutPoint &outpoint, const CTxOut &txout)
Lock-in the given output as an external input for spending because it is not in the wallet...
Definition: coincontrol.cpp:45
bool IsSelected(const COutPoint &output) const
Returns true if the given output is pre-selected.
Definition: coincontrol.cpp:20
bool HasSelected() const
Returns true if there are pre-selected inputs.
Definition: coincontrol.cpp:15
std::optional< OutputType > m_change_type
Override the default change type if set, ignored if destChange is set.
Definition: coincontrol.h:34
void UnSelect(const COutPoint &output)
Unselects the given output.
Definition: coincontrol.cpp:51
void Select(const COutPoint &output)
Lock-in the given output for spending.
Definition: coincontrol.cpp:40
int64_t GetInputWeight(const COutPoint &outpoint) const
Returns the input weight.
Definition: coincontrol.cpp:76
static constexpr bool DEFAULT_AVOIDPARTIALSPENDS
Default for -avoidpartialspends.
Definition: coincontrol.h:25
FeeEstimateMode
Definition: feerate.h:21
std::map< COutPoint, CTxOut > m_external_txouts
Map of external inputs to include in the transaction These are not in the wallet, so we need to track...
Definition: coincontrol.h:121
bool fOverrideFeeRate
Override automatic min/max checks on fee, m_feerate must be set if true.
Definition: coincontrol.h:43
void SetInputWeight(const COutPoint &outpoint, int64_t weight)
Set an input&#39;s weight.
Definition: coincontrol.cpp:66
bool IsExternalSelected(const COutPoint &output) const
Returns true if the given output is selected as an external input.
Definition: coincontrol.cpp:25
void UnSelectAll()
Unselects all outputs.
Definition: coincontrol.cpp:56
An output of a transaction.
Definition: transaction.h:157
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:35
bool m_avoid_address_reuse
Forbids inclusion of dirty (previously used) addresses.
Definition: coincontrol.h:53
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
Definition: addresstype.h:129
const int DEFAULT_MAX_DEPTH
Definition: coincontrol.h:22
const int DEFAULT_MIN_DEPTH
Definition: coincontrol.h:21
int m_min_depth
Minimum chain depth value for coin availability.
Definition: coincontrol.h:57
Use default settings based on other criteria.
bool m_include_unsafe_inputs
If false, only safe inputs will be used.
Definition: coincontrol.h:36
FeeEstimateMode m_fee_mode
Fee estimation mode to control arguments to estimateSmartFee.
Definition: coincontrol.h:55
bool m_allow_other_inputs
If true, the selection process can add extra unselected inputs from the wallet while requires all sel...
Definition: coincontrol.h:39
std::set< COutPoint > m_selected_inputs
Selected inputs (inputs that will be used, regardless of whether they&#39;re optimal or not) ...
Definition: coincontrol.h:118
int m_max_depth
Maximum chain depth value for coin availability.
Definition: coincontrol.h:59
std::optional< bool > m_signal_bip125_rbf
Override the wallet&#39;s m_signal_rbf if set.
Definition: coincontrol.h:49
std::optional< CFeeRate > m_feerate
Override the wallet&#39;s m_pay_tx_fee if set.
Definition: coincontrol.h:45
std::vector< COutPoint > ListSelected() const
List the selected inputs.
Definition: coincontrol.cpp:61
Coin Control Features.
Definition: coincontrol.h:28
bool HasInputWeight(const COutPoint &outpoint) const
Returns true if the input weight is set.
Definition: coincontrol.cpp:71