Bitcoin Core  25.99.0
P2P Digital Currency
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
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 #include <script/standard.h>
16 #include <algorithm>
17 #include <map>
18 #include <optional>
19 #include <set>
21 namespace wallet {
22 const int DEFAULT_MIN_DEPTH = 0;
23 const int DEFAULT_MAX_DEPTH = 9999999;
26 static constexpr bool DEFAULT_AVOIDPARTIALSPENDS = false;
30 {
31 public:
35  std::optional<OutputType> m_change_type;
40  bool m_allow_other_inputs = true;
42  bool fAllowWatchOnly = false;
44  bool fOverrideFeeRate = false;
46  std::optional<CFeeRate> m_feerate;
48  std::optional<unsigned int> m_confirm_target;
50  std::optional<bool> m_signal_bip125_rbf;
54  bool m_avoid_address_reuse = false;
64  CCoinControl();
69  bool HasSelected() const;
73  bool IsSelected(const COutPoint& output) const;
77  bool IsExternalSelected(const COutPoint& output) const;
81  std::optional<CTxOut> GetExternalOutput(const COutPoint& outpoint) const;
86  void Select(const COutPoint& output);
91  void SelectExternal(const COutPoint& outpoint, const CTxOut& txout);
95  void UnSelect(const COutPoint& output);
99  void UnSelectAll();
103  std::vector<COutPoint> ListSelected() const;
107  void SetInputWeight(const COutPoint& outpoint, int64_t weight);
111  bool HasInputWeight(const COutPoint& outpoint) const;
115  int64_t GetInputWeight(const COutPoint& outpoint) const;
117 private:
119  std::set<COutPoint> m_selected_inputs;
122  std::map<COutPoint, CTxOut> m_external_txouts;
124  std::map<COutPoint, int64_t> m_input_weights;
125 };
126 } // namespace wallet
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:36
An output of a transaction.
Definition: transaction.h:158
Coin Control Features.
Definition: coincontrol.h:30
FeeEstimateMode m_fee_mode
Fee estimation mode to control arguments to estimateSmartFee.
Definition: coincontrol.h:56
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
Definition: coincontrol.h:50
bool HasInputWeight(const COutPoint &outpoint) const
Returns true if the input weight is set.
Definition: coincontrol.cpp:71
std::optional< CTxOut > GetExternalOutput(const COutPoint &outpoint) const
Returns the external output for the given outpoint if it exists.
Definition: coincontrol.cpp:30
int64_t GetInputWeight(const COutPoint &outpoint) const
Returns the input weight.
Definition: coincontrol.cpp:76
void Select(const COutPoint &output)
Lock-in the given output for spending.
Definition: coincontrol.cpp:40
std::optional< unsigned int > m_confirm_target
Override the default confirmation target if set.
Definition: coincontrol.h:48
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
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:122
std::optional< OutputType > m_change_type
Override the default change type if set, ignored if destChange is set.
Definition: coincontrol.h:35
bool m_avoid_address_reuse
Forbids inclusion of dirty (previously used) addresses.
Definition: coincontrol.h:54
bool IsSelected(const COutPoint &output) const
Returns true if the given output is pre-selected.
Definition: coincontrol.cpp:20
std::set< COutPoint > m_selected_inputs
Selected inputs (inputs that will be used, regardless of whether they're optimal or not)
Definition: coincontrol.h:119
void UnSelectAll()
Unselects all outputs.
Definition: coincontrol.cpp:56
std::map< COutPoint, int64_t > m_input_weights
Map of COutPoints to the maximum weight for that input.
Definition: coincontrol.h:124
bool HasSelected() const
Returns true if there are pre-selected inputs.
Definition: coincontrol.cpp:15
int m_min_depth
Minimum chain depth value for coin availability.
Definition: coincontrol.h:58
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:40
int m_max_depth
Maximum chain depth value for coin availability.
Definition: coincontrol.h:60
bool fOverrideFeeRate
Override automatic min/max checks on fee, m_feerate must be set if true.
Definition: coincontrol.h:44
void SetInputWeight(const COutPoint &outpoint, int64_t weight)
Set an input's weight.
Definition: coincontrol.cpp:66
std::optional< CFeeRate > m_feerate
Override the wallet's m_pay_tx_fee if set.
Definition: coincontrol.h:46
bool m_include_unsafe_inputs
If false, only safe inputs will be used.
Definition: coincontrol.h:37
bool m_avoid_partial_spends
Avoid partial use of funds sent to a given address.
Definition: coincontrol.h:52
bool fAllowWatchOnly
Includes watch only addresses which are solvable.
Definition: coincontrol.h:42
bool IsExternalSelected(const COutPoint &output) const
Returns true if the given output is selected as an external input.
Definition: coincontrol.cpp:25
FlatSigningProvider m_external_provider
SigningProvider that has pubkeys and scripts to do spend size estimation for external inputs.
Definition: coincontrol.h:62
CTxDestination destChange
Custom change destination, if not set an address is generated.
Definition: coincontrol.h:33
std::vector< COutPoint > ListSelected() const
List the selected inputs.
Definition: coincontrol.cpp:61
void UnSelect(const COutPoint &output)
Unselects the given output.
Definition: coincontrol.cpp:51
Definition: feerate.h:21
Use default settings based on other criteria.
Default for -avoidpartialspends.
Definition: coincontrol.h:26
Definition: coincontrol.h:22
Definition: coincontrol.h:23
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:149