Bitcoin Core  23.99.0
P2P Digital Currency
coincontrol.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2021 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 #include <script/standard.h>
15 
16 #include <optional>
17 #include <algorithm>
18 #include <map>
19 #include <set>
20 
21 namespace wallet {
22 const int DEFAULT_MIN_DEPTH = 0;
23 const int DEFAULT_MAX_DEPTH = 9999999;
24 
26 static constexpr bool DEFAULT_AVOIDPARTIALSPENDS = false;
27 
30 {
31 public:
35  std::optional<OutputType> m_change_type;
40  bool m_allow_other_inputs = false;
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;
63 
64  CCoinControl();
65 
66  bool HasSelected() const
67  {
68  return (setSelected.size() > 0);
69  }
70 
71  bool IsSelected(const COutPoint& output) const
72  {
73  return (setSelected.count(output) > 0);
74  }
75 
76  bool IsExternalSelected(const COutPoint& output) const
77  {
78  return (m_external_txouts.count(output) > 0);
79  }
80 
81  bool GetExternalOutput(const COutPoint& outpoint, CTxOut& txout) const
82  {
83  const auto ext_it = m_external_txouts.find(outpoint);
84  if (ext_it == m_external_txouts.end()) {
85  return false;
86  }
87  txout = ext_it->second;
88  return true;
89  }
90 
91  void Select(const COutPoint& output)
92  {
93  setSelected.insert(output);
94  }
95 
96  void SelectExternal(const COutPoint& outpoint, const CTxOut& txout)
97  {
98  setSelected.insert(outpoint);
99  m_external_txouts.emplace(outpoint, txout);
100  }
101 
102  void UnSelect(const COutPoint& output)
103  {
104  setSelected.erase(output);
105  }
106 
107  void UnSelectAll()
108  {
109  setSelected.clear();
110  }
111 
112  void ListSelected(std::vector<COutPoint>& vOutpoints) const
113  {
114  vOutpoints.assign(setSelected.begin(), setSelected.end());
115  }
116 
117  void SetInputWeight(const COutPoint& outpoint, int64_t weight)
118  {
119  m_input_weights[outpoint] = weight;
120  }
121 
122  bool HasInputWeight(const COutPoint& outpoint) const
123  {
124  return m_input_weights.count(outpoint) > 0;
125  }
126 
127  int64_t GetInputWeight(const COutPoint& outpoint) const
128  {
129  auto it = m_input_weights.find(outpoint);
130  assert(it != m_input_weights.end());
131  return it->second;
132  }
133 
134 private:
135  std::set<COutPoint> setSelected;
136  std::map<COutPoint, CTxOut> m_external_txouts;
138  std::map<COutPoint, int64_t> m_input_weights;
139 };
140 } // namespace wallet
141 
142 #endif // BITCOIN_WALLET_COINCONTROL_H
wallet::CCoinControl::IsExternalSelected
bool IsExternalSelected(const COutPoint &output) const
Definition: coincontrol.h:76
feerate.h
wallet::CCoinControl::m_max_depth
int m_max_depth
Maximum chain depth value for coin availability.
Definition: coincontrol.h:60
assert
assert(!tx.IsCoinBase())
transaction.h
outputtype.h
wallet::CCoinControl::m_external_txouts
std::map< COutPoint, CTxOut > m_external_txouts
Definition: coincontrol.h:136
wallet::CCoinControl::GetExternalOutput
bool GetExternalOutput(const COutPoint &outpoint, CTxOut &txout) const
Definition: coincontrol.h:81
wallet::CCoinControl::m_confirm_target
std::optional< unsigned int > m_confirm_target
Override the default confirmation target if set.
Definition: coincontrol.h:48
wallet::CCoinControl::HasInputWeight
bool HasInputWeight(const COutPoint &outpoint) const
Definition: coincontrol.h:122
wallet
Definition: node.h:39
wallet::CCoinControl::fAllowWatchOnly
bool fAllowWatchOnly
Includes watch only addresses which are solvable.
Definition: coincontrol.h:42
wallet::CCoinControl::GetInputWeight
int64_t GetInputWeight(const COutPoint &outpoint) const
Definition: coincontrol.h:127
wallet::CCoinControl::HasSelected
bool HasSelected() const
Definition: coincontrol.h:66
signingprovider.h
wallet::CCoinControl::SetInputWeight
void SetInputWeight(const COutPoint &outpoint, int64_t weight)
Definition: coincontrol.h:117
CTxDestination
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:149
wallet::CCoinControl::destChange
CTxDestination destChange
Custom change destination, if not set an address is generated.
Definition: coincontrol.h:33
CTxOut
An output of a transaction.
Definition: transaction.h:156
wallet::CCoinControl::m_external_provider
FlatSigningProvider m_external_provider
SigningProvider that has pubkeys and scripts to do spend size estimation for external inputs.
Definition: coincontrol.h:62
wallet::CCoinControl::ListSelected
void ListSelected(std::vector< COutPoint > &vOutpoints) const
Definition: coincontrol.h:112
wallet::CCoinControl::m_avoid_address_reuse
bool m_avoid_address_reuse
Forbids inclusion of dirty (previously used) addresses.
Definition: coincontrol.h:54
FeeEstimateMode
FeeEstimateMode
Definition: feerate.h:21
wallet::CCoinControl::m_change_type
std::optional< OutputType > m_change_type
Override the default change type if set, ignored if destChange is set.
Definition: coincontrol.h:35
wallet::CCoinControl::m_input_weights
std::map< COutPoint, int64_t > m_input_weights
Map of COutPoints to the maximum weight for that input.
Definition: coincontrol.h:138
wallet::CCoinControl::m_feerate
std::optional< CFeeRate > m_feerate
Override the wallet's m_pay_tx_fee if set.
Definition: coincontrol.h:46
wallet::CCoinControl::m_min_depth
int m_min_depth
Minimum chain depth value for coin availability.
Definition: coincontrol.h:58
standard.h
wallet::CCoinControl::m_avoid_partial_spends
bool m_avoid_partial_spends
Avoid partial use of funds sent to a given address.
Definition: coincontrol.h:52
wallet::CCoinControl::UnSelect
void UnSelect(const COutPoint &output)
Definition: coincontrol.h:102
wallet::CCoinControl::m_signal_bip125_rbf
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
Definition: coincontrol.h:50
wallet::CCoinControl::Select
void Select(const COutPoint &output)
Definition: coincontrol.h:91
FeeEstimateMode::UNSET
@ UNSET
Use default settings based on other criteria.
wallet::CCoinControl::m_include_unsafe_inputs
bool m_include_unsafe_inputs
If false, only safe inputs will be used.
Definition: coincontrol.h:37
CNoDestination
Definition: standard.h:65
fees.h
wallet::CCoinControl::CCoinControl
CCoinControl()
Definition: coincontrol.cpp:10
wallet::CCoinControl::SelectExternal
void SelectExternal(const COutPoint &outpoint, const CTxOut &txout)
Definition: coincontrol.h:96
wallet::CCoinControl::fOverrideFeeRate
bool fOverrideFeeRate
Override automatic min/max checks on fee, m_feerate must be set if true.
Definition: coincontrol.h:44
wallet::DEFAULT_MAX_DEPTH
const int DEFAULT_MAX_DEPTH
Definition: coincontrol.h:23
wallet::DEFAULT_MIN_DEPTH
const int DEFAULT_MIN_DEPTH
Definition: coincontrol.h:22
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:34
wallet::CCoinControl::m_fee_mode
FeeEstimateMode m_fee_mode
Fee estimation mode to control arguments to estimateSmartFee.
Definition: coincontrol.h:56
wallet::CCoinControl::UnSelectAll
void UnSelectAll()
Definition: coincontrol.h:107
keyorigin.h
wallet::CCoinControl::IsSelected
bool IsSelected(const COutPoint &output) const
Definition: coincontrol.h:71
wallet::CCoinControl::m_allow_other_inputs
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
wallet::CCoinControl
Coin Control Features.
Definition: coincontrol.h:29
FlatSigningProvider
Definition: signingprovider.h:74
wallet::CCoinControl::setSelected
std::set< COutPoint > setSelected
Definition: coincontrol.h:135
wallet::DEFAULT_AVOIDPARTIALSPENDS
static constexpr bool DEFAULT_AVOIDPARTIALSPENDS
Default for -avoidpartialspends.
Definition: coincontrol.h:26