Bitcoin Core 22.99.0
P2P Digital Currency
coincontrol.h
Go to the documentation of this file.
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 <outputtype.h>
9#include <policy/feerate.h>
10#include <policy/fees.h>
12#include <script/keyorigin.h>
14#include <script/standard.h>
15
16#include <optional>
17#include <algorithm>
18#include <map>
19#include <set>
20
21const int DEFAULT_MIN_DEPTH = 0;
22const int DEFAULT_MAX_DEPTH = 9999999;
23
25static constexpr bool DEFAULT_AVOIDPARTIALSPENDS = false;
26
29{
30public:
34 std::optional<OutputType> m_change_type;
36 bool m_add_inputs = true;
40 bool fAllowOtherInputs = 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;
63
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
108 {
109 setSelected.clear();
110 }
111
112 void ListSelected(std::vector<COutPoint>& vOutpoints) const
113 {
114 vOutpoints.assign(setSelected.begin(), setSelected.end());
115 }
116
117private:
118 std::set<COutPoint> setSelected;
119 std::map<COutPoint, CTxOut> m_external_txouts;
120};
121
122#endif // BITCOIN_WALLET_COINCONTROL_H
Coin Control Features.
Definition: coincontrol.h:29
bool GetExternalOutput(const COutPoint &outpoint, CTxOut &txout) const
Definition: coincontrol.h:81
std::optional< OutputType > m_change_type
Override the default change type if set, ignored if destChange is set.
Definition: coincontrol.h:34
bool HasSelected() const
Definition: coincontrol.h:66
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
Definition: coincontrol.h:50
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)
Definition: coincontrol.h:96
bool IsSelected(const COutPoint &output) const
Definition: coincontrol.h:71
int m_max_depth
Maximum chain depth value for coin availability.
Definition: coincontrol.h:60
void UnSelectAll()
Definition: coincontrol.h:107
void Select(const COutPoint &output)
Definition: coincontrol.h:91
void UnSelect(const COutPoint &output)
Definition: coincontrol.h:102
bool fAllowWatchOnly
Includes watch only addresses which are solvable.
Definition: coincontrol.h:42
int m_min_depth
Minimum chain depth value for coin availability.
Definition: coincontrol.h:58
FlatSigningProvider m_external_provider
SigningProvider that has pubkeys and scripts to do spend size estimation for external inputs.
Definition: coincontrol.h:62
std::optional< CFeeRate > m_feerate
Override the wallet's m_pay_tx_fee if set.
Definition: coincontrol.h:46
bool fOverrideFeeRate
Override automatic min/max checks on fee, m_feerate must be set if true.
Definition: coincontrol.h:44
bool m_add_inputs
If false, only selected inputs are used.
Definition: coincontrol.h:36
CTxDestination destChange
Custom change destination, if not set an address is generated.
Definition: coincontrol.h:32
bool m_avoid_address_reuse
Forbids inclusion of dirty (previously used) addresses.
Definition: coincontrol.h:54
bool m_include_unsafe_inputs
If false, only safe inputs will be used.
Definition: coincontrol.h:38
bool m_avoid_partial_spends
Avoid partial use of funds sent to a given address.
Definition: coincontrol.h:52
bool fAllowOtherInputs
If false, allows unselected inputs, but requires all selected inputs be used.
Definition: coincontrol.h:40
void ListSelected(std::vector< COutPoint > &vOutpoints) const
Definition: coincontrol.h:112
std::set< COutPoint > setSelected
Definition: coincontrol.h:118
std::map< COutPoint, CTxOut > m_external_txouts
Definition: coincontrol.h:119
bool IsExternalSelected(const COutPoint &output) const
Definition: coincontrol.h:76
FeeEstimateMode m_fee_mode
Fee estimation mode to control arguments to estimateSmartFee.
Definition: coincontrol.h:56
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:27
An output of a transaction.
Definition: transaction.h:129
const int DEFAULT_MAX_DEPTH
Definition: coincontrol.h:22
static constexpr bool DEFAULT_AVOIDPARTIALSPENDS
Default for -avoidpartialspends.
Definition: coincontrol.h:25
const int DEFAULT_MIN_DEPTH
Definition: coincontrol.h:21
FeeEstimateMode
Definition: feerate.h:18
@ UNSET
Use default settings based on other criteria.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:157