Debian Codegraph @

monero/src/wallet/wallet2.h

raw symbols SCIP
1 // Copyright (c) 2014-2022, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30
31 #pragma once
32
33 #include <memory>
34
35 #include <boost/program_options/options_description.hpp>
36 #include <boost/program_options/variables_map.hpp>
37 #if BOOST_VERSION >= 107400
38 #include <boost/serialization/library_version_type.hpp>
39 #endif
40 #include <boost/serialization/list.hpp>
41 #include <boost/serialization/vector.hpp>
42 #include <boost/serialization/deque.hpp>
43 #include <boost/thread/lock_guard.hpp>
44 #include <atomic>
45 #include <random>
46
47 #include "include_base_utils.h"
48 #include "cryptonote_basic/account.h"
49 #include "cryptonote_basic/account_boost_serialization.h"
50 #include "cryptonote_basic/cryptonote_basic_impl.h"
51 #include "net/http.h"
52 #include "storages/http_abstract_invoke.h"
53 #include "rpc/core_rpc_server_commands_defs.h"
54 #include "cryptonote_basic/cryptonote_format_utils.h"
55 #include "cryptonote_core/cryptonote_tx_utils.h"
56 #include "common/unordered_containers_boost_serialization.h"
57 #include "common/util.h"
58 #include "crypto/chacha.h"
59 #include "crypto/hash.h"
60 #include "ringct/rctTypes.h"
61 #include "ringct/rctOps.h"
62 #include "checkpoints/checkpoints.h"
63 #include "serialization/crypto.h"
64 #include "serialization/string.h"
65 #include "serialization/pair.h"
66 #include "serialization/tuple.h"
67 #include "serialization/containers.h"
68
69 #include "wallet_errors.h"
70 #include "common/password.h"
71 #include "node_rpc_proxy.h"
72 #include "message_store.h"
73 #include "wallet_light_rpc.h"
74 #include "wallet_rpc_helpers.h"
75
76 #undef MONERO_DEFAULT_LOG_CATEGORY
77 #define MONERO_DEFAULT_LOG_CATEGORY "wallet.wallet2"
78
79 #define THROW_ON_RPC_RESPONSE_ERROR(r, error, res, method, ...) \
80 do { \
81 handle_payment_changes(res, std::integral_constant<bool, HasCredits<decltype(res)>::Has>()); \
82 throw_on_rpc_response_error(r, error, res.status, method); \
83 THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, ## __VA_ARGS__); \
84 } while(0)
85
86 #define THROW_ON_RPC_RESPONSE_ERROR_GENERIC(r, err, res, method) \
87 THROW_ON_RPC_RESPONSE_ERROR(r, err, res, method, tools::error::wallet_generic_rpc_error, method, res.status)
88
89 class Serialization_portability_wallet_Test;
90 class wallet_accessor_test;
91
92 namespace tools
93 {
94 class ringdb;
95 class wallet2;
96 class Notify;
97
98 class gamma_picker
99 {
100 public:
101 uint64_t pick();
102 gamma_picker(const std::vector<uint64_t> &rct_offsets);
103 gamma_picker(const std::vector<uint64_t> &rct_offsets, double shape, double scale);
104 uint64_t get_num_rct_outs() const { return num_rct_outputs; }
105
106 private:
107 struct gamma_engine
108 {
109 typedef uint64_t result_type;
110 static constexpr result_type min() { return 0; }
111 static constexpr result_type max() { return std::numeric_limits<result_type>::max(); }
112 result_type operator()() { return crypto::rand<result_type>(); }
113 } engine;
114
115 private:
116 std::gamma_distribution<double> gamma;
117 const std::vector<uint64_t> &rct_offsets;
118 const uint64_t *begin, *end;
119 uint64_t num_rct_outputs;
120 double average_output_time;
121 };
122
123 class wallet_keys_unlocker
124 {
125 public:
126 wallet_keys_unlocker(wallet2 &w, const boost::optional<tools::password_container> &password);
127 wallet_keys_unlocker(wallet2 &w, bool locked, const epee::wipeable_string &password);
128 ~wallet_keys_unlocker();
129 private:
130 wallet2 &w;
131 bool locked;
132 crypto::chacha_key key;
133 static boost::mutex lockers_lock;
134 static unsigned int lockers;
135 };
136
137 class i_wallet2_callback
138 {
139 public:
140 // Full wallet callbacks
141 virtual void on_new_block(uint64_t height, const cryptonote::block& block) {}
142 virtual void on_reorg(uint64_t height, uint64_t blocks_detached, size_t transfers_detached) {}
143 virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, uint64_t burnt, const cryptonote::subaddress_index& subaddr_index, bool is_change, uint64_t unlock_time) {}
144 virtual void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index) {}
145 virtual void on_money_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& in_tx, uint64_t amount, const cryptonote::transaction& spend_tx, const cryptonote::subaddress_index& subaddr_index) {}
146 virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx) {}
147 virtual boost::optional<epee::wipeable_string> on_get_password(const char *reason) { return boost::none; }
148 // Light wallet callbacks
149 virtual void on_lw_new_block(uint64_t height) {}
150 virtual void on_lw_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount) {}
151 virtual void on_lw_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount) {}
152 virtual void on_lw_money_spent(uint64_t height, const crypto::hash &txid, uint64_t amount) {}
153 // Device callbacks
154 virtual void on_device_button_request(uint64_t code) {}
155 virtual void on_device_button_pressed() {}
156 virtual void on_device_error(const std::string &msg, unsigned int errorCode) {}
157 virtual boost::optional<epee::wipeable_string> on_device_pin_request() { return boost::none; }
158 virtual boost::optional<epee::wipeable_string> on_device_passphrase_request(bool & on_device) { on_device = true; return boost::none; }
159 virtual void on_device_progress(const hw::device_progress& event) {};
160 // Common callbacks
161 virtual void on_pool_tx_removed(const crypto::hash &txid) {}
162 virtual ~i_wallet2_callback() {}
163 };
164
165 class wallet_device_callback : public hw::i_device_callback
166 {
167 public:
168 wallet_device_callback(wallet2 * wallet): wallet(wallet) {};
169 void on_button_request(uint64_t code=0) override;
170 void on_button_pressed() override;
171 void on_error(const std::string &message, unsigned int error_code) override;
172 boost::optional<epee::wipeable_string> on_pin_request() override;
173 boost::optional<epee::wipeable_string> on_passphrase_request(bool & on_device) override;
174 void on_progress(const hw::device_progress& event) override;
175 private:
176 wallet2 * wallet;
177 };
178
179 struct tx_dust_policy
180 {
181 uint64_t dust_threshold;
182 bool add_to_fee;
183 cryptonote::account_public_address addr_for_dust;
184
185 tx_dust_policy(uint64_t a_dust_threshold = 0, bool an_add_to_fee = true, cryptonote::account_public_address an_addr_for_dust = cryptonote::account_public_address())
186 : dust_threshold(a_dust_threshold)
187 , add_to_fee(an_add_to_fee)
188 , addr_for_dust(an_addr_for_dust)
189 {
190 }
191 };
192
193 class rct_offsets
194 {
195 public:
196 rct_offsets() : m_start_height(0) {}
197
198 void init(uint64_t start_height, const std::vector<uint64_t>& offsets) {m_start_height = start_height; m_offsets = offsets;}
199 size_t size() const { return m_offsets.size() + m_start_height; }
200 size_t start_height() const { return m_start_height; }
201 void push_back(uint64_t offset) { m_offsets.push_back(m_offsets.back() + offset); }
202 uint64_t back() { return m_offsets.back(); }
203 bool empty() { return m_offsets.empty(); }
204 uint64_t &operator[](size_t idx) { return m_offsets[idx - m_start_height]; }
205 void crop(size_t height) { m_offsets.resize(height - m_start_height); }
206 void clear() { m_start_height = 0, m_offsets.clear(); }
207 std::vector<uint64_t>& offsets() {return m_offsets;}
208
209 BEGIN_SERIALIZE_OBJECT()
210 VARINT_FIELD(m_start_height)
211 FIELD(m_offsets)
212 END_SERIALIZE()
213
214 private:
215 size_t m_start_height;
216 std::vector<uint64_t> m_offsets;
217 };
218
219 class hashchain
220 {
221 public:
222 hashchain(): m_genesis(crypto::null_hash), m_offset(0) {}
223
224 size_t size() const { return m_blockchain.size() + m_offset; }
225 size_t offset() const { return m_offset; }
226 const crypto::hash &genesis() const { return m_genesis; }
227 void push_back(const crypto::hash &hash) { if (m_offset == 0 && m_blockchain.empty()) m_genesis = hash; m_blockchain.push_back(hash); }
228 bool is_in_bounds(size_t idx) const { return idx >= m_offset && idx < size(); }
229 const crypto::hash &operator[](size_t idx) const { return m_blockchain[idx - m_offset]; }
230 crypto::hash &operator[](size_t idx) { return m_blockchain[idx - m_offset]; }
231 void crop(size_t height) { m_blockchain.resize(height - m_offset); }
232 void clear() { m_offset = 0; m_blockchain.clear(); }
233 bool empty() const { return m_blockchain.empty() && m_offset == 0; }
234 void trim(size_t height) { while (height > m_offset && m_blockchain.size() > 1) { m_blockchain.pop_front(); ++m_offset; } m_blockchain.shrink_to_fit(); }
235 void refill(const crypto::hash &hash) { m_blockchain.push_back(hash); --m_offset; }
236
237 template <class t_archive>
238 inline void serialize(t_archive &a, const unsigned int ver)
239 {
240 a & m_offset;
241 a & m_genesis;
242 a & m_blockchain;
243 }
244
245 BEGIN_SERIALIZE_OBJECT()
246 VERSION_FIELD(0)
247 VARINT_FIELD(m_offset)
248 FIELD(m_genesis)
249 FIELD(m_blockchain)
250 END_SERIALIZE()
251
252 private:
253 size_t m_offset;
254 crypto::hash m_genesis;
255 std::deque<crypto::hash> m_blockchain;
256 };
257
258 class wallet_keys_unlocker;
259 class wallet2
260 {
261 friend class ::Serialization_portability_wallet_Test;
262 friend class ::wallet_accessor_test;
263 friend class wallet_keys_unlocker;
264 friend class wallet_device_callback;
265 public:
266 static constexpr const std::chrono::seconds rpc_timeout = std::chrono::seconds(10);
267
268 enum RefreshType {
269 RefreshFull,
270 RefreshOptimizeCoinbase,
271 RefreshNoCoinbase,
272 RefreshDefault = RefreshOptimizeCoinbase,
273 };
274
275 enum AskPasswordType {
276 AskPasswordNever = 0,
277 AskPasswordOnAction = 1,
278 AskPasswordToDecrypt = 2,
279 };
280
281 enum BackgroundMiningSetupType {
282 BackgroundMiningMaybe = 0,
283 BackgroundMiningYes = 1,
284 BackgroundMiningNo = 2,
285 };
286
287 enum BackgroundSyncType {
288 BackgroundSyncOff = 0,
289 BackgroundSyncReusePassword = 1,
290 BackgroundSyncCustomPassword = 2,
291 };
292
293 static BackgroundSyncType background_sync_type_from_str(const std::string &background_sync_type_str)
294 {
295 if (background_sync_type_str == "off") return BackgroundSyncOff;
296 if (background_sync_type_str == "reuse-wallet-password") return BackgroundSyncReusePassword;
297 if (background_sync_type_str == "custom-background-password") return BackgroundSyncCustomPassword;
298 throw std::logic_error("Unknown background sync type");
299 };
300
301 enum ExportFormat {
302 Binary = 0,
303 Ascii,
304 };
305
306 static const char* tr(const char* str);
307
308 static bool has_testnet_option(const boost::program_options::variables_map& vm);
309 static bool has_stagenet_option(const boost::program_options::variables_map& vm);
310 static std::string device_name_option(const boost::program_options::variables_map& vm);
311 static std::string device_derivation_path_option(const boost::program_options::variables_map &vm);
312 static void init_options(boost::program_options::options_description& desc_params);
313
314 //! Uses stdin and stdout. Returns a wallet2 if no errors.
315 static std::pair<std::unique_ptr<wallet2>, password_container> make_from_json(const boost::program_options::variables_map& vm, bool unattended, const std::string& json_file, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter);
316
317 //! Uses stdin and stdout. Returns a wallet2 and password for `wallet_file` if no errors.
318 static std::pair<std::unique_ptr<wallet2>, password_container>
319 make_from_file(const boost::program_options::variables_map& vm, bool unattended, const std::string& wallet_file, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter);
320
321 //! Uses stdin and stdout. Returns a wallet2 and password for wallet with no file if no errors.
322 static std::pair<std::unique_ptr<wallet2>, password_container> make_new(const boost::program_options::variables_map& vm, bool unattended, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter);
323
324 //! Just parses variables.
325 static std::unique_ptr<wallet2> make_dummy(const boost::program_options::variables_map& vm, bool unattended, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter);
326
327 static bool verify_password(const std::string& keys_file_name, const epee::wipeable_string& password, bool no_spend_key, hw::device &hwdev, uint64_t kdf_rounds)
328 {
329 crypto::secret_key spend_key = crypto::null_skey;
330 return verify_password(keys_file_name, password, no_spend_key, hwdev, kdf_rounds, spend_key);
331 };
332 static bool verify_password(const std::string& keys_file_name, const epee::wipeable_string& password, bool no_spend_key, hw::device &hwdev, uint64_t kdf_rounds, crypto::secret_key &spend_key_out);
333 static bool query_device(hw::device::device_type& device_type, const std::string& keys_file_name, const epee::wipeable_string& password, uint64_t kdf_rounds = 1);
334
335 wallet2(cryptonote::network_type nettype = cryptonote::MAINNET, uint64_t kdf_rounds = 1, bool unattended = false, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory = std::unique_ptr<epee::net_utils::http::http_client_factory>(new net::http::client_factory()));
336 ~wallet2();
337
338 struct multisig_info
339 {
340 struct LR
341 {
342 rct::key m_L;
343 rct::key m_R;
344
345 BEGIN_SERIALIZE_OBJECT()
346 FIELD(m_L)
347 FIELD(m_R)
348 END_SERIALIZE()
349 };
350
351 crypto::public_key m_signer;
352 std::vector<LR> m_LR;
353 std::vector<crypto::key_image> m_partial_key_images; // one per key the participant has
354
355 BEGIN_SERIALIZE_OBJECT()
356 FIELD(m_signer)
357 FIELD(m_LR)
358 FIELD(m_partial_key_images)
359 END_SERIALIZE()
360 };
361
362 struct tx_scan_info_t
363 {
364 cryptonote::keypair in_ephemeral;
365 crypto::key_image ki;
366 rct::key mask;
367 uint64_t amount;
368 uint64_t money_transfered;
369 bool error;
370 boost::optional<cryptonote::subaddress_receive_info> received;
371
372 tx_scan_info_t(): amount(0), money_transfered(0), error(true) {}
373 };
374
375 struct transfer_details
376 {
377 uint64_t m_block_height;
378 cryptonote::transaction_prefix m_tx;
379 crypto::hash m_txid;
380 uint64_t m_internal_output_index;
381 uint64_t m_global_output_index;
382 bool m_spent;
383 bool m_frozen;
384 uint64_t m_spent_height;
385 crypto::key_image m_key_image; //TODO: key_image stored twice :(
386 rct::key m_mask;
387 uint64_t m_amount;
388 bool m_rct;
389 bool m_key_image_known;
390 bool m_key_image_request; // view wallets: we want to request it; cold wallets: it was requested
391 uint64_t m_pk_index;
392 cryptonote::subaddress_index m_subaddr_index;
393 bool m_key_image_partial;
394 std::vector<rct::key> m_multisig_k;
395 std::vector<multisig_info> m_multisig_info; // one per other participant
396 std::vector<std::pair<uint64_t, crypto::hash>> m_uses;
397
398 bool is_rct() const { return m_rct; }
399 uint64_t amount() const { return m_amount; }
400 const crypto::public_key get_public_key() const {
401 crypto::public_key output_public_key;
402 THROW_WALLET_EXCEPTION_IF(m_tx.vout.size() <= m_internal_output_index,
403 error::wallet_internal_error, "Too few outputs, outputs may be corrupted");
404 THROW_WALLET_EXCEPTION_IF(!get_output_public_key(m_tx.vout[m_internal_output_index], output_public_key),
405 error::wallet_internal_error, "Unable to get output public key from output");
406 return output_public_key;
407 };
408
409 BEGIN_SERIALIZE_OBJECT()
410 FIELD(m_block_height)
411 FIELD(m_tx)
412 FIELD(m_txid)
413 FIELD(m_internal_output_index)
414 FIELD(m_global_output_index)
415 FIELD(m_spent)
416 FIELD(m_frozen)
417 FIELD(m_spent_height)
418 FIELD(m_key_image)
419 FIELD(m_mask)
420 FIELD(m_amount)
421 FIELD(m_rct)
422 FIELD(m_key_image_known)
423 FIELD(m_key_image_request)
424 FIELD(m_pk_index)
425 FIELD(m_subaddr_index)
426 FIELD(m_key_image_partial)
427 FIELD(m_multisig_k)
428 FIELD(m_multisig_info)
429 FIELD(m_uses)
430 END_SERIALIZE()
431 };
432
433 struct exported_transfer_details
434 {
435 crypto::public_key m_pubkey;
436 uint64_t m_internal_output_index;
437 uint64_t m_global_output_index;
438 crypto::public_key m_tx_pubkey;
439 union
440 {
441 struct
442 {
443 uint8_t m_spent: 1;
444 uint8_t m_frozen: 1;
445 uint8_t m_rct: 1;
446 uint8_t m_key_image_known: 1;
447 uint8_t m_key_image_request: 1; // view wallets: we want to request it; cold wallets: it was requested
448 uint8_t m_key_image_partial: 1;
449 };
450 uint8_t flags;
451 } m_flags;
452 uint64_t m_amount;
453 std::vector<crypto::public_key> m_additional_tx_keys;
454 uint32_t m_subaddr_index_major;
455 uint32_t m_subaddr_index_minor;
456
457 BEGIN_SERIALIZE_OBJECT()
458 VERSION_FIELD(1)
459 if (version < 1)
460 return false;
461 FIELD(m_pubkey)
462 VARINT_FIELD(m_internal_output_index)
463 VARINT_FIELD(m_global_output_index)
464 FIELD(m_tx_pubkey)
465 FIELD(m_flags.flags)
466 VARINT_FIELD(m_amount)
467 FIELD(m_additional_tx_keys)
468 VARINT_FIELD(m_subaddr_index_major)
469 VARINT_FIELD(m_subaddr_index_minor)
470 END_SERIALIZE()
471 };
472
473 typedef std::vector<uint64_t> amounts_container;
474 struct payment_details
475 {
476 crypto::hash m_tx_hash;
477 uint64_t m_amount;
478 amounts_container m_amounts;
479 uint64_t m_fee;
480 uint64_t m_block_height;
481 uint64_t m_unlock_time;
482 uint64_t m_timestamp;
483 bool m_coinbase;
484 cryptonote::subaddress_index m_subaddr_index;
485
486 BEGIN_SERIALIZE_OBJECT()
487 VERSION_FIELD(0)
488 FIELD(m_tx_hash)
489 VARINT_FIELD(m_amount)
490 FIELD(m_amounts)
491 VARINT_FIELD(m_fee)
492 VARINT_FIELD(m_block_height)
493 VARINT_FIELD(m_unlock_time)
494 VARINT_FIELD(m_timestamp)
495 FIELD(m_coinbase)
496 FIELD(m_subaddr_index)
497 END_SERIALIZE()
498 };
499
500 struct address_tx : payment_details
501 {
502 bool m_mempool;
503 bool m_incoming;
504 };
505
506 struct pool_payment_details
507 {
508 payment_details m_pd;
509 bool m_double_spend_seen;
510
511 BEGIN_SERIALIZE_OBJECT()
512 VERSION_FIELD(0)
513 FIELD(m_pd)
514 FIELD(m_double_spend_seen)
515 END_SERIALIZE()
516 };
517
518 struct unconfirmed_transfer_details
519 {
520 cryptonote::transaction_prefix m_tx;
521 uint64_t m_amount_in;
522 uint64_t m_amount_out;
523 uint64_t m_change;
524 time_t m_sent_time;
525 std::vector<cryptonote::tx_destination_entry> m_dests;
526 crypto::hash m_payment_id;
527 enum { pending, pending_in_pool, failed } m_state;
528 uint64_t m_timestamp;
529 uint32_t m_subaddr_account; // subaddress account of your wallet to be used in this transfer
530 std::set<uint32_t> m_subaddr_indices; // set of address indices used as inputs in this transfer
531 std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> m_rings; // relative
532
533 BEGIN_SERIALIZE_OBJECT()
534 VERSION_FIELD(1)
535 FIELD(m_tx)
536 VARINT_FIELD(m_amount_in)
537 VARINT_FIELD(m_amount_out)
538 VARINT_FIELD(m_change)
539 VARINT_FIELD(m_sent_time)
540 FIELD(m_dests)
541 FIELD(m_payment_id)
542 if (version >= 1)
543 VARINT_FIELD(m_state)
544 VARINT_FIELD(m_timestamp)
545 VARINT_FIELD(m_subaddr_account)
546 FIELD(m_subaddr_indices)
547 FIELD(m_rings)
548 END_SERIALIZE()
549 };
550
551 struct confirmed_transfer_details
552 {
553 cryptonote::transaction_prefix m_tx;
554 uint64_t m_amount_in;
555 uint64_t m_amount_out;
556 uint64_t m_change;
557 uint64_t m_block_height;
558 std::vector<cryptonote::tx_destination_entry> m_dests;
559 crypto::hash m_payment_id;
560 uint64_t m_timestamp;
561 uint64_t m_unlock_time;
562 uint32_t m_subaddr_account; // subaddress account of your wallet to be used in this transfer
563 std::set<uint32_t> m_subaddr_indices; // set of address indices used as inputs in this transfer
564 std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> m_rings; // relative
565
566 confirmed_transfer_details(): m_amount_in(0), m_amount_out(0), m_change((uint64_t)-1), m_block_height(0), m_payment_id(crypto::null_hash), m_timestamp(0), m_unlock_time(0), m_subaddr_account((uint32_t)-1) {}
567 confirmed_transfer_details(const unconfirmed_transfer_details &utd, uint64_t height):
568 m_tx(utd.m_tx), m_amount_in(utd.m_amount_in), m_amount_out(utd.m_amount_out), m_change(utd.m_change), m_block_height(height), m_dests(utd.m_dests), m_payment_id(utd.m_payment_id), m_timestamp(utd.m_timestamp), m_unlock_time(utd.m_tx.unlock_time), m_subaddr_account(utd.m_subaddr_account), m_subaddr_indices(utd.m_subaddr_indices), m_rings(utd.m_rings) {}
569
570 BEGIN_SERIALIZE_OBJECT()
571 VERSION_FIELD(1)
572 if (version >= 1)
573 FIELD(m_tx)
574 VARINT_FIELD(m_amount_in)
575 VARINT_FIELD(m_amount_out)
576 VARINT_FIELD(m_change)
577 VARINT_FIELD(m_block_height)
578 FIELD(m_dests)
579 FIELD(m_payment_id)
580 VARINT_FIELD(m_timestamp)
581 VARINT_FIELD(m_unlock_time)
582 VARINT_FIELD(m_subaddr_account)
583 FIELD(m_subaddr_indices)
584 FIELD(m_rings)
585 END_SERIALIZE()
586 };
587
588 struct tx_construction_data
589 {
590 std::vector<cryptonote::tx_source_entry> sources;
591 cryptonote::tx_destination_entry change_dts;
592 std::vector<cryptonote::tx_destination_entry> splitted_dsts; // split, includes change
593 std::vector<size_t> selected_transfers;
594 std::vector<uint8_t> extra;
595 uint64_t unlock_time;
596 bool use_rct;
597 rct::RCTConfig rct_config;
598 bool use_view_tags;
599 std::vector<cryptonote::tx_destination_entry> dests; // original setup, does not include change
600 uint32_t subaddr_account; // subaddress account of your wallet to be used in this transfer
601 std::set<uint32_t> subaddr_indices; // set of address indices used as inputs in this transfer
602
603 enum construction_flags_ : uint8_t
604 {
605 _use_rct = 1 << 0, // 00000001
606 _use_view_tags = 1 << 1 // 00000010
607 // next flag = 1 << 2 // 00000100
608 // ...
609 // final flag = 1 << 7 // 10000000
610 };
611 uint8_t construction_flags;
612
613 BEGIN_SERIALIZE_OBJECT()
614 FIELD(sources)
615 FIELD(change_dts)
616 FIELD(splitted_dsts)
617 FIELD(selected_transfers)
618 FIELD(extra)
619 FIELD(unlock_time)
620
621 // converted `use_rct` field into construction_flags when view tags
622 // were introduced to maintain backwards compatibility
623 if (!typename Archive<W>::is_saving())
624 {
625 FIELD_N("use_rct", construction_flags)
626 use_rct = (construction_flags & _use_rct) > 0;
627 use_view_tags = (construction_flags & _use_view_tags) > 0;
628 }
629 else
630 {
631 construction_flags = 0;
632 if (use_rct)
633 construction_flags ^= _use_rct;
634 if (use_view_tags)
635 construction_flags ^= _use_view_tags;
636
637 FIELD_N("use_rct", construction_flags)
638 }
639
640 FIELD(rct_config)
641 FIELD(dests)
642 FIELD(subaddr_account)
643 FIELD(subaddr_indices)
644 END_SERIALIZE()
645 };
646
647 typedef std::vector<transfer_details> transfer_container;
648 typedef serializable_unordered_multimap<crypto::hash, payment_details> payment_container;
649 typedef std::set<uint32_t> unique_index_container;
650
651 struct multisig_sig
652 {
653 rct::rctSig sigs;
654 std::unordered_set<crypto::public_key> ignore;
655 std::unordered_set<rct::key> used_L;
656 std::unordered_set<crypto::public_key> signing_keys;
657 rct::multisig_out msout;
658
659 rct::keyM total_alpha_G;
660 rct::keyM total_alpha_H;
661 rct::keyV c_0;
662 rct::keyV s;
663
664 BEGIN_SERIALIZE_OBJECT()
665 VERSION_FIELD(1)
666 if (version < 1)
667 return false;
668 FIELD(sigs)
669 FIELD(ignore)
670 FIELD(used_L)
671 FIELD(signing_keys)
672 FIELD(msout)
673 FIELD(total_alpha_G)
674 FIELD(total_alpha_H)
675 FIELD(c_0)
676 FIELD(s)
677 END_SERIALIZE()
678 };
679
680 // The convention for destinations is:
681 // dests does not include change
682 // splitted_dsts (in construction_data) does
683 struct pending_tx
684 {
685 cryptonote::transaction tx;
686 uint64_t dust, fee;
687 bool dust_added_to_fee;
688 cryptonote::tx_destination_entry change_dts;
689 std::vector<size_t> selected_transfers;
690 std::string key_images;
691 crypto::secret_key tx_key;
692 std::vector<crypto::secret_key> additional_tx_keys;
693 std::vector<cryptonote::tx_destination_entry> dests;
694 std::vector<multisig_sig> multisig_sigs;
695 crypto::secret_key multisig_tx_key_entropy;
696
697 tx_construction_data construction_data;
698
699 BEGIN_SERIALIZE_OBJECT()
700 VERSION_FIELD(1)
701 FIELD(tx)
702 FIELD(dust)
703 FIELD(fee)
704 FIELD(dust_added_to_fee)
705 FIELD(change_dts)
706 FIELD(selected_transfers)
707 FIELD(key_images)
708 FIELD(tx_key)
709 FIELD(additional_tx_keys)
710 FIELD(dests)
711 FIELD(construction_data)
712 FIELD(multisig_sigs)
713 if (version < 1)
714 {
715 multisig_tx_key_entropy = crypto::null_skey;
716 return true;
717 }
718 FIELD(multisig_tx_key_entropy)
719 END_SERIALIZE()
720 };
721
722 // The term "Unsigned tx" is not really a tx since it's not signed yet.
723 // It doesnt have tx hash, key and the integrated address is not separated into addr + payment id.
724 struct unsigned_tx_set
725 {
726 std::vector<tx_construction_data> txes;
727 std::tuple<uint64_t, uint64_t, wallet2::transfer_container> transfers;
728 std::tuple<uint64_t, uint64_t, std::vector<wallet2::exported_transfer_details>> new_transfers;
729
730 BEGIN_SERIALIZE_OBJECT()
731 VERSION_FIELD(2)
732 FIELD(txes)
733 if (version == 0)
734 {
735 std::pair<size_t, wallet2::transfer_container> v0_transfers;
736 FIELD(v0_transfers);
737 std::get<0>(transfers) = std::get<0>(v0_transfers);
738 std::get<1>(transfers) = std::get<0>(v0_transfers) + std::get<1>(v0_transfers).size();
739 std::get<2>(transfers) = std::get<1>(v0_transfers);
740 return true;
741 }
742 if (version == 1)
743 {
744 std::pair<size_t, std::vector<wallet2::exported_transfer_details>> v1_transfers;
745 FIELD(v1_transfers);
746 std::get<0>(new_transfers) = std::get<0>(v1_transfers);
747 std::get<1>(new_transfers) = std::get<0>(v1_transfers) + std::get<1>(v1_transfers).size();
748 std::get<2>(new_transfers) = std::get<1>(v1_transfers);
749 return true;
750 }
751
752 FIELD(new_transfers)
753 END_SERIALIZE()
754 };
755
756 struct signed_tx_set
757 {
758 std::vector<pending_tx> ptx;
759 std::vector<crypto::key_image> key_images;
760 serializable_unordered_map<crypto::public_key, crypto::key_image> tx_key_images;
761
762 BEGIN_SERIALIZE_OBJECT()
763 VERSION_FIELD(0)
764 FIELD(ptx)
765 FIELD(key_images)
766 FIELD(tx_key_images)
767 END_SERIALIZE()
768 };
769
770 struct multisig_tx_set
771 {
772 std::vector<pending_tx> m_ptx;
773 std::unordered_set<crypto::public_key> m_signers;
774
775 BEGIN_SERIALIZE_OBJECT()
776 FIELD(m_ptx)
777 FIELD(m_signers)
778 END_SERIALIZE()
779 };
780
781 struct keys_file_data
782 {
783 crypto::chacha_iv iv;
784 std::string account_data;
785
786 BEGIN_SERIALIZE_OBJECT()
787 FIELD(iv)
788 FIELD(account_data)
789 END_SERIALIZE()
790 };
791
792 struct cache_file_data
793 {
794 crypto::chacha_iv iv;
795 std::string cache_data;
796
797 BEGIN_SERIALIZE_OBJECT()
798 FIELD(iv)
799 FIELD(cache_data)
800 END_SERIALIZE()
801 };
802
803 // GUI Address book
804 struct address_book_row
805 {
806 cryptonote::account_public_address m_address;
807 crypto::hash8 m_payment_id;
808 std::string m_description;
809 bool m_is_subaddress;
810 bool m_has_payment_id;
811
812 BEGIN_SERIALIZE_OBJECT()
813 VERSION_FIELD(0)
814 FIELD(m_address)
815 FIELD(m_payment_id)
816 FIELD(m_description)
817 FIELD(m_is_subaddress)
818 FIELD(m_has_payment_id)
819 END_SERIALIZE()
820 };
821
822 struct reserve_proof_entry
823 {
824 crypto::hash txid;
825 uint64_t index_in_tx;
826 crypto::public_key shared_secret;
827 crypto::key_image key_image;
828 crypto::signature shared_secret_sig;
829 crypto::signature key_image_sig;
830
831 BEGIN_SERIALIZE_OBJECT()
832 VERSION_FIELD(0)
833 FIELD(txid)
834 VARINT_FIELD(index_in_tx)
835 FIELD(shared_secret)
836 FIELD(key_image)
837 FIELD(shared_secret_sig)
838 FIELD(key_image_sig)
839 END_SERIALIZE()
840 };
841
842 struct background_synced_tx_t
843 {
844 uint64_t index_in_background_sync_data;
845 cryptonote::transaction tx;
846 std::vector<uint64_t> output_indices;
847 uint64_t height;
848 uint64_t block_timestamp;
849 bool double_spend_seen;
850
851 BEGIN_SERIALIZE_OBJECT()
852 VERSION_FIELD(0)
853 VARINT_FIELD(index_in_background_sync_data)
854
855 // prune tx; don't need to keep signature data
856 if (!tx.serialize_base(ar))
857 return false;
858
859 FIELD(output_indices)
860 VARINT_FIELD(height)
861 VARINT_FIELD(block_timestamp)
862 FIELD(double_spend_seen)
863 END_SERIALIZE()
864 };
865
866 struct background_sync_data_t
867 {
868 bool first_refresh_done = false;
869 uint64_t start_height = 0;
870 serializable_unordered_map<crypto::hash, background_synced_tx_t> txs;
871
872 // Relevant wallet settings
873 uint64_t wallet_refresh_from_block_height;
874 size_t subaddress_lookahead_major;
875 size_t subaddress_lookahead_minor;
876 RefreshType wallet_refresh_type;
877
878 BEGIN_SERIALIZE_OBJECT()
879 VERSION_FIELD(0)
880 FIELD(first_refresh_done)
881 FIELD(start_height)
882 FIELD(txs)
883 FIELD(wallet_refresh_from_block_height)
884 VARINT_FIELD(subaddress_lookahead_major)
885 VARINT_FIELD(subaddress_lookahead_minor)
886 VARINT_FIELD(wallet_refresh_type)
887 END_SERIALIZE()
888 };
889
890 typedef std::tuple<uint64_t, crypto::public_key, rct::key> get_outs_entry;
891
892 struct parsed_block
893 {
894 crypto::hash hash;
895 cryptonote::block block;
896 std::vector<cryptonote::transaction> txes;
897 cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices o_indices;
898 bool error;
899 };
900
901 struct is_out_data
902 {
903 crypto::public_key pkey;
904 crypto::key_derivation derivation;
905 std::vector<boost::optional<cryptonote::subaddress_receive_info>> received;
906 };
907
908 struct tx_cache_data
909 {
910 std::vector<cryptonote::tx_extra_field> tx_extra_fields;
911 std::vector<is_out_data> primary;
912 std::vector<is_out_data> additional;
913
914 bool empty() const { return tx_extra_fields.empty() && primary.empty() && additional.empty(); }
915 };
916
917 struct detached_blockchain_data
918 {
919 hashchain detached_blockchain;
920 size_t original_chain_size;
921 std::unordered_set<crypto::hash> detached_tx_hashes;
922 std::unordered_map<crypto::hash, std::vector<cryptonote::tx_destination_entry>> detached_confirmed_txs_dests;
923 };
924
925 struct process_tx_entry_t
926 {
927 cryptonote::COMMAND_RPC_GET_TRANSACTIONS::entry tx_entry;
928 cryptonote::transaction tx;
929 crypto::hash tx_hash;
930 };
931
932 struct tx_entry_data
933 {
934 std::vector<process_tx_entry_t> tx_entries;
935 uint64_t lowest_height;
936 uint64_t highest_height;
937
938 tx_entry_data(): lowest_height((uint64_t)-1), highest_height(0) {}
939 };
940
941 /*!
942 * \brief Generates a wallet or restores one. Assumes the multisig setup
943 * has already completed for the provided multisig info.
944 * \param wallet_ Name of wallet file
945 * \param password Password of wallet file
946 * \param multisig_data The multisig restore info and keys
947 * \param create_address_file Whether to create an address file
948 */
949 void generate(const std::string& wallet_, const epee::wipeable_string& password,
950 const epee::wipeable_string& multisig_data, bool create_address_file = false);
951
952 /*!
953 * \brief Generates a wallet or restores one.
954 * \param wallet_ Name of wallet file
955 * \param password Password of wallet file
956 * \param recovery_param If it is a restore, the recovery key
957 * \param recover Whether it is a restore
958 * \param two_random Whether it is a non-deterministic wallet
959 * \param create_address_file Whether to create an address file
960 * \return The secret key of the generated wallet
961 */
962 crypto::secret_key generate(const std::string& wallet, const epee::wipeable_string& password,
963 const crypto::secret_key& recovery_param = crypto::secret_key(), bool recover = false,
964 bool two_random = false, bool create_address_file = false);
965 /*!
966 * \brief Creates a wallet from a public address and a spend/view secret key pair.
967 * \param wallet_ Name of wallet file
968 * \param password Password of wallet file
969 * \param account_public_address The account's public address
970 * \param spendkey spend secret key
971 * \param viewkey view secret key
972 * \param create_address_file Whether to create an address file
973 */
974 void generate(const std::string& wallet, const epee::wipeable_string& password,
975 const cryptonote::account_public_address &account_public_address,
976 const crypto::secret_key& spendkey, const crypto::secret_key& viewkey, bool create_address_file = false);
977 /*!
978 * \brief Creates a watch only wallet from a public address and a view secret key.
979 * \param wallet_ Name of wallet file
980 * \param password Password of wallet file
981 * \param account_public_address The account's public address
982 * \param viewkey view secret key
983 * \param create_address_file Whether to create an address file
984 */
985 void generate(const std::string& wallet, const epee::wipeable_string& password,
986 const cryptonote::account_public_address &account_public_address,
987 const crypto::secret_key& viewkey = crypto::secret_key(), bool create_address_file = false);
988 /*!
989 * \brief Restore a wallet hold by an HW.
990 * \param wallet_ Name of wallet file
991 * \param password Password of wallet file
992 * \param device_name name of HW to use
993 * \param create_address_file Whether to create an address file
994 */
995 void restore(const std::string& wallet_, const epee::wipeable_string& password, const std::string &device_name, bool create_address_file = false);
996
997 /*!
998 * \brief Creates a multisig wallet
999 * \return empty if done, non empty if we need to send another string
1000 * to other participants
1001 */
1002 std::string make_multisig(const epee::wipeable_string &password,
1003 const std::vector<std::string> &kex_messages,
1004 const std::uint32_t threshold);
1005 /*!
1006 * \brief Increment the multisig key exchange round
1007 * \return empty if done, non empty if we need to send another string
1008 * to other participants
1009 */
1010 std::string exchange_multisig_keys(const epee::wipeable_string &password,
1011 const std::vector<std::string> &kex_messages,
1012 const bool force_update_use_with_caution = false);
1013 /*!
1014 * \brief Get initial message to start multisig key exchange (before 'make_multisig()' is called)
1015 * \return string to send to other participants
1016 */
1017 std::string get_multisig_first_kex_msg() const;
1018 /*!
1019 * Export multisig info
1020 * This will generate and remember new k values
1021 */
1022 cryptonote::blobdata export_multisig();
1023 /*!
1024 * Import a set of multisig info from multisig partners
1025 * \return the number of inputs which were imported
1026 */
1027 size_t import_multisig(std::vector<cryptonote::blobdata> info);
1028 /*!
1029 * \brief Rewrites to the wallet file for wallet upgrade (doesn't generate key, assumes it's already there)
1030 * \param wallet_name Name of wallet file (should exist)
1031 * \param password Password for wallet file
1032 */
1033 void rewrite(const std::string& wallet_name, const epee::wipeable_string& password);
1034 void write_watch_only_wallet(const std::string& wallet_name, const epee::wipeable_string& password, std::string &new_keys_filename);
1035 void load(const std::string& wallet, const epee::wipeable_string& password, const std::string& keys_buf = "", const std::string& cache_buf = "");
1036 void store();
1037 /*!
1038 * \brief store_to Stores wallet to another file(s), deleting old ones
1039 * \param path Path to the wallet file (keys and address filenames will be generated based on this filename)
1040 * \param password Password that currently locks the wallet
1041 * \param force_rewrite_keys if true, always rewrite keys file
1042 *
1043 * Leave both "path" and "password" blank to restore the cache file to the current position in the disk
1044 * (which is the same as calling `store()`). If you want to store the wallet with a new password,
1045 * use the method `change_password()`.
1046 *
1047 * Normally the keys file is not overwritten when storing, except when force_rewrite_keys is true
1048 * or when `path` is a new wallet file.
1049 *
1050 * \throw error::invalid_password If storing keys file and old password is incorrect
1051 */
1052 void store_to(const std::string &path, const epee::wipeable_string &password, bool force_rewrite_keys = false);
1053 /*!
1054 * \brief get_keys_file_data Get wallet keys data which can be stored to a wallet file.
1055 * \param password Password that currently locks the wallet
1056 * \param watch_only true to include only view key, false to include both spend and view keys
1057 * \return Encrypted wallet keys data which can be stored to a wallet file
1058 * \throw error::invalid_password if password does not match current wallet
1059 */
1060 boost::optional<wallet2::keys_file_data> get_keys_file_data(const epee::wipeable_string& password, bool watch_only);
1061 /*!
1062 * \brief get_cache_file_data Get wallet cache data which can be stored to a wallet file.
1063 * \return Encrypted wallet cache data which can be stored to a wallet file (using current password)
1064 */
1065 boost::optional<wallet2::cache_file_data> get_cache_file_data();
1066
1067 std::string path() const;
1068
1069 /*!
1070 * \brief has_proxy_option Check the global proxy (--proxy) has been defined or not.
1071 * \return returns bool representing the global proxy (--proxy).
1072 */
1073 bool has_proxy_option() const;
1074
1075 /*!
1076 * \brief verifies given password is correct for default wallet keys file
1077 */
1078 bool verify_password(const epee::wipeable_string& password) {crypto::secret_key key = crypto::null_skey; return verify_password(password, key);};
1079 bool verify_password(const epee::wipeable_string& password, crypto::secret_key &spend_key_out);
1080 cryptonote::account_base& get_account(){return m_account;}
1081 const cryptonote::account_base& get_account()const{return m_account;}
1082
1083 bool verify_keys();
1084 void encrypt_keys(const crypto::chacha_key &key);
1085 void encrypt_keys(const epee::wipeable_string &password);
1086 void decrypt_keys(const crypto::chacha_key &key);
1087 void decrypt_keys(const epee::wipeable_string &password);
1088
1089 crypto::secret_key m_hw_view_key;
1090
1091 void set_refresh_from_block_height(uint64_t height) {m_refresh_from_block_height = height;}
1092 uint64_t get_refresh_from_block_height() const {return m_refresh_from_block_height;}
1093
1094 void explicit_refresh_from_block_height(bool expl) {m_explicit_refresh_from_block_height = expl;}
1095 bool explicit_refresh_from_block_height() const {return m_explicit_refresh_from_block_height;}
1096
1097 void max_reorg_depth(uint64_t depth) {m_max_reorg_depth = depth;}
1098 uint64_t max_reorg_depth() const {return m_max_reorg_depth;}
1099
1100 bool deinit();
1101 bool init(std::string daemon_address = "http://localhost:8080",
1102 boost::optional<epee::net_utils::http::login> daemon_login = boost::none,
1103 const std::string &proxy = "",
1104 uint64_t upper_transaction_weight_limit = 0,
1105 bool trusted_daemon = true,
1106 epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
1107 bool set_daemon(std::string daemon_address = "http://localhost:8080",
1108 boost::optional<epee::net_utils::http::login> daemon_login = boost::none, bool trusted_daemon = true,
1109 epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_autodetect,
1110 const std::string &proxy = "");
1111 bool set_proxy(const std::string &address);
1112
1113 void stop() {
1114 m_run.store(false, std::memory_order_relaxed);
1115 m_message_store.stop();
1116 m_http_client->cancel_read();
1117 }
1118
1119 i_wallet2_callback* callback() const { return m_callback; }
1120 void callback(i_wallet2_callback* callback) { m_callback = callback; }
1121
1122 bool is_trusted_daemon() const { return m_trusted_daemon; }
1123 void set_trusted_daemon(bool trusted) { m_trusted_daemon = trusted; }
1124
1125 /*!
1126 * \brief Checks if deterministic wallet
1127 */
1128 bool is_deterministic() const;
1129 bool get_seed(epee::wipeable_string& electrum_words, const epee::wipeable_string &passphrase = epee::wipeable_string()) const;
1130
1131 /*!
1132 * \brief Checks if light wallet. A light wallet sends view key to a server where the blockchain is scanned.
1133 */
1134 bool light_wallet() const { return m_light_wallet; }
1135 void set_light_wallet(bool light_wallet) { m_light_wallet = light_wallet; }
1136 uint64_t get_light_wallet_scanned_block_height() const { return m_light_wallet_scanned_block_height; }
1137 uint64_t get_light_wallet_blockchain_height() const { return m_light_wallet_blockchain_height; }
1138
1139 /*!
1140 * \brief Gets the seed language
1141 */
1142 const std::string &get_seed_language() const;
1143 /*!
1144 * \brief Sets the seed language
1145 */
1146 void set_seed_language(const std::string &language);
1147
1148 // Subaddress scheme
1149 cryptonote::account_public_address get_subaddress(const cryptonote::subaddress_index& index) const;
1150 cryptonote::account_public_address get_address() const { return get_subaddress({0,0}); }
1151 boost::optional<cryptonote::subaddress_index> get_subaddress_index(const cryptonote::account_public_address& address) const;
1152 crypto::public_key get_subaddress_spend_public_key(const cryptonote::subaddress_index& index) const;
1153 std::vector<crypto::public_key> get_subaddress_spend_public_keys(uint32_t account, uint32_t begin, uint32_t end) const;
1154 std::string get_subaddress_as_str(const cryptonote::subaddress_index& index) const;
1155 std::string get_address_as_str() const { return get_subaddress_as_str({0, 0}); }
1156 std::string get_integrated_address_as_str(const crypto::hash8& payment_id) const;
1157 bool get_subaddress_used(const cryptonote::subaddress_index& index);
1158 void add_subaddress_account(const std::string& label);
1159 size_t get_num_subaddress_accounts() const { return m_subaddress_labels.size(); }
1160 size_t get_num_subaddresses(uint32_t index_major) const { return index_major < m_subaddress_labels.size() ? m_subaddress_labels[index_major].size() : 0; }
1161 void add_subaddress(uint32_t index_major, const std::string& label); // throws when index is out of bound
1162 void expand_subaddresses(const cryptonote::subaddress_index& index);
1163 void create_one_off_subaddress(const cryptonote::subaddress_index& index);
1164 std::string get_subaddress_label(const cryptonote::subaddress_index& index) const;
1165 void set_subaddress_label(const cryptonote::subaddress_index &index, const std::string &label);
1166 void set_subaddress_lookahead(size_t major, size_t minor);
1167 std::pair<size_t, size_t> get_subaddress_lookahead() const { return {m_subaddress_lookahead_major, m_subaddress_lookahead_minor}; }
1168 /*!
1169 * \brief Tells if the wallet file is deprecated.
1170 */
1171 bool is_deprecated() const;
1172 void refresh(bool trusted_daemon);
1173 void refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched);
1174 void refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched, bool& received_money, bool check_pool = true, bool try_incremental = true, uint64_t max_blocks = std::numeric_limits<uint64_t>::max());
1175 bool refresh(bool trusted_daemon, uint64_t & blocks_fetched, bool& received_money, bool& ok);
1176
1177 void set_refresh_type(RefreshType refresh_type) { m_refresh_type = refresh_type; }
1178 RefreshType get_refresh_type() const { return m_refresh_type; }
1179
1180 cryptonote::network_type nettype() const { return m_nettype; }
1181 bool watch_only() const { return m_watch_only; }
1182 bool multisig(bool *ready = NULL, uint32_t *threshold = NULL, uint32_t *total = NULL) const;
1183 bool is_background_wallet() const { return m_is_background_wallet; }
1184 bool has_multisig_partial_key_images() const;
1185 bool has_unknown_key_images() const;
1186 bool get_multisig_seed(epee::wipeable_string& seed, const epee::wipeable_string &passphrase = std::string()) const;
1187 bool key_on_device() const { return get_device_type() != hw::device::device_type::SOFTWARE; }
1188 hw::device::device_type get_device_type() const { return m_key_device_type; }
1189 bool reconnect_device();
1190 bool device_connected();
1191
1192 // locked & unlocked balance of given or current subaddress account
1193 uint64_t balance(uint32_t subaddr_index_major, bool strict) const;
1194 uint64_t unlocked_balance(uint32_t subaddr_index_major, bool strict, uint64_t *blocks_to_unlock = NULL, uint64_t *time_to_unlock = NULL);
1195 uint64_t view_only_balance(uint32_t index_major, const std::vector<crypto::key_image>& selected_inputs = {});
1196 // locked & unlocked balance per subaddress of given or current subaddress account
1197 std::map<uint32_t, uint64_t> balance_per_subaddress(uint32_t subaddr_index_major, bool strict) const;
1198 std::map<uint32_t, std::pair<uint64_t, std::pair<uint64_t, uint64_t>>> unlocked_balance_per_subaddress(uint32_t subaddr_index_major, bool strict);
1199 // all locked & unlocked balances of all subaddress accounts
1200 uint64_t balance_all(bool strict) const;
1201 uint64_t unlocked_balance_all(bool strict, uint64_t *blocks_to_unlock = NULL, uint64_t *time_to_unlock = NULL);
1202 template<typename T>
1203 void transfer_selected(const std::vector<cryptonote::tx_destination_entry>& dsts, const std::vector<size_t>& selected_transfers, size_t fake_outputs_count,
1204 std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, std::unordered_set<crypto::public_key> &valid_public_keys_cache,
1205 uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, cryptonote::transaction& tx, pending_tx &ptx, const bool use_view_tags);
1206 void transfer_selected_rct(std::vector<cryptonote::tx_destination_entry> dsts, const std::vector<size_t>& selected_transfers, size_t fake_outputs_count,
1207 std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, std::unordered_set<crypto::public_key> &valid_public_keys_cache,
1208 uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx &ptx, const rct::RCTConfig &rct_config, const bool use_view_tags, uint64_t upper_transaction_weight_limit);
1209
1210 // Check if wallet cache contains txid
1211 bool have_tx(crypto::hash txid);
1212
1213 void commit_tx(pending_tx& ptx_vector);
1214 void commit_tx(std::vector<pending_tx>& ptx_vector);
1215 bool save_tx(const std::vector<pending_tx>& ptx_vector, const std::string &filename) const;
1216 std::string dump_tx_to_str(const std::vector<pending_tx> &ptx_vector) const;
1217 std::string save_multisig_tx(multisig_tx_set txs);
1218 bool save_multisig_tx(const multisig_tx_set &txs, const std::string &filename);
1219 std::string save_multisig_tx(const std::vector<pending_tx>& ptx_vector);
1220 bool save_multisig_tx(const std::vector<pending_tx>& ptx_vector, const std::string &filename);
1221 multisig_tx_set make_multisig_tx_set(const std::vector<pending_tx>& ptx_vector) const;
1222 // load unsigned tx from file and sign it. Takes confirmation callback as argument. Used by the cli wallet
1223 bool sign_tx(const std::string &unsigned_filename, const std::string &signed_filename, std::vector<wallet2::pending_tx> &ptx, std::function<bool(const unsigned_tx_set&)> accept_func = NULL, bool export_raw = false);
1224 // sign unsigned tx. Takes unsigned_tx_set as argument. Used by GUI
1225 bool sign_tx(unsigned_tx_set &exported_txs, const std::string &signed_filename, std::vector<wallet2::pending_tx> &ptx, bool export_raw = false);
1226 bool sign_tx(unsigned_tx_set &exported_txs, std::vector<wallet2::pending_tx> &ptx, signed_tx_set &signed_txs);
1227 std::string sign_tx_dump_to_str(unsigned_tx_set &exported_txs, std::vector<wallet2::pending_tx> &ptx, signed_tx_set &signed_txes);
1228 // load unsigned_tx_set from file.
1229 bool load_unsigned_tx(const std::string &unsigned_filename, unsigned_tx_set &exported_txs) const;
1230 bool parse_unsigned_tx_from_str(const std::string &unsigned_tx_st, unsigned_tx_set &exported_txs) const;
1231 bool load_tx(const std::string &signed_filename, std::vector<tools::wallet2::pending_tx> &ptx, std::function<bool(const signed_tx_set&)> accept_func = NULL);
1232 bool parse_tx_from_str(const std::string &signed_tx_st, std::vector<tools::wallet2::pending_tx> &ptx, std::function<bool(const signed_tx_set &)> accept_func);
1233 std::vector<wallet2::pending_tx> create_transactions_2(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices, const unique_index_container& subtract_fee_from_outputs = {}, const std::vector<crypto::key_image>& preferred_input_list = {}); // pass subaddr_indices by value on purpose
1234 std::vector<wallet2::pending_tx> create_transactions_all(uint64_t below, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices, const std::vector<crypto::key_image>& preferred_input_list = {});
1235 std::vector<wallet2::pending_tx> create_transactions_single(const crypto::key_image &ki, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, uint32_t priority, const std::vector<uint8_t>& extra);
1236 std::vector<wallet2::pending_tx> create_transactions_selected(const std::vector<crypto::key_image> &key_images, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, uint32_t priority, const std::vector<uint8_t>& extra);
1237 std::vector<wallet2::pending_tx> create_transactions_from(const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, std::vector<size_t> unused_transfers_indices, std::vector<size_t> unused_dust_indices, const size_t fake_outs_count, uint32_t priority, const std::vector<uint8_t>& extra);
1238 bool sanity_check(const std::vector<wallet2::pending_tx> &ptx_vector, const std::vector<cryptonote::tx_destination_entry>& dsts, const unique_index_container& subtract_fee_from_outputs = {}) const;
1239 void cold_tx_aux_import(const std::vector<pending_tx>& ptx, const std::vector<std::string>& tx_device_aux);
1240 void cold_sign_tx(const std::vector<pending_tx>& ptx_vector, signed_tx_set &exported_txs, std::vector<cryptonote::address_parse_info> &dsts_info, std::vector<std::string> & tx_device_aux);
1241 uint64_t cold_key_image_sync(uint64_t &spent, uint64_t &unspent);
1242 void device_show_address(uint32_t account_index, uint32_t address_index, const boost::optional<crypto::hash8> &payment_id);
1243 bool parse_multisig_tx_from_str(std::string multisig_tx_st, multisig_tx_set &exported_txs) const;
1244 bool load_multisig_tx(cryptonote::blobdata blob, multisig_tx_set &exported_txs, std::function<bool(const multisig_tx_set&)> accept_func = NULL);
1245 bool load_multisig_tx_from_file(const std::string &filename, multisig_tx_set &exported_txs, std::function<bool(const multisig_tx_set&)> accept_func = NULL);
1246 bool sign_multisig_tx_from_file(const std::string &filename, std::vector<crypto::hash> &txids, std::function<bool(const multisig_tx_set&)> accept_func);
1247 bool sign_multisig_tx(multisig_tx_set &exported_txs, std::vector<crypto::hash> &txids);
1248 bool sign_multisig_tx_to_file(multisig_tx_set &exported_txs, const std::string &filename, std::vector<crypto::hash> &txids);
1249 std::vector<pending_tx> create_unmixable_sweep_transactions();
1250 void discard_unmixable_outputs();
1251 bool check_connection(uint32_t *version = NULL, bool *ssl = NULL, uint32_t timeout = 200000);
1252 void get_transfers(wallet2::transfer_container& incoming_transfers) const;
1253 void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height = 0, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
1254 void get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments, uint64_t min_height, uint64_t max_height = (uint64_t)-1, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
1255 void get_payments_out(std::list<std::pair<crypto::hash,wallet2::confirmed_transfer_details>>& confirmed_payments,
1256 uint64_t min_height, uint64_t max_height = (uint64_t)-1, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
1257 void get_unconfirmed_payments_out(std::list<std::pair<crypto::hash,wallet2::unconfirmed_transfer_details>>& unconfirmed_payments, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
1258 void get_unconfirmed_payments(std::list<std::pair<crypto::hash,wallet2::pool_payment_details>>& unconfirmed_payments, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
1259
1260 bool is_change(const wallet2::transfer_details &td);
1261
1262 uint64_t get_blockchain_current_height() const { return m_light_wallet_blockchain_height ? m_light_wallet_blockchain_height : m_blockchain.size(); }
1263 void rescan_spent();
1264 void rescan_blockchain(bool hard, bool refresh = true, bool keep_key_images = false);
1265 bool is_transfer_unlocked(const transfer_details& td);
1266 bool is_transfer_unlocked(uint64_t unlock_time, uint64_t block_height);
1267
1268 uint64_t get_last_block_reward() const { return m_last_block_reward; }
1269 uint64_t get_device_last_key_image_sync() const { return m_device_last_key_image_sync; }
1270
1271 std::vector<cryptonote::public_node> get_public_nodes(bool white_only = true);
1272
1273 bool remove_failed_tx(const crypto::hash &txid);
1274
1275 template <class t_archive>
1276 inline void serialize(t_archive &a, const unsigned int ver)
1277 {
1278 uint64_t dummy_refresh_height = 0; // moved to keys file
1279 if(ver < 5)
1280 return;
1281 if (ver < 19)
1282 {
1283 std::vector<crypto::hash> blockchain;
1284 a & blockchain;
1285 m_blockchain.clear();
1286 for (const auto &b: blockchain)
1287 {
1288 m_blockchain.push_back(b);
1289 }
1290 }
1291 else
1292 {
1293 a & m_blockchain;
1294 }
1295 a & m_transfers;
1296 a & m_account_public_address;
1297 a & m_key_images.parent();
1298 if(ver < 6)
1299 return;
1300 a & m_unconfirmed_txs.parent();
1301 if(ver < 7)
1302 return;
1303 a & m_payments.parent();
1304 if(ver < 8)
1305 return;
1306 a & m_tx_keys.parent();
1307 if(ver < 9)
1308 return;
1309 a & m_confirmed_txs.parent();
1310 if(ver < 11)
1311 return;
1312 a & dummy_refresh_height;
1313 if(ver < 12)
1314 return;
1315 a & m_tx_notes.parent();
1316 if(ver < 13)
1317 return;
1318 if (ver < 17)
1319 {
1320 // we're loading an old version, where m_unconfirmed_payments was a std::map
1321 std::unordered_map<crypto::hash, payment_details> m;
1322 a & m;
1323 m_unconfirmed_payments.clear();
1324 for (std::unordered_map<crypto::hash, payment_details>::const_iterator i = m.begin(); i != m.end(); ++i)
1325 m_unconfirmed_payments.insert(std::make_pair(i->first, pool_payment_details{i->second, false}));
1326 }
1327 if(ver < 14)
1328 return;
1329 if(ver < 15)
1330 {
1331 // we're loading an older wallet without a pubkey map, rebuild it
1332 m_pub_keys.clear();
1333 for (size_t i = 0; i < m_transfers.size(); ++i)
1334 {
1335 const transfer_details &td = m_transfers[i];
1336 m_pub_keys.emplace(td.get_public_key(), i);
1337 }
1338 return;
1339 }
1340 a & m_pub_keys.parent();
1341 if(ver < 16)
1342 return;
1343 a & m_address_book;
1344 if(ver < 17)
1345 return;
1346 if (ver < 22)
1347 {
1348 // we're loading an old version, where m_unconfirmed_payments payload was payment_details
1349 std::unordered_multimap<crypto::hash, payment_details> m;
1350 a & m;
1351 m_unconfirmed_payments.clear();
1352 for (const auto &i: m)
1353 m_unconfirmed_payments.insert(std::make_pair(i.first, pool_payment_details{i.second, false}));
1354 }
1355 if(ver < 18)
1356 return;
1357 a & m_scanned_pool_txs[0];
1358 a & m_scanned_pool_txs[1];
1359 if (ver < 20)
1360 return;
1361 a & m_subaddresses.parent();
1362 std::unordered_map<cryptonote::subaddress_index, crypto::public_key> dummy_subaddresses_inv;
1363 a & dummy_subaddresses_inv;
1364 a & m_subaddress_labels;
1365 a & m_additional_tx_keys.parent();
1366 if(ver < 21)
1367 return;
1368 a & m_attributes.parent();
1369 if(ver < 22)
1370 return;
1371 a & m_unconfirmed_payments.parent();
1372 if(ver < 23)
1373 return;
1374 a & (std::pair<std::map<std::string, std::string>, std::vector<std::string>>&)m_account_tags;
1375 if(ver < 24)
1376 return;
1377 a & m_ring_history_saved;
1378 if(ver < 25)
1379 return;
1380 a & m_last_block_reward;
1381 if(ver < 26)
1382 return;
1383 a & m_tx_device.parent();
1384 if(ver < 27)
1385 return;
1386 a & m_device_last_key_image_sync;
1387 if(ver < 28)
1388 return;
1389 a & m_cold_key_images.parent();
1390 if(ver < 29)
1391 return;
1392 a & m_rpc_client_secret_key;
1393 if(ver < 30)
1394 {
1395 m_has_ever_refreshed_from_node = false;
1396 return;
1397 }
1398 a & m_has_ever_refreshed_from_node;
1399 if(ver < 31)
1400 {
1401 m_background_sync_data = background_sync_data_t{};
1402 return;
1403 }
1404 a & m_background_sync_data;
1405 }
1406
1407 BEGIN_SERIALIZE_OBJECT()
1408 MAGIC_FIELD("monero wallet cache")
1409 VERSION_FIELD(2)
1410 FIELD(m_blockchain)
1411 FIELD(m_transfers)
1412 FIELD(m_account_public_address)
1413 FIELD(m_key_images)
1414 FIELD(m_unconfirmed_txs)
1415 FIELD(m_payments)
1416 FIELD(m_tx_keys)
1417 FIELD(m_confirmed_txs)
1418 FIELD(m_tx_notes)
1419 FIELD(m_unconfirmed_payments)
1420 FIELD(m_pub_keys)
1421 FIELD(m_address_book)
1422 FIELD(m_scanned_pool_txs[0])
1423 FIELD(m_scanned_pool_txs[1])
1424 FIELD(m_subaddresses)
1425 FIELD(m_subaddress_labels)
1426 FIELD(m_additional_tx_keys)
1427 FIELD(m_attributes)
1428 FIELD(m_account_tags)
1429 FIELD(m_ring_history_saved)
1430 FIELD(m_last_block_reward)
1431 FIELD(m_tx_device)
1432 FIELD(m_device_last_key_image_sync)
1433 FIELD(m_cold_key_images)
1434 FIELD(m_rpc_client_secret_key)
1435 if (version < 1)
1436 {
1437 m_has_ever_refreshed_from_node = false;
1438 return true;
1439 }
1440 FIELD(m_has_ever_refreshed_from_node)
1441 if (version < 2)
1442 {
1443 m_background_sync_data = background_sync_data_t{};
1444 return true;
1445 }
1446 FIELD(m_background_sync_data)
1447 END_SERIALIZE()
1448
1449 /*!
1450 * \brief Check if wallet keys and bin files exist
1451 * \param file_path Wallet file path
1452 * \param keys_file_exists Whether keys file exists
1453 * \param wallet_file_exists Whether bin file exists
1454 */
1455 static void wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exists);
1456 /*!
1457 * \brief Check if wallet file path is valid format
1458 * \param file_path Wallet file path
1459 * \return Whether path is valid format
1460 */
1461 static bool wallet_valid_path_format(const std::string& file_path);
1462 static std::string make_background_wallet_file_name(const std::string &wallet_file);
1463 static std::string make_background_keys_file_name(const std::string &wallet_file);
1464 static bool parse_long_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);
1465 static bool parse_short_payment_id(const std::string& payment_id_str, crypto::hash8& payment_id);
1466 static bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);
1467
1468 bool always_confirm_transfers() const { return m_always_confirm_transfers; }
1469 void always_confirm_transfers(bool always) { m_always_confirm_transfers = always; }
1470 bool print_ring_members() const { return m_print_ring_members; }
1471 void print_ring_members(bool value) { m_print_ring_members = value; }
1472 bool store_tx_info() const { return m_store_tx_info; }
1473 void store_tx_info(bool store) { m_store_tx_info = store; }
1474 uint32_t default_mixin() const { return m_default_mixin; }
1475 void default_mixin(uint32_t m) { m_default_mixin = m; }
1476 uint32_t get_default_priority() const { return m_default_priority; }
1477 void set_default_priority(uint32_t p) { m_default_priority = p; }
1478 bool auto_refresh() const { return m_auto_refresh; }
1479 void auto_refresh(bool r) { m_auto_refresh = r; }
1480 AskPasswordType ask_password() const { return m_ask_password; }
1481 void ask_password(AskPasswordType ask) { m_ask_password = ask; }
1482 void set_min_output_count(uint32_t count) { m_min_output_count = count; }
1483 uint32_t get_min_output_count() const { return m_min_output_count; }
1484 void set_min_output_value(uint64_t value) { m_min_output_value = value; }
1485 uint64_t get_min_output_value() const { return m_min_output_value; }
1486 void merge_destinations(bool merge) { m_merge_destinations = merge; }
1487 bool merge_destinations() const { return m_merge_destinations; }
1488 bool confirm_backlog() const { return m_confirm_backlog; }
1489 void confirm_backlog(bool always) { m_confirm_backlog = always; }
1490 void set_confirm_backlog_threshold(uint32_t threshold) { m_confirm_backlog_threshold = threshold; };
1491 uint32_t get_confirm_backlog_threshold() const { return m_confirm_backlog_threshold; };
1492 bool confirm_export_overwrite() const { return m_confirm_export_overwrite; }
1493 void confirm_export_overwrite(bool always) { m_confirm_export_overwrite = always; }
1494 bool auto_low_priority() const { return m_auto_low_priority; }
1495 void auto_low_priority(bool value) { m_auto_low_priority = value; }
1496 bool segregate_pre_fork_outputs() const { return m_segregate_pre_fork_outputs; }
1497 void segregate_pre_fork_outputs(bool value) { m_segregate_pre_fork_outputs = value; }
1498 bool key_reuse_mitigation2() const { return m_key_reuse_mitigation2; }
1499 void key_reuse_mitigation2(bool value) { m_key_reuse_mitigation2 = value; }
1500 uint64_t segregation_height() const { return m_segregation_height; }
1501 void segregation_height(uint64_t height) { m_segregation_height = height; }
1502 bool ignore_fractional_outputs() const { return m_ignore_fractional_outputs; }
1503 void ignore_fractional_outputs(bool value) { m_ignore_fractional_outputs = value; }
1504 bool confirm_non_default_ring_size() const { return m_confirm_non_default_ring_size; }
1505 void confirm_non_default_ring_size(bool always) { m_confirm_non_default_ring_size = always; }
1506 uint64_t ignore_outputs_above() const { return m_ignore_outputs_above; }
1507 void ignore_outputs_above(uint64_t value) { m_ignore_outputs_above = value; }
1508 uint64_t ignore_outputs_below() const { return m_ignore_outputs_below; }
1509 void ignore_outputs_below(uint64_t value) { m_ignore_outputs_below = value; }
1510 bool track_uses() const { return m_track_uses; }
1511 void track_uses(bool value) { m_track_uses = value; }
1512 BackgroundSyncType background_sync_type() const { return m_background_sync_type; }
1513 void setup_background_sync(BackgroundSyncType background_sync_type, const epee::wipeable_string &wallet_password, const boost::optional<epee::wipeable_string> &background_cache_password);
1514 bool is_background_syncing() const { return m_background_syncing; }
1515 bool show_wallet_name_when_locked() const { return m_show_wallet_name_when_locked; }
1516 void show_wallet_name_when_locked(bool value) { m_show_wallet_name_when_locked = value; }
1517 BackgroundMiningSetupType setup_background_mining() const { return m_setup_background_mining; }
1518 void setup_background_mining(BackgroundMiningSetupType value) { m_setup_background_mining = value; }
1519 uint32_t inactivity_lock_timeout() const { return m_inactivity_lock_timeout; }
1520 void inactivity_lock_timeout(uint32_t seconds) { m_inactivity_lock_timeout = seconds; }
1521 const std::string & device_name() const { return m_device_name; }
1522 void device_name(const std::string & device_name) { m_device_name = device_name; }
1523 const std::string & device_derivation_path() const { return m_device_derivation_path; }
1524 void device_derivation_path(const std::string &device_derivation_path) { m_device_derivation_path = device_derivation_path; }
1525 const ExportFormat & export_format() const { return m_export_format; }
1526 inline void set_export_format(const ExportFormat& export_format) { m_export_format = export_format; }
1527 bool load_deprecated_formats() const { return m_load_deprecated_formats; }
1528 void load_deprecated_formats(bool load) { m_load_deprecated_formats = load; }
1529 bool persistent_rpc_client_id() const { return m_persistent_rpc_client_id; }
1530 void persistent_rpc_client_id(bool persistent) { m_persistent_rpc_client_id = persistent; }
1531 void auto_mine_for_rpc_payment_threshold(float threshold) { m_auto_mine_for_rpc_payment_threshold = threshold; }
1532 float auto_mine_for_rpc_payment_threshold() const { return m_auto_mine_for_rpc_payment_threshold; }
1533 crypto::secret_key get_rpc_client_secret_key() const { return m_rpc_client_secret_key; }
1534 void set_rpc_client_secret_key(const crypto::secret_key &key) { m_rpc_client_secret_key = key; m_node_rpc_proxy.set_client_secret_key(key); }
1535 uint64_t credits_target() const { return m_credits_target; }
1536 void credits_target(uint64_t threshold) { m_credits_target = threshold; }
1537 bool is_multisig_enabled() const { return m_enable_multisig; }
1538 void enable_multisig(bool enable) { m_enable_multisig = enable; }
1539
1540 bool get_tx_key_cached(const crypto::hash &txid, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys) const;
1541 void set_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, const boost::optional<cryptonote::account_public_address> &single_destination_subaddress = boost::none);
1542 bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys);
1543 void check_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations);
1544 void check_tx_key_helper(const crypto::hash &txid, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations);
1545 void check_tx_key_helper(const cryptonote::transaction &tx, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, const cryptonote::account_public_address &address, uint64_t &received) const;
1546 bool is_out_to_acc(const cryptonote::account_public_address &address, const crypto::public_key& out_key, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, const size_t output_index, const boost::optional<crypto::view_tag> &view_tag_opt, crypto::key_derivation &found_derivation) const;
1547 std::string get_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message);
1548 std::string get_tx_proof(const cryptonote::transaction &tx, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message) const;
1549 bool check_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message, const std::string &sig_str, uint64_t &received, bool &in_pool, uint64_t &confirmations);
1550 bool check_tx_proof(const cryptonote::transaction &tx, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message, const std::string &sig_str, uint64_t &received) const;
1551
1552 std::string get_spend_proof(const crypto::hash &txid, const std::string &message);
1553 bool check_spend_proof(const crypto::hash &txid, const std::string &message, const std::string &sig_str);
1554
1555 void scan_tx(const std::unordered_set<crypto::hash> &txids);
1556
1557 /*!
1558 * \brief Generates a proof that proves the reserve of unspent funds
1559 * \param account_minreserve When specified, collect outputs only belonging to the given account and prove the smallest reserve above the given amount
1560 * When unspecified, proves for all unspent outputs across all accounts
1561 * \param message Arbitrary challenge message to be signed together
1562 * \return Signature string
1563 */
1564 std::string get_reserve_proof(const boost::optional<std::pair<uint32_t, uint64_t>> &account_minreserve, const std::string &message);
1565 /*!
1566 * \brief Verifies a proof of reserve
1567 * \param address The signer's address
1568 * \param message Challenge message used for signing
1569 * \param sig_str Signature string
1570 * \param total [OUT] the sum of funds included in the signature
1571 * \param spent [OUT] the sum of spent funds included in the signature
1572 * \return true if the signature verifies correctly
1573 */
1574 bool check_reserve_proof(const cryptonote::account_public_address &address, const std::string &message, const std::string &sig_str, uint64_t &total, uint64_t &spent);
1575
1576 /*!
1577 * \brief GUI Address book get/store
1578 */
1579 std::vector<address_book_row> get_address_book() const { return m_address_book; }
1580 bool add_address_book_row(const cryptonote::account_public_address &address, const crypto::hash8 *payment_id, const std::string &description, bool is_subaddress);
1581 bool set_address_book_row(size_t row_id, const cryptonote::account_public_address &address, const crypto::hash8 *payment_id, const std::string &description, bool is_subaddress);
1582 bool delete_address_book_row(std::size_t row_id);
1583
1584 uint64_t get_num_rct_outputs();
1585 size_t get_num_transfer_details() const { return m_transfers.size(); }
1586 const transfer_details &get_transfer_details(size_t idx) const;
1587 size_t get_transfer_details(const crypto::public_key &pk) const;
1588
1589 uint8_t get_current_hard_fork();
1590 void get_hard_fork_info(uint8_t version, uint64_t &earliest_height);
1591 bool use_fork_rules(uint8_t version, int64_t early_blocks = 0);
1592 int get_fee_algorithm();
1593
1594 std::string get_wallet_file() const;
1595 std::string get_keys_file() const;
1596 std::string get_daemon_address() const;
1597 const boost::optional<epee::net_utils::http::login>& get_daemon_login() const { return m_daemon_login; }
1598 uint64_t get_daemon_blockchain_height(std::string& err);
1599 uint64_t get_daemon_blockchain_target_height(std::string& err);
1600 uint64_t get_daemon_adjusted_time();
1601
1602 /*!
1603 * \brief Calculates the approximate blockchain height from current date/time.
1604 */
1605 uint64_t get_approximate_blockchain_height() const;
1606 uint64_t estimate_blockchain_height();
1607 std::vector<size_t> select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool allow_rct);
1608 std::vector<size_t> select_available_outputs(const std::function<bool(const transfer_details &td)> &f);
1609 std::vector<size_t> select_available_unmixable_outputs();
1610 std::vector<size_t> select_available_mixable_outputs();
1611
1612 size_t pop_best_value_from(const transfer_container &transfers, std::vector<size_t> &unused_dust_indices, const std::vector<size_t>& selected_transfers, bool smallest = false) const;
1613 size_t pop_best_value(std::vector<size_t> &unused_dust_indices, const std::vector<size_t>& selected_transfers, bool smallest = false) const;
1614
1615 void set_tx_note(const crypto::hash &txid, const std::string &note);
1616 std::string get_tx_note(const crypto::hash &txid) const;
1617
1618 void set_tx_device_aux(const crypto::hash &txid, const std::string &aux);
1619 std::string get_tx_device_aux(const crypto::hash &txid) const;
1620
1621 void set_description(const std::string &description);
1622 std::string get_description() const;
1623
1624 /*!
1625 * \brief Get the list of registered account tags.
1626 * \return first.Key=(tag's name), first.Value=(tag's label), second[i]=(i-th account's tag)
1627 */
1628 const std::pair<serializable_map<std::string, std::string>, std::vector<std::string>>& get_account_tags();
1629 /*!
1630 * \brief Set a tag to the given accounts.
1631 * \param account_indices Indices of accounts.
1632 * \param tag Tag's name. If empty, the accounts become untagged.
1633 */
1634 void set_account_tag(const std::set<uint32_t> &account_indices, const std::string& tag);
1635 /*!
1636 * \brief Set the label of the given tag.
1637 * \param tag Tag's name (which must be non-empty).
1638 * \param description Tag's description.
1639 */
1640 void set_account_tag_description(const std::string& tag, const std::string& description);
1641
1642 enum message_signature_type_t { sign_with_spend_key, sign_with_view_key };
1643 std::string sign(const std::string &data, message_signature_type_t signature_type, cryptonote::subaddress_index index = {0, 0}) const;
1644 struct message_signature_result_t { bool valid; unsigned version; bool old; message_signature_type_t type; };
1645 message_signature_result_t verify(const std::string &data, const cryptonote::account_public_address &address, const std::string &signature) const;
1646
1647 /*!
1648 * \brief sign_multisig_participant signs given message with the multisig public signer key
1649 * \param data message to sign
1650 * \throws if wallet is not multisig
1651 * \return signature
1652 */
1653 std::string sign_multisig_participant(const std::string& data) const;
1654 /*!
1655 * \brief verify_with_public_key verifies message was signed with given public key
1656 * \param data message
1657 * \param public_key public key to check signature
1658 * \param signature signature of the message
1659 * \return true if the signature is correct
1660 */
1661 bool verify_with_public_key(const std::string &data, const crypto::public_key &public_key, const std::string &signature) const;
1662
1663 // Import/Export wallet data
1664 std::tuple<uint64_t, uint64_t, std::vector<tools::wallet2::exported_transfer_details>> export_outputs(bool all = false, uint32_t start = 0, uint32_t count = 0xffffffff) const;
1665 std::string export_outputs_to_str(bool all = false, uint32_t start = 0, uint32_t count = 0xffffffff) const;
1666 size_t import_outputs(const std::tuple<uint64_t, uint64_t, std::vector<tools::wallet2::exported_transfer_details>> &outputs);
1667 size_t import_outputs(const std::tuple<uint64_t, uint64_t, std::vector<tools::wallet2::transfer_details>> &outputs);
1668 size_t import_outputs_from_str(const std::string &outputs_st);
1669 payment_container export_payments() const;
1670 void import_payments(const payment_container &payments);
1671 void import_payments_out(const std::list<std::pair<crypto::hash,wallet2::confirmed_transfer_details>> &confirmed_payments);
1672 std::tuple<size_t, crypto::hash, std::vector<crypto::hash>> export_blockchain() const;
1673 void import_blockchain(const std::tuple<size_t, crypto::hash, std::vector<crypto::hash>> &bc);
1674 std::string export_key_images_to_str(bool all = false) const;
1675 std::string export_key_images_for_outputs_from_str(const std::string &outputs_st);
1676 std::pair<uint64_t, std::vector<std::pair<crypto::key_image, crypto::signature>>> export_key_images(bool all = false) const;
1677 uint64_t import_key_images(const std::vector<std::pair<crypto::key_image, crypto::signature>> &signed_key_images, size_t offset, uint64_t &spent, uint64_t &unspent, bool check_spent = true);
1678 uint64_t import_key_images_from_str(std::string &data, uint64_t &spent, uint64_t &unspent);
1679 uint64_t import_key_images(const std::string &filename, uint64_t &spent, uint64_t &unspent);
1680 bool import_key_images(std::vector<crypto::key_image> key_images, size_t offset=0, boost::optional<std::unordered_set<size_t>> selected_transfers=boost::none);
1681 bool import_key_images(signed_tx_set & signed_tx, size_t offset=0, bool only_selected_transfers=false);
1682 crypto::public_key get_tx_pub_key_from_received_outs(const tools::wallet2::transfer_details &td) const;
1683
1684 void update_pool_state(std::vector<std::tuple<cryptonote::transaction, crypto::hash, bool>> &process_txs, bool refreshed = false, bool try_incremental = false);
1685 void process_pool_state(const std::vector<std::tuple<cryptonote::transaction, crypto::hash, bool>> &txs);
1686 void remove_obsolete_pool_txs(const std::vector<crypto::hash> &tx_hashes, bool remove_if_found);
1687
1688 std::string encrypt(const char *plaintext, size_t len, const crypto::secret_key &skey, bool authenticated = true) const;
1689 std::string encrypt(const epee::span<char> &span, const crypto::secret_key &skey, bool authenticated = true) const;
1690 std::string encrypt(const std::string &plaintext, const crypto::secret_key &skey, bool authenticated = true) const;
1691 std::string encrypt(const epee::wipeable_string &plaintext, const crypto::secret_key &skey, bool authenticated = true) const;
1692 std::string encrypt_with_view_secret_key(const std::string &plaintext, bool authenticated = true) const;
1693 template<typename T=std::string> T decrypt(const std::string &ciphertext, const crypto::secret_key &skey, bool authenticated = true) const;
1694 std::string decrypt_with_view_secret_key(const std::string &ciphertext, bool authenticated = true) const;
1695
1696 std::string make_uri(const std::string &address, const std::string &payment_id, uint64_t amount, const std::string &tx_description, const std::string &recipient_name, std::string &error) const;
1697 bool parse_uri(const std::string &uri, std::string &address, std::string &payment_id, uint64_t &amount, std::string &tx_description, std::string &recipient_name, std::vector<std::string> &unknown_parameters, std::string &error);
1698
1699 uint64_t get_blockchain_height_by_date(uint16_t year, uint8_t month, uint8_t day); // 1<=month<=12, 1<=day<=31
1700
1701 bool is_synced();
1702
1703 std::vector<cryptonote::tx_backlog_entry> get_txpool_backlog();
1704 uint64_t get_block_weight_limit();
1705 std::vector<uint64_t> get_base_fees();
1706
1707 std::vector<std::pair<uint64_t, uint64_t>> estimate_backlog(const std::vector<std::pair<double, double>> &fee_levels);
1708 std::vector<std::pair<uint64_t, uint64_t>> estimate_backlog(uint64_t min_tx_weight, uint64_t max_tx_weight, const std::vector<uint64_t> &fees);
1709
1710 static uint64_t estimate_fee(bool use_per_byte_fee, bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof, bool clsag, bool bulletproof_plus, bool use_view_tags, uint64_t base_fee, uint64_t fee_quantization_mask);
1711 uint64_t get_fee_multiplier(uint32_t priority, int fee_algorithm = -1);
1712 uint64_t get_base_fee(uint32_t priority);
1713 uint64_t get_base_fee();
1714 uint64_t get_fee_quantization_mask();
1715 uint64_t get_min_ring_size();
1716 uint64_t get_max_ring_size();
1717 uint64_t adjust_mixin(uint64_t mixin);
1718
1719 uint32_t adjust_priority(uint32_t priority, std::vector<std::pair<uint64_t, uint64_t>> &blocks);
1720
1721 bool is_unattended() const { return m_unattended; }
1722
1723 std::pair<size_t, uint64_t> estimate_tx_size_and_weight(bool use_rct, int n_inputs, int ring_size, int n_outputs, size_t extra_size);
1724
1725 bool get_rpc_payment_info(bool mining, bool &payment_required, uint64_t &credits, uint64_t &diff, uint64_t &credits_per_hash_found, cryptonote::blobdata &hashing_blob, uint64_t &height, uint64_t &seed_height, crypto::hash &seed_hash, crypto::hash &next_seed_hash, uint32_t &cookie);
1726 bool daemon_requires_payment();
1727 bool make_rpc_payment(uint32_t nonce, uint32_t cookie, uint64_t &credits, uint64_t &balance);
1728
1729 template<typename T> void handle_payment_changes(const T &res, std::true_type) {
1730 if (res.status == CORE_RPC_STATUS_OK || res.status == CORE_RPC_STATUS_PAYMENT_REQUIRED)
1731 m_rpc_payment_state.credits = res.credits;
1732 if (res.top_hash != m_rpc_payment_state.top_hash)
1733 {
1734 m_rpc_payment_state.top_hash = res.top_hash;
1735 m_rpc_payment_state.stale = true;
1736 }
1737 }
1738 template<typename T> void handle_payment_changes(const T &res, std::false_type) {}
1739
1740 // Light wallet specific functions
1741 // fetch unspent outs from lw node and store in m_transfers
1742 void light_wallet_get_unspent_outs();
1743 // fetch txs and store in m_payments
1744 void light_wallet_get_address_txs();
1745 // get_address_info
1746 bool light_wallet_get_address_info(tools::COMMAND_RPC_GET_ADDRESS_INFO::response &response);
1747 // Login. new_address is true if address hasn't been used on lw node before.
1748 bool light_wallet_login(bool &new_address);
1749 // Send an import request to lw node. returns info about import fee, address and payment_id
1750 bool light_wallet_import_wallet_request(tools::COMMAND_RPC_IMPORT_WALLET_REQUEST::response &response);
1751 // get random outputs from light wallet server
1752 void light_wallet_get_outs(std::vector<std::vector<get_outs_entry>> &outs, const std::vector<size_t> &selected_transfers, size_t fake_outputs_count);
1753 // Parse rct string
1754 bool light_wallet_parse_rct_str(const std::string& rct_string, const crypto::public_key& tx_pub_key, uint64_t internal_output_index, rct::key& decrypted_mask, rct::key& rct_commit, bool decrypt) const;
1755 // check if key image is ours
1756 bool light_wallet_key_image_is_ours(const crypto::key_image& key_image, const crypto::public_key& tx_public_key, uint64_t out_index);
1757
1758 /*
1759 * "attributes" are a mechanism to store an arbitrary number of string values
1760 * on the level of the wallet as a whole, identified by keys. Their introduction,
1761 * technically the unordered map m_attributes stored as part of a wallet file,
1762 * led to a new wallet file version, but now new singular pieces of info may be added
1763 * without the need for a new version.
1764 *
1765 * The first and so far only value stored as such an attribute is the description.
1766 * It's stored under the standard key ATTRIBUTE_DESCRIPTION (see method set_description).
1767 *
1768 * The mechanism is open to all clients and allows them to use it for storing basically any
1769 * single string values in a wallet. To avoid the problem that different clients possibly
1770 * overwrite or misunderstand each other's attributes, a two-part key scheme is
1771 * proposed: <client name>.<value name>
1772 */
1773 const char* const ATTRIBUTE_DESCRIPTION = "wallet2.description";
1774 void set_attribute(const std::string &key, const std::string &value);
1775 bool get_attribute(const std::string &key, std::string &value) const;
1776
1777 crypto::public_key get_multisig_signer_public_key() const;
1778 crypto::public_key get_multisig_signing_public_key(size_t idx) const;
1779 crypto::public_key get_multisig_signing_public_key(const crypto::secret_key &skey) const;
1780
1781 template<class t_request, class t_response>
1782 inline bool invoke_http_json(const boost::string_ref uri, const t_request& req, t_response& res, std::chrono::milliseconds timeout = std::chrono::seconds(15), const boost::string_ref http_method = "POST")
1783 {
1784 if (m_offline) return false;
1785 boost::lock_guard<boost::recursive_mutex> lock(m_daemon_rpc_mutex);
1786 return epee::net_utils::invoke_http_json(uri, req, res, *m_http_client, timeout, http_method);
1787 }
1788 template<class t_request, class t_response>
1789 inline bool invoke_http_bin(const boost::string_ref uri, const t_request& req, t_response& res, std::chrono::milliseconds timeout = std::chrono::seconds(15), const boost::string_ref http_method = "POST")
1790 {
1791 if (m_offline) return false;
1792 boost::lock_guard<boost::recursive_mutex> lock(m_daemon_rpc_mutex);
1793 return epee::net_utils::invoke_http_bin(uri, req, res, *m_http_client, timeout, http_method);
1794 }
1795 template<class t_request, class t_response>
1796 inline bool invoke_http_json_rpc(const boost::string_ref uri, const std::string& method_name, const t_request& req, t_response& res, std::chrono::milliseconds timeout = std::chrono::seconds(15), const boost::string_ref http_method = "POST", const std::string& req_id = "0")
1797 {
1798 if (m_offline) return false;
1799 boost::lock_guard<boost::recursive_mutex> lock(m_daemon_rpc_mutex);
1800 return epee::net_utils::invoke_http_json_rpc(uri, method_name, req, res, *m_http_client, timeout, http_method, req_id);
1801 }
1802
1803 bool set_ring_database(const std::string &filename);
1804 const std::string get_ring_database() const { return m_ring_database; }
1805 bool get_ring(const crypto::key_image &key_image, std::vector<uint64_t> &outs);
1806 bool get_rings(const crypto::hash &txid, std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> &outs);
1807 bool get_rings(const crypto::chacha_key &key, const std::vector<crypto::key_image> &key_images, std::vector<std::vector<uint64_t>> &outs);
1808 bool set_ring(const crypto::key_image &key_image, const std::vector<uint64_t> &outs, bool relative);
1809 bool set_rings(const std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> &rings, bool relative);
1810 bool unset_ring(const std::vector<crypto::key_image> &key_images);
1811 bool unset_ring(const crypto::hash &txid);
1812 bool find_and_save_rings(bool force = true);
1813
1814 bool blackball_output(const std::pair<uint64_t, uint64_t> &output);
1815 bool set_blackballed_outputs(const std::vector<std::pair<uint64_t, uint64_t>> &outputs, bool add = false);
1816 bool unblackball_output(const std::pair<uint64_t, uint64_t> &output);
1817 bool is_output_blackballed(const std::pair<uint64_t, uint64_t> &output) const;
1818
1819 void freeze(size_t idx);
1820 void thaw(size_t idx);
1821 bool frozen(size_t idx) const;
1822 void freeze(const crypto::public_key &pk);
1823 void freeze(const crypto::key_image &ki);
1824 void thaw(const crypto::public_key &pk);
1825 void thaw(const crypto::key_image &ki);
1826 bool frozen(const crypto::key_image &ki) const;
1827 bool frozen(const transfer_details &td) const;
1828 bool frozen(const multisig_tx_set& txs) const; // does partially signed txset contain frozen enotes?
1829
1830 bool save_to_file(const std::string& path_to_file, const std::string& binary, bool is_printable = false) const;
1831 static bool load_from_file(const std::string& path_to_file, std::string& target_str, size_t max_size = 1000000000);
1832
1833 uint64_t get_bytes_sent() const;
1834 uint64_t get_bytes_received() const;
1835
1836 void start_background_sync();
1837 void stop_background_sync(const epee::wipeable_string &wallet_password, const crypto::secret_key &spend_secret_key = crypto::null_skey);
1838
1839 std::string printBlockchain();
1840 std::string printTransfers();
1841 std::string printKeyImages();
1842 std::string printUnconfirmedTransferDetails();
1843 std::string printPayments();
1844 std::string printUnconfirmedPayments();
1845 std::string printConfirmedTransferDetails();
1846 std::string printPubKeys();
1847 std::string printTxNotes();
1848 std::string printSubaddresses();
1849 std::string printSubaddressLabels();
1850 std::string printAdditionalTxKeys();
1851 std::string printAttributes();
1852 std::string printAccountTags();
1853 std::string printTxKeys();
1854 std::string printAddressBook();
1855 std::string printScannedPoolTxs();
1856 std::string printTxPrefix(const cryptonote::transaction_prefix &tx);
1857 std::string printPaymentDetails(const payment_details &pd);
1858 std::string printTxDestinationEntry(const cryptonote::tx_destination_entry &tx);
1859
1860 // MMS -------------------------------------------------------------------------------------------------
1861 mms::message_store& get_message_store() { return m_message_store; };
1862 const mms::message_store& get_message_store() const { return m_message_store; };
1863 mms::multisig_wallet_state get_multisig_wallet_state() const;
1864
1865 bool lock_keys_file();
1866 bool unlock_keys_file();
1867 bool is_keys_file_locked() const;
1868
1869 void change_password(const std::string &filename, const epee::wipeable_string &original_password, const epee::wipeable_string &new_password);
1870
1871 void set_tx_notify(const std::shared_ptr<tools::Notify> &notify) { m_tx_notify = notify; }
1872
1873 bool is_tx_spendtime_unlocked(uint64_t unlock_time, uint64_t block_height);
1874 void hash_m_transfer(const transfer_details & transfer, crypto::hash &hash) const;
1875 uint64_t hash_m_transfers(boost::optional<uint64_t> transfer_height, crypto::hash &hash) const;
1876 void finish_rescan_bc_keep_key_images(uint64_t transfer_height, const crypto::hash &hash);
1877 void enable_dns(bool enable) { m_use_dns = enable; }
1878 void set_offline(bool offline = true);
1879 bool is_offline() const { return m_offline; }
1880
1881 uint64_t credits() const { return m_rpc_payment_state.credits; }
1882 void credit_report(uint64_t &expected_spent, uint64_t &discrepancy) const { expected_spent = m_rpc_payment_state.expected_spent; discrepancy = m_rpc_payment_state.discrepancy; }
1883
1884 static std::string get_default_daemon_address() { CRITICAL_REGION_LOCAL(default_daemon_address_lock); return default_daemon_address; }
1885
1886 boost::shared_mutex m_transfers_mutex;
1887
1888 bool cache_rct_distribution(uint64_t from_height);
1889 void check_rct_distribution();
1890
1891 private:
1892 /*!
1893 * \brief Stores wallet information to wallet file.
1894 * \param keys_file_name Name of wallet file
1895 * \param password Password of wallet file
1896 * \param watch_only true to save only view key, false to save both spend and view keys
1897 * \return Whether it was successful.
1898 */
1899 bool store_keys(const std::string& keys_file_name, const epee::wipeable_string& password, bool watch_only = false);
1900 bool store_keys(const std::string& keys_file_name, const crypto::chacha_key& key, bool watch_only = false, bool background_keys_file = false);
1901 boost::optional<wallet2::keys_file_data> get_keys_file_data(const crypto::chacha_key& key, bool watch_only = false, bool background_keys_file = false);
1902 bool store_keys_file_data(const std::string& keys_file_name, wallet2::keys_file_data &keys_file_data, bool background_keys_file = false);
1903 /*!
1904 * \brief Load wallet keys information from wallet file.
1905 * \param keys_file_name Name of wallet file
1906 * \param password Password of wallet file
1907 */
1908 bool load_keys(const std::string& keys_file_name, const epee::wipeable_string& password);
1909 /*!
1910 * \brief Load wallet keys information from a string buffer.
1911 * \param keys_buf Keys buffer to load
1912 * \param password Password of keys buffer
1913 */
1914 bool load_keys_buf(const std::string& keys_buf, const epee::wipeable_string& password);
1915 bool load_keys_buf(const std::string& keys_buf, const epee::wipeable_string& password, boost::optional<crypto::chacha_key>& keys_to_encrypt);
1916 void load_wallet_cache(const bool use_fs, const std::string& cache_buf = "");
1917 void process_new_transaction(const crypto::hash &txid, const cryptonote::transaction& tx, const std::vector<uint64_t> &o_indices, uint64_t height, uint8_t block_version, uint64_t ts, bool miner_tx, bool pool, bool double_spend_seen, const tx_cache_data &tx_cache_data, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL, bool ignore_callbacks = false);
1918 bool should_skip_block(const cryptonote::block &b, uint64_t height) const;
1919 void process_new_blockchain_entry(const cryptonote::block& b, const cryptonote::block_complete_entry& bche, const parsed_block &parsed_block, const crypto::hash& bl_id, uint64_t height, const std::vector<tx_cache_data> &tx_cache_data, size_t tx_cache_data_offset, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL);
1920 detached_blockchain_data detach_blockchain(uint64_t height, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL);
1921 void handle_reorg(uint64_t height, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL);
1922 void get_short_chain_history(std::list<crypto::hash>& ids, uint64_t granularity = 1) const;
1923 bool clear();
1924 void clear_soft(bool keep_key_images=false);
1925 /*
1926 * clear_user_data clears data created by the user, which is mostly data
1927 * that a view key cannot identify on chain. This function was initially
1928 * added to ensure that a "background" wallet (a wallet that syncs with just
1929 * a view key hot in memory) does not have any sensitive data loaded that it
1930 * does not need in order to sync. Future devs should take care to ensure
1931 * that this function deletes data that is not useful for background syncing
1932 */
1933 void clear_user_data();
1934 void pull_blocks(bool first, bool try_incremental, uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::vector<cryptonote::block_complete_entry> &blocks, std::vector<cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices> &o_indices, uint64_t &current_height);
1935 void pull_hashes(uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::vector<crypto::hash> &hashes);
1936 void fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history, bool force = false);
1937 void pull_and_parse_next_blocks(bool first, bool try_incremental, uint64_t start_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history, const std::vector<cryptonote::block_complete_entry> &prev_blocks, const std::vector<parsed_block> &prev_parsed_blocks, std::vector<cryptonote::block_complete_entry> &blocks, std::vector<parsed_block> &parsed_blocks, bool &last, bool &error, std::exception_ptr &exception);
1938 void process_parsed_blocks(uint64_t start_height, const std::vector<cryptonote::block_complete_entry> &blocks, const std::vector<parsed_block> &parsed_blocks, uint64_t& blocks_added, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL);
1939 bool accept_pool_tx_for_processing(const crypto::hash &txid);
1940 void process_unconfirmed_transfer(bool incremental, const crypto::hash &txid, wallet2::unconfirmed_transfer_details &tx_details, bool seen_in_pool, std::chrono::system_clock::time_point now, bool refreshed);
1941 void process_pool_info_extent(const cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::response &res, std::vector<std::tuple<cryptonote::transaction, crypto::hash, bool>> &process_txs, bool refreshed);
1942 void update_pool_state_by_pool_query(std::vector<std::tuple<cryptonote::transaction, crypto::hash, bool>> &process_txs, bool refreshed = false);
1943 void update_pool_state_from_pool_data(bool incremental, const std::vector<crypto::hash> &removed_pool_txids, const std::vector<std::tuple<cryptonote::transaction, crypto::hash, bool>> &added_pool_txs, std::vector<std::tuple<cryptonote::transaction, crypto::hash, bool>> &process_txs, bool refreshed);
1944 uint64_t select_transfers(uint64_t needed_money, std::vector<size_t> unused_transfers_indices, std::vector<size_t>& selected_transfers) const;
1945 bool prepare_file_names(const std::string& file_path);
1946 void process_unconfirmed(const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t height);
1947 void process_outgoing(const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t height, uint64_t ts, uint64_t spent, uint64_t received, uint32_t subaddr_account, const std::set<uint32_t>& subaddr_indices);
1948 void add_unconfirmed_tx(const cryptonote::transaction& tx, uint64_t amount_in, const std::vector<cryptonote::tx_destination_entry> &dests, const crypto::hash &payment_id, uint64_t change_amount, uint32_t subaddr_account, const std::set<uint32_t>& subaddr_indices);
1949 void generate_genesis(cryptonote::block& b) const;
1950 void check_genesis(const crypto::hash& genesis_hash) const; //throws
1951 bool generate_chacha_key_from_secret_keys(crypto::chacha_key &key) const;
1952 void generate_chacha_key_from_password(const epee::wipeable_string &pass, crypto::chacha_key &key) const;
1953 crypto::hash get_payment_id(const pending_tx &ptx) const;
1954 void check_acc_out_precomp(const cryptonote::tx_out &o, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, size_t i, tx_scan_info_t &tx_scan_info) const;
1955 void check_acc_out_precomp(const cryptonote::tx_out &o, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, size_t i, const is_out_data *is_out_data, tx_scan_info_t &tx_scan_info) const;
1956 void check_acc_out_precomp_once(const cryptonote::tx_out &o, const crypto::key_derivation &derivation, const std::vector<crypto::key_derivation> &additional_derivations, size_t i, const is_out_data *is_out_data, tx_scan_info_t &tx_scan_info, bool &already_seen) const;
1957 void parse_block_round(const cryptonote::blobdata &blob, cryptonote::block &bl, crypto::hash &bl_id, bool &error) const;
1958 uint64_t get_upper_transaction_weight_limit();
1959 std::vector<uint64_t> get_unspent_amounts_vector(bool strict);
1960 uint64_t get_dynamic_base_fee_estimate();
1961 float get_output_relatedness(const transfer_details &td0, const transfer_details &td1) const;
1962 std::vector<size_t> pick_preferred_rct_inputs(uint64_t needed_money, uint32_t subaddr_account, const std::set<uint32_t> &subaddr_indices, const std::vector<crypto::key_image>& preferred_input_list);
1963 void set_spent(size_t idx, uint64_t height);
1964 void set_unspent(size_t idx);
1965 bool is_spent(const transfer_details &td, bool strict = true) const;
1966 bool is_spent(size_t idx, bool strict = true) const;
1967 void get_outs(std::vector<std::vector<get_outs_entry>> &outs, const std::vector<size_t> &selected_transfers, size_t fake_outputs_count, bool rct, std::unordered_set<crypto::public_key> &valid_public_keys_cache);
1968 void get_outs(std::vector<std::vector<get_outs_entry>> &outs, const std::vector<size_t> &selected_transfers, size_t fake_outputs_count, std::vector<uint64_t> &rct_offsets, std::unordered_set<crypto::public_key> &valid_public_keys_cache);
1969 bool tx_add_fake_output(std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, uint64_t global_index, const crypto::public_key& tx_public_key, const rct::key& mask, uint64_t real_index, bool unlocked, std::unordered_set<crypto::public_key> &valid_public_keys_cache) const;
1970 bool should_pick_a_second_output(bool use_rct, size_t n_transfers, const std::vector<size_t> &unused_transfers_indices, const std::vector<size_t> &unused_dust_indices) const;
1971 std::vector<size_t> get_only_rct(const std::vector<size_t> &unused_dust_indices, const std::vector<size_t> &unused_transfers_indices) const;
1972 void scan_output(const cryptonote::transaction &tx, bool miner_tx, const crypto::public_key &tx_pub_key, size_t i, tx_scan_info_t &tx_scan_info, int &num_vouts_received, std::unordered_map<cryptonote::subaddress_index, uint64_t> &tx_money_got_in_outs, std::vector<size_t> &outs, bool pool);
1973 void trim_hashchain();
1974 crypto::key_image get_multisig_composite_key_image(size_t n) const;
1975 rct::multisig_kLRki get_multisig_composite_kLRki(size_t n, const std::unordered_set<crypto::public_key> &ignore_set, std::unordered_set<rct::key> &used_L, std::unordered_set<rct::key> &new_used_L) const;
1976 rct::multisig_kLRki get_multisig_kLRki(size_t n, const rct::key &k) const;
1977 void get_multisig_k(size_t idx, const std::unordered_set<rct::key> &used_L, rct::key &nonce);
1978 void update_multisig_rescan_info(const std::vector<std::vector<rct::key>> &multisig_k, const std::vector<std::vector<tools::wallet2::multisig_info>> &info, size_t n);
1979 bool add_rings(const crypto::chacha_key &key, const cryptonote::transaction_prefix &tx);
1980 bool add_rings(const cryptonote::transaction_prefix &tx);
1981 bool remove_rings(const cryptonote::transaction_prefix &tx);
1982 bool get_ring(const crypto::chacha_key &key, const crypto::key_image &key_image, std::vector<uint64_t> &outs);
1983 crypto::chacha_key get_ringdb_key();
1984 void setup_keys(const epee::wipeable_string &password);
1985 const crypto::chacha_key get_cache_key();
1986 void verify_password_with_cached_key(const epee::wipeable_string &password);
1987 void verify_password_with_cached_key(const crypto::chacha_key &key);
1988 size_t get_transfer_details(const crypto::key_image &ki) const;
1989 tx_entry_data get_tx_entries(const std::unordered_set<crypto::hash> &txids);
1990 void sort_scan_tx_entries(std::vector<process_tx_entry_t> &unsorted_tx_entries);
1991 void process_scan_txs(const tx_entry_data &txs_to_scan, const tx_entry_data &txs_to_reprocess, const std::unordered_set<crypto::hash> &tx_hashes_to_reprocess, detached_blockchain_data &dbd);
1992 void write_background_sync_wallet(const epee::wipeable_string &wallet_password, const epee::wipeable_string &background_cache_password);
1993 void process_background_cache_on_open();
1994 void process_background_cache(const background_sync_data_t &background_sync_data, const hashchain &background_chain, uint64_t last_block_reward);
1995 void reset_background_sync_data(background_sync_data_t &background_sync_data);
1996 void store_background_cache(const crypto::chacha_key &custom_background_key, const bool do_reset_background_sync_data = true);
1997 void store_background_keys(const crypto::chacha_key &custom_background_key);
1998
1999 bool lock_background_keys_file(const std::string &background_keys_file);
2000 bool unlock_background_keys_file();
2001 bool is_background_keys_file_locked() const;
2002
2003 void register_devices();
2004 hw::device& lookup_device(const std::string & device_descriptor);
2005
2006 bool get_rct_distribution();
2007
2008 uint64_t get_segregation_fork_height() const;
2009
2010 void cache_tx_data(const cryptonote::transaction& tx, const crypto::hash &txid, tx_cache_data &tx_cache_data) const;
2011 std::shared_ptr<std::map<std::pair<uint64_t, uint64_t>, size_t>> create_output_tracker_cache() const;
2012
2013 void init_type(hw::device::device_type device_type);
2014 void setup_new_blockchain();
2015 void create_keys_file(const std::string &wallet_, bool watch_only, const epee::wipeable_string &password, bool create_address_file);
2016
2017 wallet_device_callback * get_device_callback();
2018 void on_device_button_request(uint64_t code);
2019 void on_device_button_pressed();
2020 void on_device_error(const std::string &message, unsigned int errorCode);
2021 boost::optional<epee::wipeable_string> on_device_pin_request();
2022 boost::optional<epee::wipeable_string> on_device_passphrase_request(bool & on_device);
2023 void on_device_progress(const hw::device_progress& event);
2024
2025 std::string get_rpc_status(const std::string &s) const;
2026 void throw_on_rpc_response_error(bool r, const epee::json_rpc::error &error, const std::string &status, const char *method) const;
2027
2028 std::string get_client_signature() const;
2029 void check_rpc_cost(const char *call, uint64_t post_call_credits, uint64_t pre_credits, double expected_cost);
2030
2031 bool should_expand(const cryptonote::subaddress_index &index) const;
2032 bool spends_one_of_ours(const cryptonote::transaction &tx) const;
2033
2034 cryptonote::account_base m_account;
2035 boost::optional<epee::net_utils::http::login> m_daemon_login;
2036 std::string m_daemon_address;
2037 std::string m_proxy;
2038 std::string m_wallet_file;
2039 std::string m_keys_file;
2040 std::string m_mms_file;
2041 const std::unique_ptr<epee::net_utils::http::abstract_http_client> m_http_client;
2042 hashchain m_blockchain;
2043 serializable_unordered_map<crypto::hash, unconfirmed_transfer_details> m_unconfirmed_txs;
2044 serializable_unordered_map<crypto::hash, confirmed_transfer_details> m_confirmed_txs;
2045 serializable_unordered_multimap<crypto::hash, pool_payment_details> m_unconfirmed_payments;
2046 serializable_unordered_map<crypto::hash, crypto::secret_key> m_tx_keys;
2047 cryptonote::checkpoints m_checkpoints;
2048 serializable_unordered_map<crypto::hash, std::vector<crypto::secret_key>> m_additional_tx_keys;
2049
2050 rct_offsets m_rct_offsets;
2051 transfer_container m_transfers;
2052 payment_container m_payments;
2053 serializable_unordered_map<crypto::key_image, size_t> m_key_images;
2054 serializable_unordered_map<crypto::public_key, size_t> m_pub_keys;
2055 cryptonote::account_public_address m_account_public_address;
2056 serializable_unordered_map<crypto::public_key, cryptonote::subaddress_index> m_subaddresses;
2057 std::vector<std::vector<std::string>> m_subaddress_labels;
2058 serializable_unordered_map<crypto::hash, std::string> m_tx_notes;
2059 serializable_unordered_map<std::string, std::string> m_attributes;
2060 std::vector<tools::wallet2::address_book_row> m_address_book;
2061 std::pair<serializable_map<std::string, std::string>, std::vector<std::string>> m_account_tags;
2062 uint64_t m_upper_transaction_weight_limit; //TODO: auto-calc this value or request from daemon, now use some fixed value
2063 const std::vector<std::vector<tools::wallet2::multisig_info>> *m_multisig_rescan_info;
2064 const std::vector<std::vector<rct::key>> *m_multisig_rescan_k;
2065 serializable_unordered_map<crypto::public_key, crypto::key_image> m_cold_key_images;
2066
2067 std::atomic<bool> m_run;
2068
2069 boost::recursive_mutex m_daemon_rpc_mutex;
2070
2071 bool m_trusted_daemon;
2072 i_wallet2_callback* m_callback;
2073 hw::device::device_type m_key_device_type;
2074 cryptonote::network_type m_nettype;
2075 uint64_t m_kdf_rounds;
2076 std::string seed_language; /*!< Language of the mnemonics (seed). */
2077 bool is_old_file_format; /*!< Whether the wallet file is of an old file format */
2078 bool m_watch_only; /*!< no spend key */
2079 bool m_multisig; /*!< if > 1 spend secret key will not match spend public key */
2080 uint32_t m_multisig_threshold;
2081 std::vector<crypto::public_key> m_multisig_signers;
2082 //in case of general M/N multisig wallet we should perform N - M + 1 key exchange rounds and remember how many rounds are passed.
2083 uint32_t m_multisig_rounds_passed;
2084 std::vector<crypto::public_key> m_multisig_derivations;
2085 bool m_always_confirm_transfers;
2086 bool m_print_ring_members;
2087 bool m_store_tx_info; /*!< request txkey to be returned in RPC, and store in the wallet cache file */
2088 uint32_t m_default_mixin;
2089 uint32_t m_default_priority;
2090 RefreshType m_refresh_type;
2091 bool m_auto_refresh;
2092 bool m_first_refresh_done;
2093 uint64_t m_refresh_from_block_height;
2094 // If m_refresh_from_block_height is explicitly set to zero we need this to differentiate it from the case that
2095 // m_refresh_from_block_height was defaulted to zero.*/
2096 bool m_explicit_refresh_from_block_height;
2097 uint64_t m_pool_info_query_time;
2098 std::vector<std::tuple<cryptonote::transaction, crypto::hash, bool>> m_process_pool_txs;
2099 uint64_t m_skip_to_height;
2100 // m_skip_to_height is useful when we don't want to modify the wallet's restore height.
2101 // m_refresh_from_block_height is also a wallet's restore height which should remain constant unless explicitly modified by the user.
2102 bool m_confirm_non_default_ring_size;
2103 AskPasswordType m_ask_password;
2104 uint64_t m_max_reorg_depth;
2105 uint32_t m_min_output_count;
2106 uint64_t m_min_output_value;
2107 bool m_merge_destinations;
2108 bool m_confirm_backlog;
2109 uint32_t m_confirm_backlog_threshold;
2110 bool m_confirm_export_overwrite;
2111 bool m_auto_low_priority;
2112 bool m_segregate_pre_fork_outputs;
2113 bool m_key_reuse_mitigation2;
2114 uint64_t m_segregation_height;
2115 bool m_ignore_fractional_outputs;
2116 uint64_t m_ignore_outputs_above;
2117 uint64_t m_ignore_outputs_below;
2118 bool m_track_uses;
2119 bool m_is_background_wallet;
2120 BackgroundSyncType m_background_sync_type;
2121 bool m_show_wallet_name_when_locked;
2122 uint32_t m_inactivity_lock_timeout;
2123 BackgroundMiningSetupType m_setup_background_mining;
2124 bool m_persistent_rpc_client_id;
2125 float m_auto_mine_for_rpc_payment_threshold;
2126 bool m_is_initialized;
2127 NodeRPCProxy m_node_rpc_proxy;
2128 std::unordered_set<crypto::hash> m_scanned_pool_txs[2];
2129 size_t m_subaddress_lookahead_major, m_subaddress_lookahead_minor;
2130 std::string m_device_name;
2131 std::string m_device_derivation_path;
2132 uint64_t m_device_last_key_image_sync;
2133 bool m_use_dns;
2134 bool m_offline;
2135 uint32_t m_rpc_version;
2136 crypto::secret_key m_rpc_client_secret_key;
2137 rpc_payment_state_t m_rpc_payment_state;
2138 uint64_t m_credits_target;
2139 bool m_enable_multisig;
2140
2141 // Aux transaction data from device
2142 serializable_unordered_map<crypto::hash, std::string> m_tx_device;
2143
2144 // Light wallet
2145 bool m_light_wallet; /* sends view key to daemon for scanning */
2146 uint64_t m_light_wallet_scanned_block_height;
2147 uint64_t m_light_wallet_blockchain_height;
2148 uint64_t m_light_wallet_per_kb_fee = FEE_PER_KB;
2149 bool m_light_wallet_connected;
2150 uint64_t m_light_wallet_balance;
2151 uint64_t m_light_wallet_unlocked_balance;
2152 // Light wallet info needed to populate m_payment requires 2 separate api calls (get_address_txs and get_unspent_outs)
2153 // We save the info from the first call in m_light_wallet_address_txs for easier lookup.
2154 std::unordered_map<crypto::hash, address_tx> m_light_wallet_address_txs;
2155 // store calculated key image for faster lookup
2156 serializable_unordered_map<crypto::public_key, serializable_map<uint64_t, crypto::key_image> > m_key_image_cache;
2157
2158 std::string m_ring_database;
2159 bool m_ring_history_saved;
2160 std::unique_ptr<ringdb> m_ringdb;
2161 boost::optional<crypto::chacha_key> m_ringdb_key;
2162
2163 uint64_t m_last_block_reward;
2164 std::unique_ptr<tools::file_locker> m_keys_file_locker;
2165 std::unique_ptr<tools::file_locker> m_background_keys_file_locker;
2166
2167 mms::message_store m_message_store;
2168 bool m_original_keys_available;
2169 cryptonote::account_public_address m_original_address;
2170 crypto::secret_key m_original_view_secret_key;
2171
2172 crypto::chacha_key m_cache_key;
2173 boost::optional<crypto::chacha_key> m_custom_background_key = boost::none;
2174 std::shared_ptr<wallet_keys_unlocker> m_encrypt_keys_after_refresh;
2175
2176 bool m_unattended;
2177 bool m_devices_registered;
2178
2179 std::shared_ptr<tools::Notify> m_tx_notify;
2180 std::unique_ptr<wallet_device_callback> m_device_callback;
2181
2182 ExportFormat m_export_format;
2183 bool m_load_deprecated_formats;
2184
2185 bool m_has_ever_refreshed_from_node;
2186
2187 static boost::mutex default_daemon_address_lock;
2188 static std::string default_daemon_address;
2189
2190 bool m_background_syncing;
2191 bool m_processing_background_cache;
2192 background_sync_data_t m_background_sync_data;
2193 };
2194 }
2195 BOOST_CLASS_VERSION(tools::wallet2, 31)
2196 BOOST_CLASS_VERSION(tools::wallet2::transfer_details, 12)
2197 BOOST_CLASS_VERSION(tools::wallet2::multisig_info, 1)
2198 BOOST_CLASS_VERSION(tools::wallet2::multisig_info::LR, 0)
2199 BOOST_CLASS_VERSION(tools::wallet2::multisig_tx_set, 1)
2200 BOOST_CLASS_VERSION(tools::wallet2::payment_details, 5)
2201 BOOST_CLASS_VERSION(tools::wallet2::pool_payment_details, 1)
2202 BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 8)
2203 BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 6)
2204 BOOST_CLASS_VERSION(tools::wallet2::address_book_row, 18)
2205 BOOST_CLASS_VERSION(tools::wallet2::reserve_proof_entry, 0)
2206 BOOST_CLASS_VERSION(tools::wallet2::unsigned_tx_set, 1)
2207 BOOST_CLASS_VERSION(tools::wallet2::signed_tx_set, 1)
2208 BOOST_CLASS_VERSION(tools::wallet2::tx_construction_data, 4)
2209 BOOST_CLASS_VERSION(tools::wallet2::pending_tx, 3)
2210 BOOST_CLASS_VERSION(tools::wallet2::multisig_sig, 1)
2211 BOOST_CLASS_VERSION(tools::wallet2::background_synced_tx_t, 0)
2212 BOOST_CLASS_VERSION(tools::wallet2::background_sync_data_t, 0)
2213
2214 namespace boost
2215 {
2216 namespace serialization
2217 {
2218 template<class Archive, class F, class S, class T>
2219 inline void serialize(
2220 Archive & ar,
2221 std::tuple<F, S, T> & t,
2222 const unsigned int /* file_version */
2223 ){
2224 ar & boost::serialization::make_nvp("f", std::get<0>(t));
2225 ar & boost::serialization::make_nvp("s", std::get<1>(t));
2226 ar & boost::serialization::make_nvp("t", std::get<2>(t));
2227 }
2228
2229 template <class Archive>
2230 inline typename std::enable_if<!Archive::is_loading::value, void>::type initialize_transfer_details(Archive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
2231 {
2232 }
2233 template <class Archive>
2234 inline typename std::enable_if<Archive::is_loading::value, void>::type initialize_transfer_details(Archive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
2235 {
2236 if (ver < 1)
2237 {
2238 x.m_mask = rct::identity();
2239 x.m_amount = x.m_tx.vout[x.m_internal_output_index].amount;
2240 }
2241 if (ver < 2)
2242 {
2243 x.m_spent_height = 0;
2244 }
2245 if (ver < 4)
2246 {
2247 x.m_rct = x.m_tx.vout[x.m_internal_output_index].amount == 0;
2248 }
2249 if (ver < 6)
2250 {
2251 x.m_key_image_known = true;
2252 }
2253 if (ver < 7)
2254 {
2255 x.m_pk_index = 0;
2256 }
2257 if (ver < 8)
2258 {
2259 x.m_subaddr_index = {};
2260 }
2261 if (ver < 9)
2262 {
2263 x.m_key_image_partial = false;
2264 x.m_multisig_k.clear();
2265 x.m_multisig_info.clear();
2266 }
2267 if (ver < 10)
2268 {
2269 x.m_key_image_request = false;
2270 }
2271 if (ver < 12)
2272 {
2273 x.m_frozen = false;
2274 }
2275 }
2276
2277 template <class Archive>
2278 inline void serialize(Archive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
2279 {
2280 a & x.m_block_height;
2281 a & x.m_global_output_index;
2282 a & x.m_internal_output_index;
2283 if (ver < 3)
2284 {
2285 cryptonote::transaction tx;
2286 a & tx;
2287 x.m_tx = (const cryptonote::transaction_prefix&)tx;
2288 x.m_txid = cryptonote::get_transaction_hash(tx);
2289 }
2290 else
2291 {
2292 a & x.m_tx;
2293 }
2294 a & x.m_spent;
2295 a & x.m_key_image;
2296 if (ver < 1)
2297 {
2298 // ensure mask and amount are set
2299 initialize_transfer_details(a, x, ver);
2300 return;
2301 }
2302 a & x.m_mask;
2303 a & x.m_amount;
2304 if (ver < 2)
2305 {
2306 initialize_transfer_details(a, x, ver);
2307 return;
2308 }
2309 a & x.m_spent_height;
2310 if (ver < 3)
2311 {
2312 initialize_transfer_details(a, x, ver);
2313 return;
2314 }
2315 a & x.m_txid;
2316 if (ver < 4)
2317 {
2318 initialize_transfer_details(a, x, ver);
2319 return;
2320 }
2321 a & x.m_rct;
2322 if (ver < 5)
2323 {
2324 initialize_transfer_details(a, x, ver);
2325 return;
2326 }
2327 if (ver < 6)
2328 {
2329 // v5 did not properly initialize
2330 uint8_t u;
2331 a & u;
2332 x.m_key_image_known = true;
2333 return;
2334 }
2335 a & x.m_key_image_known;
2336 if (ver < 7)
2337 {
2338 initialize_transfer_details(a, x, ver);
2339 return;
2340 }
2341 a & x.m_pk_index;
2342 if (ver < 8)
2343 {
2344 initialize_transfer_details(a, x, ver);
2345 return;
2346 }
2347 a & x.m_subaddr_index;
2348 if (ver < 9)
2349 {
2350 initialize_transfer_details(a, x, ver);
2351 return;
2352 }
2353 a & x.m_multisig_info;
2354 a & x.m_multisig_k;
2355 a & x.m_key_image_partial;
2356 if (ver < 10)
2357 {
2358 initialize_transfer_details(a, x, ver);
2359 return;
2360 }
2361 a & x.m_key_image_request;
2362 if (ver < 11)
2363 {
2364 initialize_transfer_details(a, x, ver);
2365 return;
2366 }
2367 a & x.m_uses;
2368 if (ver < 12)
2369 {
2370 initialize_transfer_details(a, x, ver);
2371 return;
2372 }
2373 a & x.m_frozen;
2374 }
2375
2376 template <class Archive>
2377 inline void serialize(Archive &a, tools::wallet2::multisig_info::LR &x, const boost::serialization::version_type ver)
2378 {
2379 a & x.m_L;
2380 a & x.m_R;
2381 }
2382
2383 template <class Archive>
2384 inline void serialize(Archive &a, tools::wallet2::multisig_info &x, const boost::serialization::version_type ver)
2385 {
2386 a & x.m_signer;
2387 a & x.m_LR;
2388 a & x.m_partial_key_images;
2389 }
2390
2391 template <class Archive>
2392 inline void serialize(Archive &a, tools::wallet2::multisig_tx_set &x, const boost::serialization::version_type ver)
2393 {
2394 a & x.m_ptx;
2395 a & x.m_signers;
2396 }
2397
2398 template <class Archive>
2399 inline void serialize(Archive &a, tools::wallet2::unconfirmed_transfer_details &x, const boost::serialization::version_type ver)
2400 {
2401 a & x.m_change;
2402 a & x.m_sent_time;
2403 if (ver < 5)
2404 {
2405 cryptonote::transaction tx;
2406 a & tx;
2407 x.m_tx = (const cryptonote::transaction_prefix&)tx;
2408 }
2409 else
2410 {
2411 a & x.m_tx;
2412 }
2413 if (ver < 1)
2414 return;
2415 a & x.m_dests;
2416 a & x.m_payment_id;
2417 if (ver < 2)
2418 return;
2419 a & x.m_state;
2420 if (ver < 3)
2421 return;
2422 a & x.m_timestamp;
2423 if (ver < 4)
2424 return;
2425 a & x.m_amount_in;
2426 a & x.m_amount_out;
2427 if (ver < 6)
2428 {
2429 // v<6 may not have change accumulated in m_amount_out, which is a pain,
2430 // as it's readily understood to be sum of outputs.
2431 // We convert it to include change from v6
2432 if (!typename Archive::is_saving() && x.m_change != (uint64_t)-1)
2433 x.m_amount_out += x.m_change;
2434 }
2435 if (ver < 7)
2436 {
2437 x.m_subaddr_account = 0;
2438 return;
2439 }
2440 a & x.m_subaddr_account;
2441 a & x.m_subaddr_indices;
2442 if (ver < 8)
2443 return;
2444 a & x.m_rings;
2445 }
2446
2447 template <class Archive>
2448 inline void serialize(Archive &a, tools::wallet2::confirmed_transfer_details &x, const boost::serialization::version_type ver)
2449 {
2450 a & x.m_amount_in;
2451 a & x.m_amount_out;
2452 a & x.m_change;
2453 a & x.m_block_height;
2454 if (ver < 1)
2455 return;
2456 a & x.m_dests;
2457 a & x.m_payment_id;
2458 if (ver < 2)
2459 return;
2460 a & x.m_timestamp;
2461 if (ver < 3)
2462 {
2463 // v<3 may not have change accumulated in m_amount_out, which is a pain,
2464 // as it's readily understood to be sum of outputs. Whether it got added
2465 // or not depends on whether it came from a unconfirmed_transfer_details
2466 // (not included) or not (included). We can't reliably tell here, so we
2467 // check whether either yields a "negative" fee, or use the other if so.
2468 // We convert it to include change from v3
2469 if (!typename Archive::is_saving() && x.m_change != (uint64_t)-1)
2470 {
2471 if (x.m_amount_in > (x.m_amount_out + x.m_change))
2472 x.m_amount_out += x.m_change;
2473 }
2474 }
2475 if (ver < 4)
2476 {
2477 if (!typename Archive::is_saving())
2478 x.m_unlock_time = 0;
2479 return;
2480 }
2481 a & x.m_unlock_time;
2482 if (ver < 5)
2483 {
2484 x.m_subaddr_account = 0;
2485 return;
2486 }
2487 a & x.m_subaddr_account;
2488 a & x.m_subaddr_indices;
2489 if (ver < 6)
2490 return;
2491 a & x.m_rings;
2492 }
2493
2494 template <class Archive>
2495 inline void serialize(Archive& a, tools::wallet2::payment_details& x, const boost::serialization::version_type ver)
2496 {
2497 a & x.m_tx_hash;
2498 a & x.m_amount;
2499 a & x.m_block_height;
2500 a & x.m_unlock_time;
2501 if (ver < 1)
2502 return;
2503 a & x.m_timestamp;
2504 if (ver < 2)
2505 {
2506 x.m_coinbase = false;
2507 x.m_subaddr_index = {};
2508 return;
2509 }
2510 a & x.m_subaddr_index;
2511 if (ver < 3)
2512 {
2513 x.m_coinbase = false;
2514 x.m_fee = 0;
2515 return;
2516 }
2517 a & x.m_fee;
2518 if (ver < 4)
2519 {
2520 x.m_coinbase = false;
2521 return;
2522 }
2523 a & x.m_coinbase;
2524 if (ver < 5)
2525 return;
2526 a & x.m_amounts;
2527 }
2528
2529 template <class Archive>
2530 inline void serialize(Archive& a, tools::wallet2::pool_payment_details& x, const boost::serialization::version_type ver)
2531 {
2532 a & x.m_pd;
2533 a & x.m_double_spend_seen;
2534 }
2535
2536 template <class Archive>
2537 inline void serialize(Archive& a, tools::wallet2::address_book_row& x, const boost::serialization::version_type ver)
2538 {
2539 a & x.m_address;
2540 if (ver < 18)
2541 {
2542 crypto::hash payment_id;
2543 a & payment_id;
2544 x.m_has_payment_id = !(payment_id == crypto::null_hash);
2545 if (x.m_has_payment_id)
2546 {
2547 bool is_long = false;
2548 for (int i = 8; i < 32; ++i)
2549 is_long |= payment_id.data[i];
2550 if (is_long)
2551 {
2552 MWARNING("Long payment ID ignored on address book load");
2553 x.m_payment_id = crypto::null_hash8;
2554 x.m_has_payment_id = false;
2555 }
2556 else
2557 memcpy(x.m_payment_id.data, payment_id.data, 8);
2558 }
2559 }
2560 a & x.m_description;
2561 if (ver < 17)
2562 {
2563 x.m_is_subaddress = false;
2564 return;
2565 }
2566 a & x.m_is_subaddress;
2567 if (ver < 18)
2568 return;
2569 a & x.m_has_payment_id;
2570 if (x.m_has_payment_id)
2571 a & x.m_payment_id;
2572 }
2573
2574 template <class Archive>
2575 inline void serialize(Archive& a, tools::wallet2::reserve_proof_entry& x, const boost::serialization::version_type ver)
2576 {
2577 a & x.txid;
2578 a & x.index_in_tx;
2579 a & x.shared_secret;
2580 a & x.key_image;
2581 a & x.shared_secret_sig;
2582 a & x.key_image_sig;
2583 }
2584
2585 template <class Archive>
2586 inline void serialize(Archive &a, tools::wallet2::unsigned_tx_set &x, const boost::serialization::version_type ver)
2587 {
2588 a & x.txes;
2589 if (ver == 0)
2590 {
2591 // load old version
2592 std::pair<size_t, tools::wallet2::transfer_container> old_transfers;
2593 a & old_transfers;
2594 std::get<0>(x.transfers) = std::get<0>(old_transfers);
2595 std::get<1>(x.transfers) = std::get<0>(old_transfers) + std::get<1>(old_transfers).size();
2596 std::get<2>(x.transfers) = std::get<1>(old_transfers);
2597 return;
2598 }
2599 throw std::runtime_error("Boost serialization not supported for newest unsigned_tx_set");
2600 }
2601
2602 template <class Archive>
2603 inline void serialize(Archive &a, tools::wallet2::signed_tx_set &x, const boost::serialization::version_type ver)
2604 {
2605 a & x.ptx;
2606 a & x.key_images;
2607 if (ver < 1)
2608 return;
2609 a & x.tx_key_images.parent();
2610 }
2611
2612 template <class Archive>
2613 inline void serialize(Archive &a, tools::wallet2::tx_construction_data &x, const boost::serialization::version_type ver)
2614 {
2615 a & x.sources;
2616 a & x.change_dts;
2617 a & x.splitted_dsts;
2618 if (ver < 2)
2619 {
2620 // load list to vector
2621 std::list<size_t> selected_transfers;
2622 a & selected_transfers;
2623 x.selected_transfers.clear();
2624 x.selected_transfers.reserve(selected_transfers.size());
2625 for (size_t t: selected_transfers)
2626 x.selected_transfers.push_back(t);
2627 }
2628 a & x.extra;
2629 a & x.unlock_time;
2630 a & x.use_rct;
2631 a & x.dests;
2632 if (ver < 1)
2633 {
2634 x.subaddr_account = 0;
2635 return;
2636 }
2637 a & x.subaddr_account;
2638 a & x.subaddr_indices;
2639 if (ver < 2)
2640 {
2641 if (!typename Archive::is_saving())
2642 x.rct_config = { rct::RangeProofBorromean, 0 };
2643 return;
2644 }
2645 a & x.selected_transfers;
2646 if (ver < 3)
2647 {
2648 if (!typename Archive::is_saving())
2649 x.rct_config = { rct::RangeProofBorromean, 0 };
2650 return;
2651 }
2652 if (ver < 4)
2653 {
2654 bool use_bulletproofs = x.rct_config.range_proof_type != rct::RangeProofBorromean;
2655 a & use_bulletproofs;
2656 if (!typename Archive::is_saving())
2657 x.rct_config = { use_bulletproofs ? rct::RangeProofPaddedBulletproof : rct::RangeProofBorromean, 0 };
2658 return;
2659 }
2660 a & x.rct_config;
2661 }
2662
2663 template <class Archive>
2664 inline void serialize(Archive &a, tools::wallet2::multisig_sig &x, const boost::serialization::version_type ver)
2665 {
2666 a & x.sigs;
2667 a & x.ignore;
2668 a & x.used_L;
2669 a & x.signing_keys;
2670 a & x.msout;
2671 if (ver < 1)
2672 return;
2673 a & x.total_alpha_G;
2674 a & x.total_alpha_H;
2675 a & x.c_0;
2676 a & x.s;
2677 }
2678
2679 template <class Archive>
2680 inline void serialize(Archive &a, tools::wallet2::pending_tx &x, const boost::serialization::version_type ver)
2681 {
2682 a & x.tx;
2683 a & x.dust;
2684 a & x.fee;
2685 a & x.dust_added_to_fee;
2686 a & x.change_dts;
2687 if (ver < 2)
2688 {
2689 // load list to vector
2690 std::list<size_t> selected_transfers;
2691 a & selected_transfers;
2692 x.selected_transfers.clear();
2693 x.selected_transfers.reserve(selected_transfers.size());
2694 for (size_t t: selected_transfers)
2695 x.selected_transfers.push_back(t);
2696 }
2697 a & x.key_images;
2698 a & x.tx_key;
2699 a & x.dests;
2700 a & x.construction_data;
2701 if (ver < 1)
2702 return;
2703 a & x.additional_tx_keys;
2704 if (ver < 2)
2705 return;
2706 a & x.selected_transfers;
2707 if (ver < 3)
2708 return;
2709 a & x.multisig_sigs;
2710 }
2711
2712 template <class Archive>
2713 inline void serialize(Archive& a, tools::wallet2::background_synced_tx_t &x, const boost::serialization::version_type ver)
2714 {
2715 a & x.index_in_background_sync_data;
2716 a & x.tx;
2717 a & x.output_indices;
2718 a & x.height;
2719 a & x.block_timestamp;
2720 a & x.double_spend_seen;
2721 }
2722
2723 template <class Archive>
2724 inline void serialize(Archive& a, tools::wallet2::background_sync_data_t &x, const boost::serialization::version_type ver)
2725 {
2726 a & x.first_refresh_done;
2727 a & x.start_height;
2728 a & x.txs.parent();
2729 a & x.wallet_refresh_from_block_height;
2730 a & x.subaddress_lookahead_major;
2731 a & x.subaddress_lookahead_minor;
2732 a & x.wallet_refresh_type;
2733 }
2734 }
2735 }
2736
2737 namespace tools
2738 {
2739
2740 namespace detail
2741 {
2742 //----------------------------------------------------------------------------------------------------
2743 inline void digit_split_strategy(const std::vector<cryptonote::tx_destination_entry>& dsts,
2744 const cryptonote::tx_destination_entry& change_dst, uint64_t dust_threshold,
2745 std::vector<cryptonote::tx_destination_entry>& splitted_dsts, std::vector<cryptonote::tx_destination_entry> &dust_dsts)
2746 {
2747 splitted_dsts.clear();
2748 dust_dsts.clear();
2749
2750 for(auto& de: dsts)
2751 {
2752 cryptonote::decompose_amount_into_digits(de.amount, 0,
2753 [&](uint64_t chunk) { splitted_dsts.push_back(cryptonote::tx_destination_entry(chunk, de.addr, de.is_subaddress)); },
2754 [&](uint64_t a_dust) { splitted_dsts.push_back(cryptonote::tx_destination_entry(a_dust, de.addr, de.is_subaddress)); } );
2755 }
2756
2757 cryptonote::decompose_amount_into_digits(change_dst.amount, 0,
2758 [&](uint64_t chunk) {
2759 if (chunk <= dust_threshold)
2760 dust_dsts.push_back(cryptonote::tx_destination_entry(chunk, change_dst.addr, false));
2761 else
2762 splitted_dsts.push_back(cryptonote::tx_destination_entry(chunk, change_dst.addr, false));
2763 },
2764 [&](uint64_t a_dust) { dust_dsts.push_back(cryptonote::tx_destination_entry(a_dust, change_dst.addr, false)); } );
2765 }
2766 //----------------------------------------------------------------------------------------------------
2767 inline void null_split_strategy(const std::vector<cryptonote::tx_destination_entry>& dsts,
2768 const cryptonote::tx_destination_entry& change_dst, uint64_t dust_threshold,
2769 std::vector<cryptonote::tx_destination_entry>& splitted_dsts, std::vector<cryptonote::tx_destination_entry> &dust_dsts)
2770 {
2771 splitted_dsts = dsts;
2772
2773 dust_dsts.clear();
2774 uint64_t change = change_dst.amount;
2775
2776 if (0 != change)
2777 {
2778 splitted_dsts.push_back(cryptonote::tx_destination_entry(change, change_dst.addr, false));
2779 }
2780 }
2781 //----------------------------------------------------------------------------------------------------
2782 inline void print_source_entry(const cryptonote::tx_source_entry& src)
2783 {
2784 std::string indexes;
2785 std::for_each(src.outputs.begin(), src.outputs.end(), [&](const cryptonote::tx_source_entry::output_entry& s_e) { indexes += boost::to_string(s_e.first) + " "; });
2786 LOG_PRINT_L0("amount=" << cryptonote::print_money(src.amount) << ", real_output=" <<src.real_output << ", real_output_in_tx_index=" << src.real_output_in_tx_index << ", indexes: " << indexes);
2787 }
2788 //----------------------------------------------------------------------------------------------------
2789 }
2790 //----------------------------------------------------------------------------------------------------
2791 }