summaryrefslogtreecommitdiff
path: root/patches/wownero/0004-coin-control.patch
blob: 45ed9d8fbe464594fc0050850dfacf6439ce1778 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
From 1d12f355eeeba80930f38d398c758154d2d4c340 Mon Sep 17 00:00:00 2001
From: Czarek Nakamoto <cyjan@mrcyjanek.net>
Date: Wed, 27 Mar 2024 16:31:36 +0100
Subject: [PATCH 4/4] coin control

---
 src/wallet/api/coins.cpp     | 62 ++++++++++++++++++++++++++++++++++++
 src/wallet/api/coins.h       |  4 +++
 src/wallet/api/wallet.cpp    |  4 +--
 src/wallet/api/wallet2_api.h |  3 ++
 src/wallet/wallet2.cpp       | 22 +++++++++++++
 src/wallet/wallet2.h         |  4 +++
 6 files changed, 97 insertions(+), 2 deletions(-)

diff --git a/src/wallet/api/coins.cpp b/src/wallet/api/coins.cpp
index fe54b82cf..5ce69b5b9 100644
--- a/src/wallet/api/coins.cpp
+++ b/src/wallet/api/coins.cpp
@@ -90,6 +90,26 @@ namespace Monero {
         }
     }
 
+    void CoinsImpl::setFrozen(std::string public_key)
+    {
+        crypto::public_key pk;
+        if (!epee::string_tools::hex_to_pod(public_key, pk))
+        {
+            LOG_ERROR("Invalid public key: " << public_key);
+            return;
+        }
+
+        try
+        {
+            m_wallet->m_wallet->freeze(pk);
+            refresh();
+        }
+        catch (const std::exception& e)
+        {
+            LOG_ERROR("setFrozen: " << e.what());
+        }
+    }
+
     void CoinsImpl::setFrozen(int index)
     {
         try
@@ -103,6 +123,26 @@ namespace Monero {
         }
     }
 
+    void CoinsImpl::thaw(std::string public_key)
+    {
+        crypto::public_key pk;
+        if (!epee::string_tools::hex_to_pod(public_key, pk))
+        {
+            LOG_ERROR("Invalid public key: " << public_key);
+            return;
+        }
+
+        try
+        {
+            m_wallet->m_wallet->thaw(pk);
+            refresh();
+        }
+        catch (const std::exception& e)
+        {
+            LOG_ERROR("thaw: " << e.what());
+        }
+    }
+
     void CoinsImpl::thaw(int index)
     {
         try
@@ -120,4 +160,26 @@ namespace Monero {
         return m_wallet->m_wallet->is_transfer_unlocked(unlockTime, blockHeight);
     }
 
+    void CoinsImpl::setDescription(const std::string &public_key, const std::string &description)
+    {
+        crypto::public_key pk;
+        if (!epee::string_tools::hex_to_pod(public_key, pk))
+        {
+            LOG_ERROR("Invalid public key: " << public_key);
+            return;
+        }
+
+        try
+        {
+            const size_t index = m_wallet->m_wallet->get_transfer_details(pk);
+            const tools::wallet2::transfer_details &td = m_wallet->m_wallet->get_transfer_details(index);
+            m_wallet->m_wallet->set_tx_note(td.m_txid, description);
+            refresh();
+        }
+        catch (const std::exception& e)
+        {
+            LOG_ERROR("setDescription: " << e.what());
+        }
+    }
+
 } // namespace
diff --git a/src/wallet/api/coins.h b/src/wallet/api/coins.h
index 3293d8ae9..bcd8b517f 100644
--- a/src/wallet/api/coins.h
+++ b/src/wallet/api/coins.h
@@ -18,11 +18,15 @@ namespace Monero {
         std::vector<CoinsInfo*> getAll() const override;
         void refresh() override;
 
+        void setFrozen(std::string public_key) override;
         void setFrozen(int index) override;
+        void thaw(std::string public_key) override;
         void thaw(int index) override;
 
         bool isTransferUnlocked(uint64_t unlockTime, uint64_t blockHeight) override;
 
+        void setDescription(const std::string &public_key, const std::string &description) override;
+
     private:
         WalletImpl *m_wallet;
         std::vector<CoinsInfo*> m_rows;
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 63ed26a11..3bbc60d74 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -2018,11 +2018,11 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
             if (amount) {
                 transaction->m_pending_tx = m_wallet->create_transactions_2(dsts, fake_outs_count, 0 /* unlock_time */,
                                                                             adjusted_priority,
-                                                                            extra, subaddr_account, subaddr_indices);
+                                                                            extra, subaddr_account, subaddr_indices, {}, preferred_input_list);
             } else {
                 transaction->m_pending_tx = m_wallet->create_transactions_all(0, info.address, info.is_subaddress, 1, fake_outs_count, 0 /* unlock_time */,
                                                                               adjusted_priority,
-                                                                              extra, subaddr_account, subaddr_indices);
+                                                                              extra, subaddr_account, subaddr_indices, preferred_input_list);
             }
             pendingTxPostProcess(transaction);
 
diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h
index c2fa3d95b..99616b025 100644
--- a/src/wallet/api/wallet2_api.h
+++ b/src/wallet/api/wallet2_api.h
@@ -352,9 +352,12 @@ struct Coins
     virtual CoinsInfo * coin(int index)  const = 0;
     virtual std::vector<CoinsInfo*> getAll() const = 0;
     virtual void refresh() = 0;
+    virtual void setFrozen(std::string public_key) = 0;
     virtual void setFrozen(int index) = 0;
     virtual void thaw(int index) = 0;
+    virtual void thaw(std::string public_key) = 0;
     virtual bool isTransferUnlocked(uint64_t unlockTime, uint64_t blockHeight) = 0;
+    virtual void setDescription(const std::string &public_key, const std::string &description) = 0;
 };
 
 struct SubaddressRow {
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 00d9c133e..ae0305d28 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -2092,11 +2092,21 @@ bool wallet2::frozen(const multisig_tx_set& txs) const
   return false;
 }
 //----------------------------------------------------------------------------------------------------
+void wallet2::freeze(const crypto::public_key &pk)
+{
+  freeze(get_transfer_details(pk));
+}
+//----------------------------------------------------------------------------------------------------
 void wallet2::freeze(const crypto::key_image &ki)
 {
   freeze(get_transfer_details(ki));
 }
 //----------------------------------------------------------------------------------------------------
+void wallet2::thaw(const crypto::public_key &pk)
+{
+  thaw(get_transfer_details(pk));
+}
+//----------------------------------------------------------------------------------------------------
 void wallet2::thaw(const crypto::key_image &ki)
 {
   thaw(get_transfer_details(ki));
@@ -2107,6 +2117,18 @@ bool wallet2::frozen(const crypto::key_image &ki) const
   return frozen(get_transfer_details(ki));
 }
 //----------------------------------------------------------------------------------------------------
+size_t wallet2::get_transfer_details(const crypto::public_key &pk) const
+{
+    for (size_t idx = 0; idx < m_transfers.size(); ++idx)
+    {
+        const transfer_details &td = m_transfers[idx];
+        if (td.get_public_key() == pk) {
+            return idx;
+        }
+    }
+    CHECK_AND_ASSERT_THROW_MES(false, "Public key not found");
+}
+//----------------------------------------------------------------------------------------------------
 size_t wallet2::get_transfer_details(const crypto::key_image &ki) const
 {
   for (size_t idx = 0; idx < m_transfers.size(); ++idx)
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 40997cdbb..6fa955681 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -1562,6 +1562,8 @@ private:
     uint64_t get_num_rct_outputs();
     size_t get_num_transfer_details() const { return m_transfers.size(); }
     const transfer_details &get_transfer_details(size_t idx) const;
+    size_t get_transfer_details(const crypto::public_key &pk) const;
+
 
     uint8_t get_current_hard_fork();
     void get_hard_fork_info(uint8_t version, uint64_t &earliest_height);
@@ -1792,7 +1794,9 @@ private:
     void freeze(size_t idx);
     void thaw(size_t idx);
     bool frozen(size_t idx) const;
+    void freeze(const crypto::public_key &pk);
     void freeze(const crypto::key_image &ki);
+    void thaw(const crypto::public_key &pk);
     void thaw(const crypto::key_image &ki);
     bool frozen(const crypto::key_image &ki) const;
     bool frozen(const transfer_details &td) const;
-- 
2.39.2