mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
wallet: Move CoinCointrol definitions to .cpp
Move definitions to coincontrol.cpp and add documentation.
This commit is contained in:
parent
1db23da6e1
commit
94776621ba
2 changed files with 121 additions and 67 deletions
|
@ -11,4 +11,72 @@ CCoinControl::CCoinControl()
|
||||||
{
|
{
|
||||||
m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS);
|
m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CCoinControl::HasSelected() const
|
||||||
|
{
|
||||||
|
return !m_selected_inputs.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCoinControl::IsSelected(const COutPoint& output) const
|
||||||
|
{
|
||||||
|
return m_selected_inputs.count(output) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCoinControl::IsExternalSelected(const COutPoint& output) const
|
||||||
|
{
|
||||||
|
return m_external_txouts.count(output) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<CTxOut> CCoinControl::GetExternalOutput(const COutPoint& outpoint) const
|
||||||
|
{
|
||||||
|
const auto ext_it = m_external_txouts.find(outpoint);
|
||||||
|
if (ext_it == m_external_txouts.end()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_optional(ext_it->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCoinControl::Select(const COutPoint& output)
|
||||||
|
{
|
||||||
|
m_selected_inputs.insert(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCoinControl::SelectExternal(const COutPoint& outpoint, const CTxOut& txout)
|
||||||
|
{
|
||||||
|
m_selected_inputs.insert(outpoint);
|
||||||
|
m_external_txouts.emplace(outpoint, txout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCoinControl::UnSelect(const COutPoint& output)
|
||||||
|
{
|
||||||
|
m_selected_inputs.erase(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCoinControl::UnSelectAll()
|
||||||
|
{
|
||||||
|
m_selected_inputs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCoinControl::ListSelected(std::vector<COutPoint>& vOutpoints) const
|
||||||
|
{
|
||||||
|
vOutpoints.assign(m_selected_inputs.begin(), m_selected_inputs.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCoinControl::SetInputWeight(const COutPoint& outpoint, int64_t weight)
|
||||||
|
{
|
||||||
|
m_input_weights[outpoint] = weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCoinControl::HasInputWeight(const COutPoint& outpoint) const
|
||||||
|
{
|
||||||
|
return m_input_weights.count(outpoint) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t CCoinControl::GetInputWeight(const COutPoint& outpoint) const
|
||||||
|
{
|
||||||
|
auto it = m_input_weights.find(outpoint);
|
||||||
|
assert(it != m_input_weights.end());
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
} // namespace wallet
|
} // namespace wallet
|
||||||
|
|
|
@ -63,76 +63,62 @@ public:
|
||||||
|
|
||||||
CCoinControl();
|
CCoinControl();
|
||||||
|
|
||||||
bool HasSelected() const
|
/**
|
||||||
{
|
* Returns true if there are pre-selected inputs.
|
||||||
return !m_selected_inputs.empty();
|
*/
|
||||||
}
|
bool HasSelected() const;
|
||||||
|
/**
|
||||||
bool IsSelected(const COutPoint& output) const
|
* Returns true if the given output is pre-selected.
|
||||||
{
|
*/
|
||||||
return m_selected_inputs.count(output) > 0;
|
bool IsSelected(const COutPoint& output) const;
|
||||||
}
|
/**
|
||||||
|
* Returns true if the given output is selected as an external input.
|
||||||
bool IsExternalSelected(const COutPoint& output) const
|
*/
|
||||||
{
|
bool IsExternalSelected(const COutPoint& output) const;
|
||||||
return m_external_txouts.count(output) > 0;
|
/**
|
||||||
}
|
* Returns the external output for the given outpoint if it exists.
|
||||||
|
*/
|
||||||
std::optional<CTxOut> GetExternalOutput(const COutPoint& outpoint) const
|
std::optional<CTxOut> GetExternalOutput(const COutPoint& outpoint) const;
|
||||||
{
|
/**
|
||||||
const auto ext_it = m_external_txouts.find(outpoint);
|
* Lock-in the given output for spending.
|
||||||
if (ext_it == m_external_txouts.end()) {
|
* The output will be included in the transaction even if it's not the most optimal choice.
|
||||||
return std::nullopt;
|
*/
|
||||||
}
|
void Select(const COutPoint& output);
|
||||||
|
/**
|
||||||
return std::make_optional(ext_it->second);
|
* Lock-in the given output as an external input for spending because it is not in the wallet.
|
||||||
}
|
* The output will be included in the transaction even if it's not the most optimal choice.
|
||||||
|
*/
|
||||||
void Select(const COutPoint& output)
|
void SelectExternal(const COutPoint& outpoint, const CTxOut& txout);
|
||||||
{
|
/**
|
||||||
m_selected_inputs.insert(output);
|
* Unselects the given output.
|
||||||
}
|
*/
|
||||||
|
void UnSelect(const COutPoint& output);
|
||||||
void SelectExternal(const COutPoint& outpoint, const CTxOut& txout)
|
/**
|
||||||
{
|
* Unselects all outputs.
|
||||||
m_selected_inputs.insert(outpoint);
|
*/
|
||||||
m_external_txouts.emplace(outpoint, txout);
|
void UnSelectAll();
|
||||||
}
|
/**
|
||||||
|
* List the selected inputs.
|
||||||
void UnSelect(const COutPoint& output)
|
*/
|
||||||
{
|
void ListSelected(std::vector<COutPoint>& vOutpoints) const;
|
||||||
m_selected_inputs.erase(output);
|
/**
|
||||||
}
|
* Set an input's weight.
|
||||||
|
*/
|
||||||
void UnSelectAll()
|
void SetInputWeight(const COutPoint& outpoint, int64_t weight);
|
||||||
{
|
/**
|
||||||
m_selected_inputs.clear();
|
* Returns true if the input weight is set.
|
||||||
}
|
*/
|
||||||
|
bool HasInputWeight(const COutPoint& outpoint) const;
|
||||||
void ListSelected(std::vector<COutPoint>& vOutpoints) const
|
/**
|
||||||
{
|
* Returns the input weight.
|
||||||
vOutpoints.assign(m_selected_inputs.begin(), m_selected_inputs.end());
|
*/
|
||||||
}
|
int64_t GetInputWeight(const COutPoint& outpoint) const;
|
||||||
|
|
||||||
void SetInputWeight(const COutPoint& outpoint, int64_t weight)
|
|
||||||
{
|
|
||||||
m_input_weights[outpoint] = weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HasInputWeight(const COutPoint& outpoint) const
|
|
||||||
{
|
|
||||||
return m_input_weights.count(outpoint) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t GetInputWeight(const COutPoint& outpoint) const
|
|
||||||
{
|
|
||||||
auto it = m_input_weights.find(outpoint);
|
|
||||||
assert(it != m_input_weights.end());
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
//! Selected inputs (inputs that will be used, regardless of whether they're optimal or not)
|
||||||
std::set<COutPoint> m_selected_inputs;
|
std::set<COutPoint> m_selected_inputs;
|
||||||
|
//! Map of external inputs to include in the transaction
|
||||||
|
//! These are not in the wallet, so we need to track them separately
|
||||||
std::map<COutPoint, CTxOut> m_external_txouts;
|
std::map<COutPoint, CTxOut> m_external_txouts;
|
||||||
//! Map of COutPoints to the maximum weight for that input
|
//! Map of COutPoints to the maximum weight for that input
|
||||||
std::map<COutPoint, int64_t> m_input_weights;
|
std::map<COutPoint, int64_t> m_input_weights;
|
||||||
|
|
Loading…
Add table
Reference in a new issue