@@ -14,69 +14,104 @@ CCoinControl::CCoinControl()
14
14
15
15
bool CCoinControl::HasSelected () const
16
16
{
17
- return !m_selected_inputs .empty ();
17
+ return !m_selected .empty ();
18
18
}
19
19
20
- bool CCoinControl::IsSelected (const COutPoint& output ) const
20
+ bool CCoinControl::IsSelected (const COutPoint& outpoint ) const
21
21
{
22
- return m_selected_inputs .count (output ) > 0 ;
22
+ return m_selected .count (outpoint ) > 0 ;
23
23
}
24
24
25
- bool CCoinControl::IsExternalSelected (const COutPoint& output ) const
25
+ bool CCoinControl::IsExternalSelected (const COutPoint& outpoint ) const
26
26
{
27
- return m_external_txouts.count (output) > 0 ;
27
+ const auto it = m_selected.find (outpoint);
28
+ return it != m_selected.end () && it->second .HasTxOut ();
28
29
}
29
30
30
31
std::optional<CTxOut> CCoinControl::GetExternalOutput (const COutPoint& outpoint) const
31
32
{
32
- const auto ext_it = m_external_txouts .find (outpoint);
33
- if (ext_it == m_external_txouts .end ()) {
33
+ const auto it = m_selected .find (outpoint);
34
+ if (it == m_selected .end () || !it-> second . HasTxOut ()) {
34
35
return std::nullopt;
35
36
}
36
-
37
- return std::make_optional (ext_it->second );
37
+ return it->second .GetTxOut ();
38
38
}
39
39
40
- void CCoinControl::Select (const COutPoint& output )
40
+ PreselectedInput& CCoinControl::Select (const COutPoint& outpoint )
41
41
{
42
- m_selected_inputs. insert (output) ;
42
+ return m_selected[outpoint] ;
43
43
}
44
44
45
45
void CCoinControl::SelectExternal (const COutPoint& outpoint, const CTxOut& txout)
46
46
{
47
- m_selected_inputs.insert (outpoint);
48
- m_external_txouts.emplace (outpoint, txout);
47
+ m_selected[outpoint].SetTxOut (txout);
49
48
}
50
49
51
- void CCoinControl::UnSelect (const COutPoint& output )
50
+ void CCoinControl::UnSelect (const COutPoint& outpoint )
52
51
{
53
- m_selected_inputs .erase (output );
52
+ m_selected .erase (outpoint );
54
53
}
55
54
56
55
void CCoinControl::UnSelectAll ()
57
56
{
58
- m_selected_inputs .clear ();
57
+ m_selected .clear ();
59
58
}
60
59
61
60
std::vector<COutPoint> CCoinControl::ListSelected () const
62
61
{
63
- return {m_selected_inputs.begin (), m_selected_inputs.end ()};
62
+ std::vector<COutPoint> outpoints;
63
+ std::transform (m_selected.begin (), m_selected.end (), std::back_inserter (outpoints),
64
+ [](const std::map<COutPoint, PreselectedInput>::value_type& pair) {
65
+ return pair.first ;
66
+ });
67
+ return outpoints;
64
68
}
65
69
66
70
void CCoinControl::SetInputWeight (const COutPoint& outpoint, int64_t weight)
67
71
{
68
- m_input_weights [outpoint] = weight;
72
+ m_selected [outpoint]. SetInputWeight ( weight) ;
69
73
}
70
74
71
75
bool CCoinControl::HasInputWeight (const COutPoint& outpoint) const
72
76
{
73
- return m_input_weights.count (outpoint) > 0 ;
77
+ const auto it = m_selected.find (outpoint);
78
+ return it != m_selected.end () && it->second .HasInputWeight ();
74
79
}
75
80
76
81
int64_t CCoinControl::GetInputWeight (const COutPoint& outpoint) const
77
82
{
78
- auto it = m_input_weights.find (outpoint);
79
- assert (it != m_input_weights.end ());
80
- return it->second ;
83
+ return m_selected.at (outpoint).GetInputWeight ();
84
+ }
85
+
86
+ void PreselectedInput::SetTxOut (const CTxOut& txout)
87
+ {
88
+ m_txout = txout;
89
+ }
90
+
91
+ CTxOut PreselectedInput::GetTxOut () const
92
+ {
93
+ assert (m_txout.has_value ());
94
+ return m_txout.value ();
95
+ }
96
+
97
+ bool PreselectedInput::HasTxOut () const
98
+ {
99
+ return m_txout.has_value ();
100
+ }
101
+
102
+ void PreselectedInput::SetInputWeight (int64_t weight)
103
+ {
104
+ m_weight = weight;
105
+ }
106
+
107
+ int64_t PreselectedInput::GetInputWeight () const
108
+ {
109
+ assert (m_weight.has_value ());
110
+ return m_weight.value ();
111
+ }
112
+
113
+ bool PreselectedInput::HasInputWeight () const
114
+ {
115
+ return m_weight.has_value ();
81
116
}
82
117
} // namespace wallet
0 commit comments