@@ -14,69 +14,104 @@ CCoinControl::CCoinControl()
1414
1515bool CCoinControl::HasSelected () const
1616{
17- return !m_selected_inputs .empty ();
17+ return !m_selected .empty ();
1818}
1919
20- bool CCoinControl::IsSelected (const COutPoint& output ) const
20+ bool CCoinControl::IsSelected (const COutPoint& outpoint ) const
2121{
22- return m_selected_inputs .count (output ) > 0 ;
22+ return m_selected .count (outpoint ) > 0 ;
2323}
2424
25- bool CCoinControl::IsExternalSelected (const COutPoint& output ) const
25+ bool CCoinControl::IsExternalSelected (const COutPoint& outpoint ) const
2626{
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 ();
2829}
2930
3031std::optional<CTxOut> CCoinControl::GetExternalOutput (const COutPoint& outpoint) const
3132{
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 ()) {
3435 return std::nullopt ;
3536 }
36-
37- return std::make_optional (ext_it->second );
37+ return it->second .GetTxOut ();
3838}
3939
40- void CCoinControl::Select (const COutPoint& output )
40+ PreselectedInput& CCoinControl::Select (const COutPoint& outpoint )
4141{
42- m_selected_inputs. insert (output) ;
42+ return m_selected[outpoint] ;
4343}
4444
4545void CCoinControl::SelectExternal (const COutPoint& outpoint, const CTxOut& txout)
4646{
47- m_selected_inputs.insert (outpoint);
48- m_external_txouts.emplace (outpoint, txout);
47+ m_selected[outpoint].SetTxOut (txout);
4948}
5049
51- void CCoinControl::UnSelect (const COutPoint& output )
50+ void CCoinControl::UnSelect (const COutPoint& outpoint )
5251{
53- m_selected_inputs .erase (output );
52+ m_selected .erase (outpoint );
5453}
5554
5655void CCoinControl::UnSelectAll ()
5756{
58- m_selected_inputs .clear ();
57+ m_selected .clear ();
5958}
6059
6160std::vector<COutPoint> CCoinControl::ListSelected () const
6261{
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;
6468}
6569
6670void CCoinControl::SetInputWeight (const COutPoint& outpoint, int64_t weight)
6771{
68- m_input_weights [outpoint] = weight;
72+ m_selected [outpoint]. SetInputWeight ( weight) ;
6973}
7074
7175bool CCoinControl::HasInputWeight (const COutPoint& outpoint) const
7276{
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 ();
7479}
7580
7681int64_t CCoinControl::GetInputWeight (const COutPoint& outpoint) const
7782{
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 ();
81116}
82117} // namespace wallet
0 commit comments