Skip to content

Commit 9477662

Browse files
committed
wallet: Move CoinCointrol definitions to .cpp
Move definitions to coincontrol.cpp and add documentation.
1 parent 1db23da commit 9477662

File tree

2 files changed

+121
-67
lines changed

2 files changed

+121
-67
lines changed

src/wallet/coincontrol.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,72 @@ CCoinControl::CCoinControl()
1111
{
1212
m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS);
1313
}
14+
15+
bool CCoinControl::HasSelected() const
16+
{
17+
return !m_selected_inputs.empty();
18+
}
19+
20+
bool CCoinControl::IsSelected(const COutPoint& output) const
21+
{
22+
return m_selected_inputs.count(output) > 0;
23+
}
24+
25+
bool CCoinControl::IsExternalSelected(const COutPoint& output) const
26+
{
27+
return m_external_txouts.count(output) > 0;
28+
}
29+
30+
std::optional<CTxOut> CCoinControl::GetExternalOutput(const COutPoint& outpoint) const
31+
{
32+
const auto ext_it = m_external_txouts.find(outpoint);
33+
if (ext_it == m_external_txouts.end()) {
34+
return std::nullopt;
35+
}
36+
37+
return std::make_optional(ext_it->second);
38+
}
39+
40+
void CCoinControl::Select(const COutPoint& output)
41+
{
42+
m_selected_inputs.insert(output);
43+
}
44+
45+
void CCoinControl::SelectExternal(const COutPoint& outpoint, const CTxOut& txout)
46+
{
47+
m_selected_inputs.insert(outpoint);
48+
m_external_txouts.emplace(outpoint, txout);
49+
}
50+
51+
void CCoinControl::UnSelect(const COutPoint& output)
52+
{
53+
m_selected_inputs.erase(output);
54+
}
55+
56+
void CCoinControl::UnSelectAll()
57+
{
58+
m_selected_inputs.clear();
59+
}
60+
61+
void CCoinControl::ListSelected(std::vector<COutPoint>& vOutpoints) const
62+
{
63+
vOutpoints.assign(m_selected_inputs.begin(), m_selected_inputs.end());
64+
}
65+
66+
void CCoinControl::SetInputWeight(const COutPoint& outpoint, int64_t weight)
67+
{
68+
m_input_weights[outpoint] = weight;
69+
}
70+
71+
bool CCoinControl::HasInputWeight(const COutPoint& outpoint) const
72+
{
73+
return m_input_weights.count(outpoint) > 0;
74+
}
75+
76+
int64_t CCoinControl::GetInputWeight(const COutPoint& outpoint) const
77+
{
78+
auto it = m_input_weights.find(outpoint);
79+
assert(it != m_input_weights.end());
80+
return it->second;
81+
}
1482
} // namespace wallet

src/wallet/coincontrol.h

Lines changed: 53 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -63,76 +63,62 @@ class CCoinControl
6363

6464
CCoinControl();
6565

66-
bool HasSelected() const
67-
{
68-
return !m_selected_inputs.empty();
69-
}
70-
71-
bool IsSelected(const COutPoint& output) const
72-
{
73-
return m_selected_inputs.count(output) > 0;
74-
}
75-
76-
bool IsExternalSelected(const COutPoint& output) const
77-
{
78-
return m_external_txouts.count(output) > 0;
79-
}
80-
81-
std::optional<CTxOut> GetExternalOutput(const COutPoint& outpoint) const
82-
{
83-
const auto ext_it = m_external_txouts.find(outpoint);
84-
if (ext_it == m_external_txouts.end()) {
85-
return std::nullopt;
86-
}
87-
88-
return std::make_optional(ext_it->second);
89-
}
90-
91-
void Select(const COutPoint& output)
92-
{
93-
m_selected_inputs.insert(output);
94-
}
95-
96-
void SelectExternal(const COutPoint& outpoint, const CTxOut& txout)
97-
{
98-
m_selected_inputs.insert(outpoint);
99-
m_external_txouts.emplace(outpoint, txout);
100-
}
101-
102-
void UnSelect(const COutPoint& output)
103-
{
104-
m_selected_inputs.erase(output);
105-
}
106-
107-
void UnSelectAll()
108-
{
109-
m_selected_inputs.clear();
110-
}
111-
112-
void ListSelected(std::vector<COutPoint>& vOutpoints) const
113-
{
114-
vOutpoints.assign(m_selected_inputs.begin(), m_selected_inputs.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-
}
66+
/**
67+
* Returns true if there are pre-selected inputs.
68+
*/
69+
bool HasSelected() const;
70+
/**
71+
* Returns true if the given output is pre-selected.
72+
*/
73+
bool IsSelected(const COutPoint& output) const;
74+
/**
75+
* Returns true if the given output is selected as an external input.
76+
*/
77+
bool IsExternalSelected(const COutPoint& output) const;
78+
/**
79+
* Returns the external output for the given outpoint if it exists.
80+
*/
81+
std::optional<CTxOut> GetExternalOutput(const COutPoint& outpoint) const;
82+
/**
83+
* Lock-in the given output for spending.
84+
* The output will be included in the transaction even if it's not the most optimal choice.
85+
*/
86+
void Select(const COutPoint& output);
87+
/**
88+
* Lock-in the given output as an external input for spending because it is not in the wallet.
89+
* The output will be included in the transaction even if it's not the most optimal choice.
90+
*/
91+
void SelectExternal(const COutPoint& outpoint, const CTxOut& txout);
92+
/**
93+
* Unselects the given output.
94+
*/
95+
void UnSelect(const COutPoint& output);
96+
/**
97+
* Unselects all outputs.
98+
*/
99+
void UnSelectAll();
100+
/**
101+
* List the selected inputs.
102+
*/
103+
void ListSelected(std::vector<COutPoint>& vOutpoints) const;
104+
/**
105+
* Set an input's weight.
106+
*/
107+
void SetInputWeight(const COutPoint& outpoint, int64_t weight);
108+
/**
109+
* Returns true if the input weight is set.
110+
*/
111+
bool HasInputWeight(const COutPoint& outpoint) const;
112+
/**
113+
* Returns the input weight.
114+
*/
115+
int64_t GetInputWeight(const COutPoint& outpoint) const;
133116

134117
private:
118+
//! Selected inputs (inputs that will be used, regardless of whether they're optimal or not)
135119
std::set<COutPoint> m_selected_inputs;
120+
//! Map of external inputs to include in the transaction
121+
//! These are not in the wallet, so we need to track them separately
136122
std::map<COutPoint, CTxOut> m_external_txouts;
137123
//! Map of COutPoints to the maximum weight for that input
138124
std::map<COutPoint, int64_t> m_input_weights;

0 commit comments

Comments
 (0)