blob: f13b7073beec0e69c95c9062baabae6237dce228 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
// Copyright (c) 2018-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <wallet/coincontrol.h>
#include <common/args.h>
namespace wallet {
CCoinControl::CCoinControl()
{
m_avoid_partial_spends = gArgs.GetBoolArg("-avoidpartialspends", DEFAULT_AVOIDPARTIALSPENDS);
}
bool CCoinControl::HasSelected() const
{
return !m_selected.empty();
}
bool CCoinControl::IsSelected(const COutPoint& outpoint) const
{
return m_selected.count(outpoint) > 0;
}
bool CCoinControl::IsExternalSelected(const COutPoint& outpoint) const
{
const auto it = m_selected.find(outpoint);
return it != m_selected.end() && it->second.HasTxOut();
}
std::optional<CTxOut> CCoinControl::GetExternalOutput(const COutPoint& outpoint) const
{
const auto it = m_selected.find(outpoint);
if (it == m_selected.end() || !it->second.HasTxOut()) {
return std::nullopt;
}
return it->second.GetTxOut();
}
PreselectedInput& CCoinControl::Select(const COutPoint& outpoint)
{
return m_selected[outpoint];
}
void CCoinControl::UnSelect(const COutPoint& outpoint)
{
m_selected.erase(outpoint);
}
void CCoinControl::UnSelectAll()
{
m_selected.clear();
}
std::vector<COutPoint> CCoinControl::ListSelected() const
{
std::vector<COutPoint> outpoints;
std::transform(m_selected.begin(), m_selected.end(), std::back_inserter(outpoints),
[](const std::map<COutPoint, PreselectedInput>::value_type& pair) {
return pair.first;
});
return outpoints;
}
void CCoinControl::SetInputWeight(const COutPoint& outpoint, int64_t weight)
{
m_selected[outpoint].SetInputWeight(weight);
}
std::optional<int64_t> CCoinControl::GetInputWeight(const COutPoint& outpoint) const
{
const auto it = m_selected.find(outpoint);
return it != m_selected.end() ? it->second.GetInputWeight() : std::nullopt;
}
std::optional<uint32_t> CCoinControl::GetSequence(const COutPoint& outpoint) const
{
const auto it = m_selected.find(outpoint);
return it != m_selected.end() ? it->second.GetSequence() : std::nullopt;
}
void PreselectedInput::SetTxOut(const CTxOut& txout)
{
m_txout = txout;
}
CTxOut PreselectedInput::GetTxOut() const
{
assert(m_txout.has_value());
return m_txout.value();
}
bool PreselectedInput::HasTxOut() const
{
return m_txout.has_value();
}
void PreselectedInput::SetInputWeight(int64_t weight)
{
m_weight = weight;
}
std::optional<int64_t> PreselectedInput::GetInputWeight() const
{
return m_weight;
}
void PreselectedInput::SetSequence(uint32_t sequence)
{
m_sequence = sequence;
}
std::optional<uint32_t> PreselectedInput::GetSequence() const
{
return m_sequence;
}
} // namespace wallet
|