2021-12-30 19:36:57 +02:00
|
|
|
// Copyright (c) 2018-2021 The Bitcoin Core developers
|
2018-07-17 14:26:35 +09:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <wallet/coincontrol.h>
|
|
|
|
|
2023-03-23 12:23:29 +01:00
|
|
|
#include <common/args.h>
|
2018-07-17 14:26:35 +09:00
|
|
|
|
2021-11-12 11:13:29 -05:00
|
|
|
namespace wallet {
|
2021-04-17 01:49:57 +01:00
|
|
|
CCoinControl::CCoinControl()
|
2018-07-17 14:26:35 +09:00
|
|
|
{
|
|
|
|
m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS);
|
|
|
|
}
|
2022-09-12 12:13:17 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2023-01-23 17:00:14 +01:00
|
|
|
std::vector<COutPoint> CCoinControl::ListSelected() const
|
2022-09-12 12:13:17 +02:00
|
|
|
{
|
2023-01-23 17:00:14 +01:00
|
|
|
return {m_selected_inputs.begin(), m_selected_inputs.end()};
|
2022-09-12 12:13:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2021-11-12 11:13:29 -05:00
|
|
|
} // namespace wallet
|