Monero
wallet2.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2020, 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"
51 #include "net/http.h"
52 #include "storages/http_abstract_invoke.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"
63 #include "serialization/crypto.h"
64 #include "serialization/string.h"
65 #include "serialization/pair.h"
67 
68 #include "wallet_errors.h"
69 #include "common/password.h"
70 #include "node_rpc_proxy.h"
71 #include "message_store.h"
72 #include "wallet_light_rpc.h"
73 #include "wallet_rpc_helpers.h"
74 
75 #undef MONERO_DEFAULT_LOG_CATEGORY
76 #define MONERO_DEFAULT_LOG_CATEGORY "wallet.wallet2"
77 
78 #define THROW_ON_RPC_RESPONSE_ERROR(r, error, res, method, ...) \
79  do { \
80  handle_payment_changes(res, std::integral_constant<bool, HasCredits<decltype(res)>::Has>()); \
81  throw_on_rpc_response_error(r, error, res.status, method); \
82  THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, ## __VA_ARGS__); \
83  } while(0)
84 
85 #define THROW_ON_RPC_RESPONSE_ERROR_GENERIC(r, err, res, method) \
86  THROW_ON_RPC_RESPONSE_ERROR(r, err, res, method, tools::error::wallet_generic_rpc_error, method, res.status)
87 
88 class Serialization_portability_wallet_Test;
89 class wallet_accessor_test;
90 
91 namespace tools
92 {
93  class ringdb;
94  class wallet2;
95  class Notify;
96 
98  {
99  public:
100  uint64_t pick();
101  gamma_picker(const std::vector<uint64_t> &rct_offsets);
102  gamma_picker(const std::vector<uint64_t> &rct_offsets, double shape, double scale);
103 
104  private:
106  {
107  typedef uint64_t result_type;
108  static constexpr result_type min() { return 0; }
109  static constexpr result_type max() { return std::numeric_limits<result_type>::max(); }
110  result_type operator()() { return crypto::rand<result_type>(); }
112 
113 private:
114  std::gamma_distribution<double> gamma;
115  const std::vector<uint64_t> &rct_offsets;
116  const uint64_t *begin, *end;
117  uint64_t num_rct_outputs;
119  };
120 
122  {
123  public:
124  wallet_keys_unlocker(wallet2 &w, const boost::optional<tools::password_container> &password);
125  wallet_keys_unlocker(wallet2 &w, bool locked, const epee::wipeable_string &password);
127  private:
129  bool locked;
130  crypto::chacha_key key;
131  static boost::mutex lockers_lock;
132  static unsigned int lockers;
133  };
134 
136  {
137  public:
138  // Full wallet callbacks
139  virtual void on_new_block(uint64_t height, const cryptonote::block& block) {}
140  virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, bool is_change, uint64_t unlock_time) {}
141  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) {}
142  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) {}
143  virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx) {}
144  virtual boost::optional<epee::wipeable_string> on_get_password(const char *reason) { return boost::none; }
145  // Light wallet callbacks
146  virtual void on_lw_new_block(uint64_t height) {}
147  virtual void on_lw_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount) {}
148  virtual void on_lw_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount) {}
149  virtual void on_lw_money_spent(uint64_t height, const crypto::hash &txid, uint64_t amount) {}
150  // Device callbacks
151  virtual void on_device_button_request(uint64_t code) {}
152  virtual void on_device_button_pressed() {}
153  virtual boost::optional<epee::wipeable_string> on_device_pin_request() { return boost::none; }
154  virtual boost::optional<epee::wipeable_string> on_device_passphrase_request(bool & on_device) { on_device = true; return boost::none; }
155  virtual void on_device_progress(const hw::device_progress& event) {};
156  // Common callbacks
157  virtual void on_pool_tx_removed(const crypto::hash &txid) {}
158  virtual ~i_wallet2_callback() {}
159  };
160 
162  {
163  public:
165  void on_button_request(uint64_t code=0) override;
166  void on_button_pressed() override;
167  boost::optional<epee::wipeable_string> on_pin_request() override;
168  boost::optional<epee::wipeable_string> on_passphrase_request(bool & on_device) override;
169  void on_progress(const hw::device_progress& event) override;
170  private:
172  };
173 
175  {
176  uint64_t dust_threshold;
179 
180  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())
181  : dust_threshold(a_dust_threshold)
182  , add_to_fee(an_add_to_fee)
183  , addr_for_dust(an_addr_for_dust)
184  {
185  }
186  };
187 
188  class hashchain
189  {
190  public:
192 
193  size_t size() const { return m_blockchain.size() + m_offset; }
194  size_t offset() const { return m_offset; }
195  const crypto::hash &genesis() const { return m_genesis; }
196  void push_back(const crypto::hash &hash) { if (m_offset == 0 && m_blockchain.empty()) m_genesis = hash; m_blockchain.push_back(hash); }
197  bool is_in_bounds(size_t idx) const { return idx >= m_offset && idx < size(); }
198  const crypto::hash &operator[](size_t idx) const { return m_blockchain[idx - m_offset]; }
199  crypto::hash &operator[](size_t idx) { return m_blockchain[idx - m_offset]; }
200  void crop(size_t height) { m_blockchain.resize(height - m_offset); }
201  void clear() { m_offset = 0; m_blockchain.clear(); }
202  bool empty() const { return m_blockchain.empty() && m_offset == 0; }
203  void trim(size_t height) { while (height > m_offset && m_blockchain.size() > 1) { m_blockchain.pop_front(); ++m_offset; } m_blockchain.shrink_to_fit(); }
204  void refill(const crypto::hash &hash) { m_blockchain.push_back(hash); --m_offset; }
205 
206  template <class t_archive>
207  inline void serialize(t_archive &a, const unsigned int ver)
208  {
209  a & m_offset;
210  a & m_genesis;
211  a & m_blockchain;
212  }
213 
215  VERSION_FIELD(0)
219  END_SERIALIZE()
220 
221  private:
222  size_t m_offset;
225  };
226 
227  class wallet_keys_unlocker;
228  class wallet2
229  {
230  friend class ::Serialization_portability_wallet_Test;
231  friend class ::wallet_accessor_test;
232  friend class wallet_keys_unlocker;
234  public:
235  static constexpr const std::chrono::seconds rpc_timeout = std::chrono::minutes(3) + std::chrono::seconds(30);
236 
237  enum RefreshType {
241  RefreshDefault = RefreshOptimizeCoinbase,
242  };
243 
245  AskPasswordNever = 0,
246  AskPasswordOnAction = 1,
247  AskPasswordToDecrypt = 2,
248  };
249 
251  BackgroundMiningMaybe = 0,
252  BackgroundMiningYes = 1,
253  BackgroundMiningNo = 2,
254  };
255 
257  Binary = 0,
259  };
260 
261  static const char* tr(const char* str);
262 
263  static bool has_testnet_option(const boost::program_options::variables_map& vm);
264  static bool has_stagenet_option(const boost::program_options::variables_map& vm);
265  static std::string device_name_option(const boost::program_options::variables_map& vm);
266  static std::string device_derivation_path_option(const boost::program_options::variables_map &vm);
267  static void init_options(boost::program_options::options_description& desc_params);
268 
270  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);
271 
273  static std::pair<std::unique_ptr<wallet2>, password_container>
274  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);
275 
277  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);
278 
280  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);
281 
282  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);
283  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);
284 
285  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()));
286  ~wallet2();
287 
289  {
290  struct LR
291  {
294 
296  FIELD(m_L)
297  FIELD(m_R)
298  END_SERIALIZE()
299  };
300 
301  crypto::public_key m_signer;
302  std::vector<LR> m_LR;
303  std::vector<crypto::key_image> m_partial_key_images; // one per key the participant has
304 
306  FIELD(m_signer)
307  FIELD(m_LR)
308  FIELD(m_partial_key_images)
309  END_SERIALIZE()
310  };
311 
313  {
317  uint64_t amount;
319  bool error;
320  boost::optional<cryptonote::subaddress_receive_info> received;
321 
322  tx_scan_info_t(): amount(0), money_transfered(0), error(true) {}
323  };
324 
326  {
327  uint64_t m_block_height;
332  bool m_spent;
333  bool m_frozen;
334  uint64_t m_spent_height;
335  crypto::key_image m_key_image; //TODO: key_image stored twice :(
337  uint64_t m_amount;
338  bool m_rct;
340  bool m_key_image_request; // view wallets: we want to request it; cold wallets: it was requested
341  size_t m_pk_index;
344  std::vector<rct::key> m_multisig_k;
345  std::vector<multisig_info> m_multisig_info; // one per other participant
346  std::vector<std::pair<uint64_t, crypto::hash>> m_uses;
347 
348  bool is_rct() const { return m_rct; }
349  uint64_t amount() const { return m_amount; }
350  const crypto::public_key &get_public_key() const { return boost::get<const cryptonote::txout_to_key>(m_tx.vout[m_internal_output_index].target).key; }
351 
353  FIELD(m_block_height)
354  FIELD(m_tx)
355  FIELD(m_txid)
356  FIELD(m_internal_output_index)
357  FIELD(m_global_output_index)
358  FIELD(m_spent)
359  FIELD(m_frozen)
360  FIELD(m_spent_height)
361  FIELD(m_key_image)
362  FIELD(m_mask)
363  FIELD(m_amount)
364  FIELD(m_rct)
365  FIELD(m_key_image_known)
366  FIELD(m_key_image_request)
367  FIELD(m_pk_index)
368  FIELD(m_subaddr_index)
369  FIELD(m_key_image_partial)
370  FIELD(m_multisig_k)
371  FIELD(m_multisig_info)
372  FIELD(m_uses)
373  END_SERIALIZE()
374  };
375 
376  typedef std::vector<uint64_t> amounts_container;
378  {
380  uint64_t m_amount;
382  uint64_t m_fee;
383  uint64_t m_block_height;
384  uint64_t m_unlock_time;
385  uint64_t m_timestamp;
388 
390  VERSION_FIELD(0)
391  FIELD(m_tx_hash)
392  VARINT_FIELD(m_amount)
393  FIELD(m_amounts)
394  VARINT_FIELD(m_fee)
395  VARINT_FIELD(m_block_height)
396  VARINT_FIELD(m_unlock_time)
397  VARINT_FIELD(m_timestamp)
398  FIELD(m_coinbase)
399  FIELD(m_subaddr_index)
400  END_SERIALIZE()
401  };
402 
404  {
405  bool m_mempool;
407  };
408 
410  {
413 
415  VERSION_FIELD(0)
416  FIELD(m_pd)
417  FIELD(m_double_spend_seen)
418  END_SERIALIZE()
419  };
420 
422  {
424  uint64_t m_amount_in;
425  uint64_t m_amount_out;
426  uint64_t m_change;
427  time_t m_sent_time;
428  std::vector<cryptonote::tx_destination_entry> m_dests;
430  enum { pending, pending_not_in_pool, failed } m_state;
431  uint64_t m_timestamp;
432  uint32_t m_subaddr_account; // subaddress account of your wallet to be used in this transfer
433  std::set<uint32_t> m_subaddr_indices; // set of address indices used as inputs in this transfer
434  std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> m_rings; // relative
435 
437  VERSION_FIELD(1)
438  FIELD(m_tx)
439  VARINT_FIELD(m_amount_in)
440  VARINT_FIELD(m_amount_out)
441  VARINT_FIELD(m_change)
442  VARINT_FIELD(m_sent_time)
443  FIELD(m_dests)
444  FIELD(m_payment_id)
445  if (version >= 1)
446  VARINT_FIELD(m_state)
447  VARINT_FIELD(m_timestamp)
448  VARINT_FIELD(m_subaddr_account)
449  FIELD(m_subaddr_indices)
450  FIELD(m_rings)
451  END_SERIALIZE()
452  };
453 
455  {
456  uint64_t m_amount_in;
457  uint64_t m_amount_out;
458  uint64_t m_change;
459  uint64_t m_block_height;
460  std::vector<cryptonote::tx_destination_entry> m_dests;
462  uint64_t m_timestamp;
463  uint64_t m_unlock_time;
464  uint32_t m_subaddr_account; // subaddress account of your wallet to be used in this transfer
465  std::set<uint32_t> m_subaddr_indices; // set of address indices used as inputs in this transfer
466  std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> m_rings; // relative
467 
468  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) {}
470  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) {}
471 
473  VERSION_FIELD(0)
474  VARINT_FIELD(m_amount_in)
475  VARINT_FIELD(m_amount_out)
476  VARINT_FIELD(m_change)
477  VARINT_FIELD(m_block_height)
478  FIELD(m_dests)
479  FIELD(m_payment_id)
480  VARINT_FIELD(m_timestamp)
481  VARINT_FIELD(m_unlock_time)
482  VARINT_FIELD(m_subaddr_account)
483  FIELD(m_subaddr_indices)
484  FIELD(m_rings)
485  END_SERIALIZE()
486  };
487 
489  {
490  std::vector<cryptonote::tx_source_entry> sources;
492  std::vector<cryptonote::tx_destination_entry> splitted_dsts; // split, includes change
493  std::vector<size_t> selected_transfers;
494  std::vector<uint8_t> extra;
495  uint64_t unlock_time;
496  bool use_rct;
498  std::vector<cryptonote::tx_destination_entry> dests; // original setup, does not include change
499  uint32_t subaddr_account; // subaddress account of your wallet to be used in this transfer
500  std::set<uint32_t> subaddr_indices; // set of address indices used as inputs in this transfer
501 
503  FIELD(sources)
504  FIELD(change_dts)
505  FIELD(splitted_dsts)
506  FIELD(selected_transfers)
507  FIELD(extra)
508  FIELD(unlock_time)
509  FIELD(use_rct)
510  FIELD(rct_config)
511  FIELD(dests)
512  FIELD(subaddr_account)
513  FIELD(subaddr_indices)
514  END_SERIALIZE()
515  };
516 
519 
521  {
523  std::unordered_set<crypto::public_key> ignore;
524  std::unordered_set<rct::key> used_L;
525  std::unordered_set<crypto::public_key> signing_keys;
527 
529  VERSION_FIELD(0)
530  FIELD(sigs)
531  FIELD(ignore)
532  FIELD(used_L)
533  FIELD(signing_keys)
534  FIELD(msout)
535  END_SERIALIZE()
536  };
537 
538  // The convention for destinations is:
539  // dests does not include change
540  // splitted_dsts (in construction_data) does
541  struct pending_tx
542  {
544  uint64_t dust, fee;
547  std::vector<size_t> selected_transfers;
548  std::string key_images;
550  std::vector<crypto::secret_key> additional_tx_keys;
551  std::vector<cryptonote::tx_destination_entry> dests;
552  std::vector<multisig_sig> multisig_sigs;
553 
555 
557  FIELD(tx)
558  FIELD(dust)
559  FIELD(fee)
560  FIELD(dust_added_to_fee)
561  FIELD(change_dts)
562  FIELD(selected_transfers)
563  FIELD(key_images)
564  FIELD(tx_key)
565  FIELD(additional_tx_keys)
566  FIELD(dests)
567  FIELD(construction_data)
568  FIELD(multisig_sigs)
569  END_SERIALIZE()
570  };
571 
572  // The term "Unsigned tx" is not really a tx since it's not signed yet.
573  // It doesnt have tx hash, key and the integrated address is not separated into addr + payment id.
575  {
576  std::vector<tx_construction_data> txes;
577  std::pair<size_t, wallet2::transfer_container> transfers;
578 
580  VERSION_FIELD(0)
581  FIELD(txes)
582  FIELD(transfers)
583  END_SERIALIZE()
584  };
585 
587  {
588  std::vector<pending_tx> ptx;
589  std::vector<crypto::key_image> key_images;
591 
593  VERSION_FIELD(0)
594  FIELD(ptx)
595  FIELD(key_images)
596  FIELD(tx_key_images)
597  END_SERIALIZE()
598  };
599 
601  {
602  std::vector<pending_tx> m_ptx;
603  std::unordered_set<crypto::public_key> m_signers;
604 
606  FIELD(m_ptx)
607  FIELD(m_signers)
608  END_SERIALIZE()
609  };
610 
612  {
613  crypto::chacha_iv iv;
614  std::string account_data;
615 
617  FIELD(iv)
618  FIELD(account_data)
619  END_SERIALIZE()
620  };
621 
623  {
624  crypto::chacha_iv iv;
625  std::string cache_data;
626 
628  FIELD(iv)
629  FIELD(cache_data)
630  END_SERIALIZE()
631  };
632 
633  // GUI Address book
635  {
638  std::string m_description;
641 
643  VERSION_FIELD(0)
644  FIELD(m_address)
645  FIELD(m_payment_id)
646  FIELD(m_description)
647  FIELD(m_is_subaddress)
648  FIELD(m_has_payment_id)
649  END_SERIALIZE()
650  };
651 
653  {
655  uint64_t index_in_tx;
660 
662  VERSION_FIELD(0)
663  FIELD(txid)
664  VARINT_FIELD(index_in_tx)
665  FIELD(shared_secret)
667  FIELD(shared_secret_sig)
668  FIELD(key_image_sig)
669  END_SERIALIZE()
670  };
671 
672  typedef std::tuple<uint64_t, crypto::public_key, rct::key> get_outs_entry;
673 
675  {
678  std::vector<cryptonote::transaction> txes;
680  bool error;
681  };
682 
683  struct is_out_data
684  {
687  std::vector<boost::optional<cryptonote::subaddress_receive_info>> received;
688  };
689 
691  {
692  std::vector<cryptonote::tx_extra_field> tx_extra_fields;
693  std::vector<is_out_data> primary;
694  std::vector<is_out_data> additional;
695 
696  bool empty() const { return tx_extra_fields.empty() && primary.empty() && additional.empty(); }
697  };
698 
706  void generate(const std::string& wallet_, const epee::wipeable_string& password,
707  const epee::wipeable_string& multisig_data, bool create_address_file = false);
708 
719  crypto::secret_key generate(const std::string& wallet, const epee::wipeable_string& password,
720  const crypto::secret_key& recovery_param = crypto::secret_key(), bool recover = false,
721  bool two_random = false, bool create_address_file = false);
731  void generate(const std::string& wallet, const epee::wipeable_string& password,
732  const cryptonote::account_public_address &account_public_address,
733  const crypto::secret_key& spendkey, const crypto::secret_key& viewkey, bool create_address_file = false);
742  void generate(const std::string& wallet, const epee::wipeable_string& password,
743  const cryptonote::account_public_address &account_public_address,
744  const crypto::secret_key& viewkey = crypto::secret_key(), bool create_address_file = false);
752  void restore(const std::string& wallet_, const epee::wipeable_string& password, const std::string &device_name, bool create_address_file = false);
753 
759  std::string make_multisig(const epee::wipeable_string &password,
760  const std::vector<std::string> &info,
761  uint32_t threshold);
767  std::string make_multisig(const epee::wipeable_string &password,
768  const std::vector<crypto::secret_key> &view_keys,
769  const std::vector<crypto::public_key> &spend_keys,
770  uint32_t threshold);
771  std::string exchange_multisig_keys(const epee::wipeable_string &password,
772  const std::vector<std::string> &info);
776  std::string exchange_multisig_keys(const epee::wipeable_string &password,
777  std::unordered_set<crypto::public_key> pkeys,
778  std::vector<crypto::public_key> signers);
782  bool finalize_multisig(const epee::wipeable_string &password, const std::vector<std::string> &info);
786  bool finalize_multisig(const epee::wipeable_string &password, const std::unordered_set<crypto::public_key> &pkeys, std::vector<crypto::public_key> signers);
790  std::string get_multisig_info() const;
794  static bool verify_multisig_info(const std::string &data, crypto::secret_key &skey, crypto::public_key &pkey);
798  static bool verify_extra_multisig_info(const std::string &data, std::unordered_set<crypto::public_key> &pkeys, crypto::public_key &signer);
803  cryptonote::blobdata export_multisig();
808  size_t import_multisig(std::vector<cryptonote::blobdata> info);
814  void rewrite(const std::string& wallet_name, const epee::wipeable_string& password);
815  void write_watch_only_wallet(const std::string& wallet_name, const epee::wipeable_string& password, std::string &new_keys_filename);
816  void load(const std::string& wallet, const epee::wipeable_string& password, const std::string& keys_buf = "", const std::string& cache_buf = "");
817  void store();
823  void store_to(const std::string &path, const epee::wipeable_string &password);
830  boost::optional<wallet2::keys_file_data> get_keys_file_data(const epee::wipeable_string& password, bool watch_only);
836  boost::optional<wallet2::cache_file_data> get_cache_file_data(const epee::wipeable_string& password);
837 
838  std::string path() const;
839 
843  bool verify_password(const epee::wipeable_string& password);
844  cryptonote::account_base& get_account(){return m_account;}
845  const cryptonote::account_base& get_account()const{return m_account;}
846 
847  void encrypt_keys(const crypto::chacha_key &key);
848  void encrypt_keys(const epee::wipeable_string &password);
849  void decrypt_keys(const crypto::chacha_key &key);
850  void decrypt_keys(const epee::wipeable_string &password);
851 
852  void set_refresh_from_block_height(uint64_t height) {m_refresh_from_block_height = height;}
853  uint64_t get_refresh_from_block_height() const {return m_refresh_from_block_height;}
854 
855  void explicit_refresh_from_block_height(bool expl) {m_explicit_refresh_from_block_height = expl;}
856  bool explicit_refresh_from_block_height() const {return m_explicit_refresh_from_block_height;}
857 
858  bool deinit();
859  bool init(std::string daemon_address = "http://localhost:8080",
860  boost::optional<epee::net_utils::http::login> daemon_login = boost::none,
861  const std::string &proxy = "",
862  uint64_t upper_transaction_weight_limit = 0,
863  bool trusted_daemon = true,
864  epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
865  bool set_daemon(std::string daemon_address = "http://localhost:8080",
866  boost::optional<epee::net_utils::http::login> daemon_login = boost::none, bool trusted_daemon = true,
867  epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
868  bool set_proxy(const std::string &address);
869 
870  void stop() { m_run.store(false, std::memory_order_relaxed); m_message_store.stop(); }
871 
872  i_wallet2_callback* callback() const { return m_callback; }
873  void callback(i_wallet2_callback* callback) { m_callback = callback; }
874 
875  bool is_trusted_daemon() const { return m_trusted_daemon; }
876  void set_trusted_daemon(bool trusted) { m_trusted_daemon = trusted; }
877 
881  bool is_deterministic() const;
882  bool get_seed(epee::wipeable_string& electrum_words, const epee::wipeable_string &passphrase = epee::wipeable_string()) const;
883 
887  bool light_wallet() const { return m_light_wallet; }
888  void set_light_wallet(bool light_wallet) { m_light_wallet = light_wallet; }
889  uint64_t get_light_wallet_scanned_block_height() const { return m_light_wallet_scanned_block_height; }
890  uint64_t get_light_wallet_blockchain_height() const { return m_light_wallet_blockchain_height; }
891 
895  const std::string &get_seed_language() const;
899  void set_seed_language(const std::string &language);
900 
901  // Subaddress scheme
902  cryptonote::account_public_address get_subaddress(const cryptonote::subaddress_index& index) const;
903  cryptonote::account_public_address get_address() const { return get_subaddress({0,0}); }
904  boost::optional<cryptonote::subaddress_index> get_subaddress_index(const cryptonote::account_public_address& address) const;
905  crypto::public_key get_subaddress_spend_public_key(const cryptonote::subaddress_index& index) const;
906  std::vector<crypto::public_key> get_subaddress_spend_public_keys(uint32_t account, uint32_t begin, uint32_t end) const;
907  std::string get_subaddress_as_str(const cryptonote::subaddress_index& index) const;
908  std::string get_address_as_str() const { return get_subaddress_as_str({0, 0}); }
909  std::string get_integrated_address_as_str(const crypto::hash8& payment_id) const;
910  void add_subaddress_account(const std::string& label);
911  size_t get_num_subaddress_accounts() const { return m_subaddress_labels.size(); }
912  size_t get_num_subaddresses(uint32_t index_major) const { return index_major < m_subaddress_labels.size() ? m_subaddress_labels[index_major].size() : 0; }
913  void add_subaddress(uint32_t index_major, const std::string& label); // throws when index is out of bound
914  void expand_subaddresses(const cryptonote::subaddress_index& index);
915  void create_one_off_subaddress(const cryptonote::subaddress_index& index);
916  std::string get_subaddress_label(const cryptonote::subaddress_index& index) const;
917  void set_subaddress_label(const cryptonote::subaddress_index &index, const std::string &label);
918  void set_subaddress_lookahead(size_t major, size_t minor);
919  std::pair<size_t, size_t> get_subaddress_lookahead() const { return {m_subaddress_lookahead_major, m_subaddress_lookahead_minor}; }
923  bool is_deprecated() const;
924  void refresh(bool trusted_daemon);
925  void refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched);
926  void refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blocks_fetched, bool& received_money, bool check_pool = true);
927  bool refresh(bool trusted_daemon, uint64_t & blocks_fetched, bool& received_money, bool& ok);
928 
930  RefreshType get_refresh_type() const { return m_refresh_type; }
931 
932  cryptonote::network_type nettype() const { return m_nettype; }
933  bool watch_only() const { return m_watch_only; }
934  bool multisig(bool *ready = NULL, uint32_t *threshold = NULL, uint32_t *total = NULL) const;
935  bool has_multisig_partial_key_images() const;
936  bool has_unknown_key_images() const;
937  bool get_multisig_seed(epee::wipeable_string& seed, const epee::wipeable_string &passphrase = std::string(), bool raw = true) const;
938  bool key_on_device() const { return get_device_type() != hw::device::device_type::SOFTWARE; }
939  hw::device::device_type get_device_type() const { return m_key_device_type; }
940  bool reconnect_device();
941 
942  // locked & unlocked balance of given or current subaddress account
943  uint64_t balance(uint32_t subaddr_index_major, bool strict) const;
944  uint64_t unlocked_balance(uint32_t subaddr_index_major, bool strict, uint64_t *blocks_to_unlock = NULL, uint64_t *time_to_unlock = NULL);
945  // locked & unlocked balance per subaddress of given or current subaddress account
946  std::map<uint32_t, uint64_t> balance_per_subaddress(uint32_t subaddr_index_major, bool strict) const;
947  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);
948  // all locked & unlocked balances of all subaddress accounts
949  uint64_t balance_all(bool strict) const;
950  uint64_t unlocked_balance_all(bool strict, uint64_t *blocks_to_unlock = NULL, uint64_t *time_to_unlock = NULL);
951  template<typename T>
952  void transfer_selected(const std::vector<cryptonote::tx_destination_entry>& dsts, const std::vector<size_t>& selected_transfers, size_t fake_outputs_count,
953  std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs,
954  uint64_t unlock_time, 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);
955  void transfer_selected_rct(std::vector<cryptonote::tx_destination_entry> dsts, const std::vector<size_t>& selected_transfers, size_t fake_outputs_count,
956  std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs,
957  uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx &ptx, const rct::RCTConfig &rct_config);
958 
959  void commit_tx(pending_tx& ptx_vector);
960  void commit_tx(std::vector<pending_tx>& ptx_vector);
961  bool save_tx(const std::vector<pending_tx>& ptx_vector, const std::string &filename) const;
962  std::string dump_tx_to_str(const std::vector<pending_tx> &ptx_vector) const;
963  std::string save_multisig_tx(multisig_tx_set txs);
964  bool save_multisig_tx(const multisig_tx_set &txs, const std::string &filename);
965  std::string save_multisig_tx(const std::vector<pending_tx>& ptx_vector);
966  bool save_multisig_tx(const std::vector<pending_tx>& ptx_vector, const std::string &filename);
967  multisig_tx_set make_multisig_tx_set(const std::vector<pending_tx>& ptx_vector) const;
968  // load unsigned tx from file and sign it. Takes confirmation callback as argument. Used by the cli wallet
969  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);
970  // sign unsigned tx. Takes unsigned_tx_set as argument. Used by GUI
971  bool sign_tx(unsigned_tx_set &exported_txs, const std::string &signed_filename, std::vector<wallet2::pending_tx> &ptx, bool export_raw = false);
972  bool sign_tx(unsigned_tx_set &exported_txs, std::vector<wallet2::pending_tx> &ptx, signed_tx_set &signed_txs);
973  std::string sign_tx_dump_to_str(unsigned_tx_set &exported_txs, std::vector<wallet2::pending_tx> &ptx, signed_tx_set &signed_txes);
974  // load unsigned_tx_set from file.
975  bool load_unsigned_tx(const std::string &unsigned_filename, unsigned_tx_set &exported_txs) const;
976  bool parse_unsigned_tx_from_str(const std::string &unsigned_tx_st, unsigned_tx_set &exported_txs) const;
977  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);
978  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);
979  std::vector<wallet2::pending_tx> create_transactions_2(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices); // pass subaddr_indices by value on purpose
980  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, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices);
981  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, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra);
982  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, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra);
983  bool sanity_check(const std::vector<wallet2::pending_tx> &ptx_vector, std::vector<cryptonote::tx_destination_entry> dsts) const;
984  void cold_tx_aux_import(const std::vector<pending_tx>& ptx, const std::vector<std::string>& tx_device_aux);
985  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);
986  uint64_t cold_key_image_sync(uint64_t &spent, uint64_t &unspent);
987  void device_show_address(uint32_t account_index, uint32_t address_index, const boost::optional<crypto::hash8> &payment_id);
988  bool parse_multisig_tx_from_str(std::string multisig_tx_st, multisig_tx_set &exported_txs) const;
989  bool load_multisig_tx(cryptonote::blobdata blob, multisig_tx_set &exported_txs, std::function<bool(const multisig_tx_set&)> accept_func = NULL);
990  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);
991  bool sign_multisig_tx_from_file(const std::string &filename, std::vector<crypto::hash> &txids, std::function<bool(const multisig_tx_set&)> accept_func);
992  bool sign_multisig_tx(multisig_tx_set &exported_txs, std::vector<crypto::hash> &txids);
993  bool sign_multisig_tx_to_file(multisig_tx_set &exported_txs, const std::string &filename, std::vector<crypto::hash> &txids);
994  std::vector<pending_tx> create_unmixable_sweep_transactions();
995  void discard_unmixable_outputs();
996  bool check_connection(uint32_t *version = NULL, bool *ssl = NULL, uint32_t timeout = 200000);
997  void get_transfers(wallet2::transfer_container& incoming_transfers) const;
998  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;
999  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;
1000  void get_payments_out(std::list<std::pair<crypto::hash,wallet2::confirmed_transfer_details>>& confirmed_payments,
1001  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;
1002  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;
1003  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;
1004 
1005  uint64_t get_blockchain_current_height() const { return m_light_wallet_blockchain_height ? m_light_wallet_blockchain_height : m_blockchain.size(); }
1006  void rescan_spent();
1007  void rescan_blockchain(bool hard, bool refresh = true, bool keep_key_images = false);
1008  bool is_transfer_unlocked(const transfer_details& td);
1009  bool is_transfer_unlocked(uint64_t unlock_time, uint64_t block_height);
1010 
1011  uint64_t get_last_block_reward() const { return m_last_block_reward; }
1012  uint64_t get_device_last_key_image_sync() const { return m_device_last_key_image_sync; }
1013 
1014  std::vector<cryptonote::public_node> get_public_nodes(bool white_only = true);
1015 
1016  template <class t_archive>
1017  inline void serialize(t_archive &a, const unsigned int ver)
1018  {
1019  uint64_t dummy_refresh_height = 0; // moved to keys file
1020  if(ver < 5)
1021  return;
1022  if (ver < 19)
1023  {
1024  std::vector<crypto::hash> blockchain;
1025  a & blockchain;
1026  m_blockchain.clear();
1027  for (const auto &b: blockchain)
1028  {
1029  m_blockchain.push_back(b);
1030  }
1031  }
1032  else
1033  {
1034  a & m_blockchain;
1035  }
1036  a & m_transfers;
1037  a & m_account_public_address;
1038  a & m_key_images.parent();
1039  if(ver < 6)
1040  return;
1041  a & m_unconfirmed_txs.parent();
1042  if(ver < 7)
1043  return;
1044  a & m_payments.parent();
1045  if(ver < 8)
1046  return;
1047  a & m_tx_keys.parent();
1048  if(ver < 9)
1049  return;
1050  a & m_confirmed_txs.parent();
1051  if(ver < 11)
1052  return;
1053  a & dummy_refresh_height;
1054  if(ver < 12)
1055  return;
1056  a & m_tx_notes.parent();
1057  if(ver < 13)
1058  return;
1059  if (ver < 17)
1060  {
1061  // we're loading an old version, where m_unconfirmed_payments was a std::map
1062  std::unordered_map<crypto::hash, payment_details> m;
1063  a & m;
1064  m_unconfirmed_payments.clear();
1065  for (std::unordered_map<crypto::hash, payment_details>::const_iterator i = m.begin(); i != m.end(); ++i)
1066  m_unconfirmed_payments.insert(std::make_pair(i->first, pool_payment_details{i->second, false}));
1067  }
1068  if(ver < 14)
1069  return;
1070  if(ver < 15)
1071  {
1072  // we're loading an older wallet without a pubkey map, rebuild it
1073  m_pub_keys.clear();
1074  for (size_t i = 0; i < m_transfers.size(); ++i)
1075  {
1076  const transfer_details &td = m_transfers[i];
1078  const cryptonote::txout_to_key &o = boost::get<const cryptonote::txout_to_key>(out.target);
1079  m_pub_keys.emplace(o.key, i);
1080  }
1081  return;
1082  }
1083  a & m_pub_keys.parent();
1084  if(ver < 16)
1085  return;
1086  a & m_address_book;
1087  if(ver < 17)
1088  return;
1089  if (ver < 22)
1090  {
1091  // we're loading an old version, where m_unconfirmed_payments payload was payment_details
1092  std::unordered_multimap<crypto::hash, payment_details> m;
1093  a & m;
1094  m_unconfirmed_payments.clear();
1095  for (const auto &i: m)
1096  m_unconfirmed_payments.insert(std::make_pair(i.first, pool_payment_details{i.second, false}));
1097  }
1098  if(ver < 18)
1099  return;
1100  a & m_scanned_pool_txs[0];
1101  a & m_scanned_pool_txs[1];
1102  if (ver < 20)
1103  return;
1104  a & m_subaddresses.parent();
1105  std::unordered_map<cryptonote::subaddress_index, crypto::public_key> dummy_subaddresses_inv;
1106  a & dummy_subaddresses_inv;
1107  a & m_subaddress_labels;
1108  a & m_additional_tx_keys.parent();
1109  if(ver < 21)
1110  return;
1111  a & m_attributes.parent();
1112  if(ver < 22)
1113  return;
1114  a & m_unconfirmed_payments.parent();
1115  if(ver < 23)
1116  return;
1117  a & (std::pair<std::map<std::string, std::string>, std::vector<std::string>>&)m_account_tags;
1118  if(ver < 24)
1119  return;
1120  a & m_ring_history_saved;
1121  if(ver < 25)
1122  return;
1123  a & m_last_block_reward;
1124  if(ver < 26)
1125  return;
1126  a & m_tx_device.parent();
1127  if(ver < 27)
1128  return;
1129  a & m_device_last_key_image_sync;
1130  if(ver < 28)
1131  return;
1132  a & m_cold_key_images.parent();
1133  if(ver < 29)
1134  return;
1135  a & m_rpc_client_secret_key;
1136  }
1137 
1139  MAGIC_FIELD("monero wallet cache")
1140  VERSION_FIELD(0)
1142  FIELD(m_transfers)
1143  FIELD(m_account_public_address)
1144  FIELD(m_key_images)
1145  FIELD(m_unconfirmed_txs)
1146  FIELD(m_payments)
1147  FIELD(m_tx_keys)
1148  FIELD(m_confirmed_txs)
1149  FIELD(m_tx_notes)
1150  FIELD(m_unconfirmed_payments)
1151  FIELD(m_pub_keys)
1152  FIELD(m_address_book)
1153  FIELD(m_scanned_pool_txs[0])
1154  FIELD(m_scanned_pool_txs[1])
1155  FIELD(m_subaddresses)
1156  FIELD(m_subaddress_labels)
1157  FIELD(m_additional_tx_keys)
1158  FIELD(m_attributes)
1159  FIELD(m_account_tags)
1160  FIELD(m_ring_history_saved)
1161  FIELD(m_last_block_reward)
1162  FIELD(m_tx_device)
1163  FIELD(m_device_last_key_image_sync)
1164  FIELD(m_cold_key_images)
1165  FIELD(m_rpc_client_secret_key)
1166  END_SERIALIZE()
1167 
1174  static void wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exists);
1180  static bool wallet_valid_path_format(const std::string& file_path);
1181  static bool parse_long_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);
1182  static bool parse_short_payment_id(const std::string& payment_id_str, crypto::hash8& payment_id);
1183  static bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);
1184 
1185  bool always_confirm_transfers() const { return m_always_confirm_transfers; }
1186  void always_confirm_transfers(bool always) { m_always_confirm_transfers = always; }
1187  bool print_ring_members() const { return m_print_ring_members; }
1188  void print_ring_members(bool value) { m_print_ring_members = value; }
1189  bool store_tx_info() const { return m_store_tx_info; }
1190  void store_tx_info(bool store) { m_store_tx_info = store; }
1191  uint32_t default_mixin() const { return m_default_mixin; }
1192  void default_mixin(uint32_t m) { m_default_mixin = m; }
1193  uint32_t get_default_priority() const { return m_default_priority; }
1194  void set_default_priority(uint32_t p) { m_default_priority = p; }
1195  bool auto_refresh() const { return m_auto_refresh; }
1196  void auto_refresh(bool r) { m_auto_refresh = r; }
1197  AskPasswordType ask_password() const { return m_ask_password; }
1198  void ask_password(AskPasswordType ask) { m_ask_password = ask; }
1199  void set_min_output_count(uint32_t count) { m_min_output_count = count; }
1200  uint32_t get_min_output_count() const { return m_min_output_count; }
1201  void set_min_output_value(uint64_t value) { m_min_output_value = value; }
1202  uint64_t get_min_output_value() const { return m_min_output_value; }
1203  void merge_destinations(bool merge) { m_merge_destinations = merge; }
1204  bool merge_destinations() const { return m_merge_destinations; }
1205  bool confirm_backlog() const { return m_confirm_backlog; }
1206  void confirm_backlog(bool always) { m_confirm_backlog = always; }
1207  void set_confirm_backlog_threshold(uint32_t threshold) { m_confirm_backlog_threshold = threshold; };
1208  uint32_t get_confirm_backlog_threshold() const { return m_confirm_backlog_threshold; };
1209  bool confirm_export_overwrite() const { return m_confirm_export_overwrite; }
1210  void confirm_export_overwrite(bool always) { m_confirm_export_overwrite = always; }
1211  bool auto_low_priority() const { return m_auto_low_priority; }
1212  void auto_low_priority(bool value) { m_auto_low_priority = value; }
1213  bool segregate_pre_fork_outputs() const { return m_segregate_pre_fork_outputs; }
1214  void segregate_pre_fork_outputs(bool value) { m_segregate_pre_fork_outputs = value; }
1215  bool key_reuse_mitigation2() const { return m_key_reuse_mitigation2; }
1216  void key_reuse_mitigation2(bool value) { m_key_reuse_mitigation2 = value; }
1217  uint64_t segregation_height() const { return m_segregation_height; }
1218  void segregation_height(uint64_t height) { m_segregation_height = height; }
1219  bool ignore_fractional_outputs() const { return m_ignore_fractional_outputs; }
1220  void ignore_fractional_outputs(bool value) { m_ignore_fractional_outputs = value; }
1221  bool confirm_non_default_ring_size() const { return m_confirm_non_default_ring_size; }
1222  void confirm_non_default_ring_size(bool always) { m_confirm_non_default_ring_size = always; }
1223  uint64_t ignore_outputs_above() const { return m_ignore_outputs_above; }
1224  void ignore_outputs_above(uint64_t value) { m_ignore_outputs_above = value; }
1225  uint64_t ignore_outputs_below() const { return m_ignore_outputs_below; }
1226  void ignore_outputs_below(uint64_t value) { m_ignore_outputs_below = value; }
1227  bool track_uses() const { return m_track_uses; }
1228  void track_uses(bool value) { m_track_uses = value; }
1229  BackgroundMiningSetupType setup_background_mining() const { return m_setup_background_mining; }
1230  void setup_background_mining(BackgroundMiningSetupType value) { m_setup_background_mining = value; }
1231  uint32_t inactivity_lock_timeout() const { return m_inactivity_lock_timeout; }
1232  void inactivity_lock_timeout(uint32_t seconds) { m_inactivity_lock_timeout = seconds; }
1233  const std::string & device_name() const { return m_device_name; }
1234  void device_name(const std::string & device_name) { m_device_name = device_name; }
1235  const std::string & device_derivation_path() const { return m_device_derivation_path; }
1236  void device_derivation_path(const std::string &device_derivation_path) { m_device_derivation_path = device_derivation_path; }
1237  const ExportFormat & export_format() const { return m_export_format; }
1238  inline void set_export_format(const ExportFormat& export_format) { m_export_format = export_format; }
1239  bool load_deprecated_formats() const { return m_load_deprecated_formats; }
1240  void load_deprecated_formats(bool load) { m_load_deprecated_formats = load; }
1241  bool persistent_rpc_client_id() const { return m_persistent_rpc_client_id; }
1242  void persistent_rpc_client_id(bool persistent) { m_persistent_rpc_client_id = persistent; }
1243  void auto_mine_for_rpc_payment_threshold(float threshold) { m_auto_mine_for_rpc_payment_threshold = threshold; }
1244  float auto_mine_for_rpc_payment_threshold() const { return m_auto_mine_for_rpc_payment_threshold; }
1245  crypto::secret_key get_rpc_client_secret_key() const { return m_rpc_client_secret_key; }
1246  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); }
1247  uint64_t credits_target() const { return m_credits_target; }
1248  void credits_target(uint64_t threshold) { m_credits_target = threshold; }
1249 
1250  bool get_tx_key_cached(const crypto::hash &txid, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys) const;
1251  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);
1252  bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys);
1253  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);
1254  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);
1255  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;
1256  std::string get_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message);
1257  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;
1258  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);
1259  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;
1260 
1261  std::string get_spend_proof(const crypto::hash &txid, const std::string &message);
1262  bool check_spend_proof(const crypto::hash &txid, const std::string &message, const std::string &sig_str);
1263 
1271  std::string get_reserve_proof(const boost::optional<std::pair<uint32_t, uint64_t>> &account_minreserve, const std::string &message);
1281  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);
1282 
1286  std::vector<address_book_row> get_address_book() const { return m_address_book; }
1287  bool add_address_book_row(const cryptonote::account_public_address &address, const crypto::hash8 *payment_id, const std::string &description, bool is_subaddress);
1288  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);
1289  bool delete_address_book_row(std::size_t row_id);
1290 
1291  uint64_t get_num_rct_outputs();
1292  size_t get_num_transfer_details() const { return m_transfers.size(); }
1293  const transfer_details &get_transfer_details(size_t idx) const;
1294 
1295  uint8_t get_current_hard_fork();
1296  void get_hard_fork_info(uint8_t version, uint64_t &earliest_height);
1297  bool use_fork_rules(uint8_t version, int64_t early_blocks = 0);
1298  int get_fee_algorithm();
1299 
1300  std::string get_wallet_file() const;
1301  std::string get_keys_file() const;
1302  std::string get_daemon_address() const;
1303  const boost::optional<epee::net_utils::http::login>& get_daemon_login() const { return m_daemon_login; }
1304  uint64_t get_daemon_blockchain_height(std::string& err);
1305  uint64_t get_daemon_blockchain_target_height(std::string& err);
1306  uint64_t get_daemon_adjusted_time();
1307 
1311  uint64_t get_approximate_blockchain_height() const;
1312  uint64_t estimate_blockchain_height();
1313  std::vector<size_t> select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool allow_rct);
1314  std::vector<size_t> select_available_outputs(const std::function<bool(const transfer_details &td)> &f);
1315  std::vector<size_t> select_available_unmixable_outputs();
1316  std::vector<size_t> select_available_mixable_outputs();
1317 
1318  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;
1319  size_t pop_best_value(std::vector<size_t> &unused_dust_indices, const std::vector<size_t>& selected_transfers, bool smallest = false) const;
1320 
1321  void set_tx_note(const crypto::hash &txid, const std::string &note);
1322  std::string get_tx_note(const crypto::hash &txid) const;
1323 
1324  void set_tx_device_aux(const crypto::hash &txid, const std::string &aux);
1325  std::string get_tx_device_aux(const crypto::hash &txid) const;
1326 
1327  void set_description(const std::string &description);
1328  std::string get_description() const;
1329 
1334  const std::pair<serializable_map<std::string, std::string>, std::vector<std::string>>& get_account_tags();
1340  void set_account_tag(const std::set<uint32_t> &account_indices, const std::string& tag);
1346  void set_account_tag_description(const std::string& tag, const std::string& description);
1347 
1348  enum message_signature_type_t { sign_with_spend_key, sign_with_view_key };
1349  std::string sign(const std::string &data, message_signature_type_t signature_type, cryptonote::subaddress_index index = {0, 0}) const;
1350  struct message_signature_result_t { bool valid; unsigned version; bool old; message_signature_type_t type; };
1351  message_signature_result_t verify(const std::string &data, const cryptonote::account_public_address &address, const std::string &signature) const;
1352 
1359  std::string sign_multisig_participant(const std::string& data) const;
1367  bool verify_with_public_key(const std::string &data, const crypto::public_key &public_key, const std::string &signature) const;
1368 
1369  // Import/Export wallet data
1370  std::pair<size_t, std::vector<tools::wallet2::transfer_details>> export_outputs(bool all = false) const;
1371  std::string export_outputs_to_str(bool all = false) const;
1372  size_t import_outputs(const std::pair<size_t, std::vector<tools::wallet2::transfer_details>> &outputs);
1373  size_t import_outputs_from_str(const std::string &outputs_st);
1374  payment_container export_payments() const;
1375  void import_payments(const payment_container &payments);
1376  void import_payments_out(const std::list<std::pair<crypto::hash,wallet2::confirmed_transfer_details>> &confirmed_payments);
1377  std::tuple<size_t, crypto::hash, std::vector<crypto::hash>> export_blockchain() const;
1378  void import_blockchain(const std::tuple<size_t, crypto::hash, std::vector<crypto::hash>> &bc);
1379  bool export_key_images(const std::string &filename, bool all = false) const;
1380  std::pair<size_t, std::vector<std::pair<crypto::key_image, crypto::signature>>> export_key_images(bool all = false) const;
1381  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);
1382  uint64_t import_key_images(const std::string &filename, uint64_t &spent, uint64_t &unspent);
1383  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);
1384  bool import_key_images(signed_tx_set & signed_tx, size_t offset=0, bool only_selected_transfers=false);
1385  crypto::public_key get_tx_pub_key_from_received_outs(const tools::wallet2::transfer_details &td) const;
1386 
1387  void update_pool_state(std::vector<std::tuple<cryptonote::transaction, crypto::hash, bool>> &process_txs, bool refreshed = false);
1388  void process_pool_state(const std::vector<std::tuple<cryptonote::transaction, crypto::hash, bool>> &txs);
1389  void remove_obsolete_pool_txs(const std::vector<crypto::hash> &tx_hashes);
1390 
1391  std::string encrypt(const char *plaintext, size_t len, const crypto::secret_key &skey, bool authenticated = true) const;
1392  std::string encrypt(const epee::span<char> &span, const crypto::secret_key &skey, bool authenticated = true) const;
1393  std::string encrypt(const std::string &plaintext, const crypto::secret_key &skey, bool authenticated = true) const;
1394  std::string encrypt(const epee::wipeable_string &plaintext, const crypto::secret_key &skey, bool authenticated = true) const;
1395  std::string encrypt_with_view_secret_key(const std::string &plaintext, bool authenticated = true) const;
1396  template<typename T=std::string> T decrypt(const std::string &ciphertext, const crypto::secret_key &skey, bool authenticated = true) const;
1397  std::string decrypt_with_view_secret_key(const std::string &ciphertext, bool authenticated = true) const;
1398 
1399  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;
1400  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);
1401 
1402  uint64_t get_blockchain_height_by_date(uint16_t year, uint8_t month, uint8_t day); // 1<=month<=12, 1<=day<=31
1403 
1404  bool is_synced();
1405 
1406  std::vector<std::pair<uint64_t, uint64_t>> estimate_backlog(const std::vector<std::pair<double, double>> &fee_levels);
1407  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);
1408 
1409  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, uint64_t base_fee, uint64_t fee_multiplier, uint64_t fee_quantization_mask) const;
1410  uint64_t get_fee_multiplier(uint32_t priority, int fee_algorithm = -1);
1411  uint64_t get_base_fee();
1412  uint64_t get_fee_quantization_mask();
1413  uint64_t get_min_ring_size();
1414  uint64_t get_max_ring_size();
1415  uint64_t adjust_mixin(uint64_t mixin);
1416 
1417  uint32_t adjust_priority(uint32_t priority);
1418 
1419  bool is_unattended() const { return m_unattended; }
1420 
1421  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);
1422 
1423  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);
1424  bool daemon_requires_payment();
1425  bool make_rpc_payment(uint32_t nonce, uint32_t cookie, uint64_t &credits, uint64_t &balance);
1426  bool search_for_rpc_payment(uint64_t credits_target, const std::function<bool(uint64_t, uint64_t)> &startfunc, const std::function<bool(unsigned)> &contfunc, const std::function<bool(uint64_t)> &foundfunc = NULL, const std::function<void(const std::string&)> &errorfunc = NULL);
1427  template<typename T> void handle_payment_changes(const T &res, std::true_type) {
1428  if (res.status == CORE_RPC_STATUS_OK || res.status == CORE_RPC_STATUS_PAYMENT_REQUIRED)
1429  m_rpc_payment_state.credits = res.credits;
1430  if (res.top_hash != m_rpc_payment_state.top_hash)
1431  {
1432  m_rpc_payment_state.top_hash = res.top_hash;
1433  m_rpc_payment_state.stale = true;
1434  }
1435  }
1436  template<typename T> void handle_payment_changes(const T &res, std::false_type) {}
1437 
1438  // Light wallet specific functions
1439  // fetch unspent outs from lw node and store in m_transfers
1440  void light_wallet_get_unspent_outs();
1441  // fetch txs and store in m_payments
1442  void light_wallet_get_address_txs();
1443  // get_address_info
1444  bool light_wallet_get_address_info(tools::COMMAND_RPC_GET_ADDRESS_INFO::response &response);
1445  // Login. new_address is true if address hasn't been used on lw node before.
1446  bool light_wallet_login(bool &new_address);
1447  // Send an import request to lw node. returns info about import fee, address and payment_id
1448  bool light_wallet_import_wallet_request(tools::COMMAND_RPC_IMPORT_WALLET_REQUEST::response &response);
1449  // get random outputs from light wallet server
1450  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);
1451  // Parse rct string
1452  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;
1453  // check if key image is ours
1454  bool light_wallet_key_image_is_ours(const crypto::key_image& key_image, const crypto::public_key& tx_public_key, uint64_t out_index);
1455 
1456  /*
1457  * "attributes" are a mechanism to store an arbitrary number of string values
1458  * on the level of the wallet as a whole, identified by keys. Their introduction,
1459  * technically the unordered map m_attributes stored as part of a wallet file,
1460  * led to a new wallet file version, but now new singular pieces of info may be added
1461  * without the need for a new version.
1462  *
1463  * The first and so far only value stored as such an attribute is the description.
1464  * It's stored under the standard key ATTRIBUTE_DESCRIPTION (see method set_description).
1465  *
1466  * The mechanism is open to all clients and allows them to use it for storing basically any
1467  * single string values in a wallet. To avoid the problem that different clients possibly
1468  * overwrite or misunderstand each other's attributes, a two-part key scheme is
1469  * proposed: <client name>.<value name>
1470  */
1471  const char* const ATTRIBUTE_DESCRIPTION = "wallet2.description";
1472  void set_attribute(const std::string &key, const std::string &value);
1473  bool get_attribute(const std::string &key, std::string &value) const;
1474 
1475  crypto::public_key get_multisig_signer_public_key(const crypto::secret_key &spend_skey) const;
1476  crypto::public_key get_multisig_signer_public_key() const;
1477  crypto::public_key get_multisig_signing_public_key(size_t idx) const;
1478  crypto::public_key get_multisig_signing_public_key(const crypto::secret_key &skey) const;
1479 
1480  template<class t_request, class t_response>
1481  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")
1482  {
1483  if (m_offline) return false;
1484  boost::lock_guard<boost::recursive_mutex> lock(m_daemon_rpc_mutex);
1485  return epee::net_utils::invoke_http_json(uri, req, res, *m_http_client, timeout, http_method);
1486  }
1487  template<class t_request, class t_response>
1488  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")
1489  {
1490  if (m_offline) return false;
1491  boost::lock_guard<boost::recursive_mutex> lock(m_daemon_rpc_mutex);
1492  return epee::net_utils::invoke_http_bin(uri, req, res, *m_http_client, timeout, http_method);
1493  }
1494  template<class t_request, class t_response>
1495  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")
1496  {
1497  if (m_offline) return false;
1498  boost::lock_guard<boost::recursive_mutex> lock(m_daemon_rpc_mutex);
1499  return epee::net_utils::invoke_http_json_rpc(uri, method_name, req, res, *m_http_client, timeout, http_method, req_id);
1500  }
1501 
1502  bool set_ring_database(const std::string &filename);
1503  const std::string get_ring_database() const { return m_ring_database; }
1504  bool get_ring(const crypto::key_image &key_image, std::vector<uint64_t> &outs);
1505  bool get_rings(const crypto::hash &txid, std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> &outs);
1506  bool set_ring(const crypto::key_image &key_image, const std::vector<uint64_t> &outs, bool relative);
1507  bool unset_ring(const std::vector<crypto::key_image> &key_images);
1508  bool unset_ring(const crypto::hash &txid);
1509  bool find_and_save_rings(bool force = true);
1510 
1511  bool blackball_output(const std::pair<uint64_t, uint64_t> &output);
1512  bool set_blackballed_outputs(const std::vector<std::pair<uint64_t, uint64_t>> &outputs, bool add = false);
1513  bool unblackball_output(const std::pair<uint64_t, uint64_t> &output);
1514  bool is_output_blackballed(const std::pair<uint64_t, uint64_t> &output) const;
1515 
1516  void freeze(size_t idx);
1517  void thaw(size_t idx);
1518  bool frozen(size_t idx) const;
1519  void freeze(const crypto::key_image &ki);
1520  void thaw(const crypto::key_image &ki);
1521  bool frozen(const crypto::key_image &ki) const;
1522  bool frozen(const transfer_details &td) const;
1523 
1524  bool save_to_file(const std::string& path_to_file, const std::string& binary, bool is_printable = false) const;
1525  static bool load_from_file(const std::string& path_to_file, std::string& target_str, size_t max_size = 1000000000);
1526 
1527  uint64_t get_bytes_sent() const;
1528  uint64_t get_bytes_received() const;
1529 
1530  // MMS -------------------------------------------------------------------------------------------------
1531  mms::message_store& get_message_store() { return m_message_store; };
1532  const mms::message_store& get_message_store() const { return m_message_store; };
1533  mms::multisig_wallet_state get_multisig_wallet_state() const;
1534 
1535  bool lock_keys_file();
1536  bool unlock_keys_file();
1537  bool is_keys_file_locked() const;
1538 
1539  void change_password(const std::string &filename, const epee::wipeable_string &original_password, const epee::wipeable_string &new_password);
1540 
1541  void set_tx_notify(const std::shared_ptr<tools::Notify> &notify) { m_tx_notify = notify; }
1542 
1543  bool is_tx_spendtime_unlocked(uint64_t unlock_time, uint64_t block_height);
1544  void hash_m_transfer(const transfer_details & transfer, crypto::hash &hash) const;
1545  uint64_t hash_m_transfers(int64_t transfer_height, crypto::hash &hash) const;
1546  void finish_rescan_bc_keep_key_images(uint64_t transfer_height, const crypto::hash &hash);
1547  void enable_dns(bool enable) { m_use_dns = enable; }
1548  void set_offline(bool offline = true);
1549 
1550  uint64_t credits() const { return m_rpc_payment_state.credits; }
1551  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; }
1552 
1553  static std::string get_default_daemon_address() { CRITICAL_REGION_LOCAL(default_daemon_address_lock); return default_daemon_address; }
1554 
1555  private:
1563  bool store_keys(const std::string& keys_file_name, const epee::wipeable_string& password, bool watch_only = false);
1569  bool load_keys(const std::string& keys_file_name, const epee::wipeable_string& password);
1575  bool load_keys_buf(const std::string& keys_buf, const epee::wipeable_string& password);
1576  bool load_keys_buf(const std::string& keys_buf, const epee::wipeable_string& password, boost::optional<crypto::chacha_key>& keys_to_encrypt);
1577  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);
1578  bool should_skip_block(const cryptonote::block &b, uint64_t height) const;
1579  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);
1580  void detach_blockchain(uint64_t height, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL);
1581  void get_short_chain_history(std::list<crypto::hash>& ids, uint64_t granularity = 1) const;
1582  bool clear();
1583  void clear_soft(bool keep_key_images=false);
1584  void pull_blocks(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);
1585  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);
1586  void fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history, bool force = false);
1587  void pull_and_parse_next_blocks(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);
1588  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);
1589  uint64_t select_transfers(uint64_t needed_money, std::vector<size_t> unused_transfers_indices, std::vector<size_t>& selected_transfers) const;
1590  bool prepare_file_names(const std::string& file_path);
1591  void process_unconfirmed(const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t height);
1592  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);
1593  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);
1594  void generate_genesis(cryptonote::block& b) const;
1595  void check_genesis(const crypto::hash& genesis_hash) const; //throws
1596  bool generate_chacha_key_from_secret_keys(crypto::chacha_key &key) const;
1597  void generate_chacha_key_from_password(const epee::wipeable_string &pass, crypto::chacha_key &key) const;
1598  crypto::hash get_payment_id(const pending_tx &ptx) const;
1599  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;
1600  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;
1601  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;
1602  void parse_block_round(const cryptonote::blobdata &blob, cryptonote::block &bl, crypto::hash &bl_id, bool &error) const;
1603  uint64_t get_upper_transaction_weight_limit();
1604  std::vector<uint64_t> get_unspent_amounts_vector(bool strict);
1605  uint64_t get_dynamic_base_fee_estimate();
1606  float get_output_relatedness(const transfer_details &td0, const transfer_details &td1) const;
1607  std::vector<size_t> pick_preferred_rct_inputs(uint64_t needed_money, uint32_t subaddr_account, const std::set<uint32_t> &subaddr_indices);
1608  void set_spent(size_t idx, uint64_t height);
1609  void set_unspent(size_t idx);
1610  bool is_spent(const transfer_details &td, bool strict = true) const;
1611  bool is_spent(size_t idx, bool strict = true) const;
1612  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);
1613  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);
1614  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) const;
1615  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;
1616  std::vector<size_t> get_only_rct(const std::vector<size_t> &unused_dust_indices, const std::vector<size_t> &unused_transfers_indices) const;
1617  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);
1618  void trim_hashchain();
1619  crypto::key_image get_multisig_composite_key_image(size_t n) const;
1620  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;
1621  rct::multisig_kLRki get_multisig_kLRki(size_t n, const rct::key &k) const;
1622  rct::key get_multisig_k(size_t idx, const std::unordered_set<rct::key> &used_L) const;
1623  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);
1624  bool add_rings(const crypto::chacha_key &key, const cryptonote::transaction_prefix &tx);
1625  bool add_rings(const cryptonote::transaction_prefix &tx);
1626  bool remove_rings(const cryptonote::transaction_prefix &tx);
1627  bool get_ring(const crypto::chacha_key &key, const crypto::key_image &key_image, std::vector<uint64_t> &outs);
1628  crypto::chacha_key get_ringdb_key();
1629  void setup_keys(const epee::wipeable_string &password);
1630  size_t get_transfer_details(const crypto::key_image &ki) const;
1631 
1632  void register_devices();
1633  hw::device& lookup_device(const std::string & device_descriptor);
1634 
1635  bool get_rct_distribution(uint64_t &start_height, std::vector<uint64_t> &distribution);
1636 
1637  uint64_t get_segregation_fork_height() const;
1638  void unpack_multisig_info(const std::vector<std::string>& info,
1639  std::vector<crypto::public_key> &public_keys,
1640  std::vector<crypto::secret_key> &secret_keys) const;
1641  bool unpack_extra_multisig_info(const std::vector<std::string>& info,
1642  std::vector<crypto::public_key> &signers,
1643  std::unordered_set<crypto::public_key> &pkeys) const;
1644 
1645  void cache_tx_data(const cryptonote::transaction& tx, const crypto::hash &txid, tx_cache_data &tx_cache_data) const;
1646  std::shared_ptr<std::map<std::pair<uint64_t, uint64_t>, size_t>> create_output_tracker_cache() const;
1647 
1648  void init_type(hw::device::device_type device_type);
1649  void setup_new_blockchain();
1650  void create_keys_file(const std::string &wallet_, bool watch_only, const epee::wipeable_string &password, bool create_address_file);
1651 
1652  wallet_device_callback * get_device_callback();
1653  void on_device_button_request(uint64_t code);
1654  void on_device_button_pressed();
1655  boost::optional<epee::wipeable_string> on_device_pin_request();
1656  boost::optional<epee::wipeable_string> on_device_passphrase_request(bool & on_device);
1657  void on_device_progress(const hw::device_progress& event);
1658 
1659  std::string get_rpc_status(const std::string &s) const;
1660  void throw_on_rpc_response_error(bool r, const epee::json_rpc::error &error, const std::string &status, const char *method) const;
1661 
1662  std::string get_client_signature() const;
1663  void check_rpc_cost(const char *call, uint64_t post_call_credits, uint64_t pre_credits, double expected_cost);
1664 
1665  bool should_expand(const cryptonote::subaddress_index &index) const;
1666  bool spends_one_of_ours(const cryptonote::transaction &tx) const;
1667 
1669  boost::optional<epee::net_utils::http::login> m_daemon_login;
1670  std::string m_daemon_address;
1671  std::string m_wallet_file;
1672  std::string m_keys_file;
1673  std::string m_mms_file;
1674  const std::unique_ptr<epee::net_utils::http::abstract_http_client> m_http_client;
1682 
1689  std::vector<std::vector<std::string>> m_subaddress_labels;
1692  std::vector<tools::wallet2::address_book_row> m_address_book;
1693  std::pair<serializable_map<std::string, std::string>, std::vector<std::string>> m_account_tags;
1694  uint64_t m_upper_transaction_weight_limit; //TODO: auto-calc this value or request from daemon, now use some fixed value
1695  const std::vector<std::vector<tools::wallet2::multisig_info>> *m_multisig_rescan_info;
1696  const std::vector<std::vector<rct::key>> *m_multisig_rescan_k;
1698 
1699  std::atomic<bool> m_run;
1700 
1701  boost::recursive_mutex m_daemon_rpc_mutex;
1702 
1707  uint64_t m_kdf_rounds;
1708  std::string seed_language;
1711  bool m_multisig;
1713  std::vector<crypto::public_key> m_multisig_signers;
1714  //in case of general M/N multisig wallet we should perform N - M + 1 key exchange rounds and remember how many rounds are passed.
1716  std::vector<crypto::public_key> m_multisig_derivations;
1726  // If m_refresh_from_block_height is explicitly set to zero we need this to differentiate it from the case that
1727  // m_refresh_from_block_height was defaulted to zero.*/
1751  std::unordered_set<crypto::hash> m_scanned_pool_txs[2];
1752  size_t m_subaddress_lookahead_major, m_subaddress_lookahead_minor;
1753  std::string m_device_name;
1758  uint32_t m_rpc_version;
1762 
1763  // Aux transaction data from device
1765 
1766  // Light wallet
1767  bool m_light_wallet; /* sends view key to daemon for scanning */
1770  uint64_t m_light_wallet_per_kb_fee = FEE_PER_KB;
1774  // Light wallet info needed to populate m_payment requires 2 separate api calls (get_address_txs and get_unspent_outs)
1775  // We save the info from the first call in m_light_wallet_address_txs for easier lookup.
1776  std::unordered_map<crypto::hash, address_tx> m_light_wallet_address_txs;
1777  // store calculated key image for faster lookup
1779 
1780  std::string m_ring_database;
1782  std::unique_ptr<ringdb> m_ringdb;
1783  boost::optional<crypto::chacha_key> m_ringdb_key;
1784 
1786  std::unique_ptr<tools::file_locker> m_keys_file_locker;
1787 
1792 
1793  crypto::chacha_key m_cache_key;
1794  boost::optional<epee::wipeable_string> m_encrypt_keys_after_refresh;
1795  boost::mutex m_decrypt_keys_lock;
1797 
1800 
1801  std::shared_ptr<tools::Notify> m_tx_notify;
1802  std::unique_ptr<wallet_device_callback> m_device_callback;
1803 
1806 
1807  static boost::mutex default_daemon_address_lock;
1808  static std::string default_daemon_address;
1809  };
1810 }
1812 BOOST_CLASS_VERSION(tools::wallet2::transfer_details, 12)
1813 BOOST_CLASS_VERSION(tools::wallet2::multisig_info, 1)
1814 BOOST_CLASS_VERSION(tools::wallet2::multisig_info::LR, 0)
1815 BOOST_CLASS_VERSION(tools::wallet2::multisig_tx_set, 1)
1816 BOOST_CLASS_VERSION(tools::wallet2::payment_details, 5)
1817 BOOST_CLASS_VERSION(tools::wallet2::pool_payment_details, 1)
1818 BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 8)
1819 BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 6)
1820 BOOST_CLASS_VERSION(tools::wallet2::address_book_row, 18)
1821 BOOST_CLASS_VERSION(tools::wallet2::reserve_proof_entry, 0)
1823 BOOST_CLASS_VERSION(tools::wallet2::signed_tx_set, 1)
1825 BOOST_CLASS_VERSION(tools::wallet2::pending_tx, 3)
1826 BOOST_CLASS_VERSION(tools::wallet2::multisig_sig, 0)
1827 
1828 namespace boost
1829 {
1830  namespace serialization
1831  {
1832  template <class Archive>
1833  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)
1834  {
1835  }
1836  template <class Archive>
1837  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)
1838  {
1839  if (ver < 1)
1840  {
1841  x.m_mask = rct::identity();
1842  x.m_amount = x.m_tx.vout[x.m_internal_output_index].amount;
1843  }
1844  if (ver < 2)
1845  {
1846  x.m_spent_height = 0;
1847  }
1848  if (ver < 4)
1849  {
1850  x.m_rct = x.m_tx.vout[x.m_internal_output_index].amount == 0;
1851  }
1852  if (ver < 6)
1853  {
1854  x.m_key_image_known = true;
1855  }
1856  if (ver < 7)
1857  {
1858  x.m_pk_index = 0;
1859  }
1860  if (ver < 8)
1861  {
1862  x.m_subaddr_index = {};
1863  }
1864  if (ver < 9)
1865  {
1866  x.m_key_image_partial = false;
1867  x.m_multisig_k.clear();
1868  x.m_multisig_info.clear();
1869  }
1870  if (ver < 10)
1871  {
1872  x.m_key_image_request = false;
1873  }
1874  if (ver < 12)
1875  {
1876  x.m_frozen = false;
1877  }
1878  }
1879 
1880  template <class Archive>
1881  inline void serialize(Archive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
1882  {
1883  a & x.m_block_height;
1886  if (ver < 3)
1887  {
1889  a & tx;
1890  x.m_tx = (const cryptonote::transaction_prefix&)tx;
1892  }
1893  else
1894  {
1895  a & x.m_tx;
1896  }
1897  a & x.m_spent;
1898  a & x.m_key_image;
1899  if (ver < 1)
1900  {
1901  // ensure mask and amount are set
1902  initialize_transfer_details(a, x, ver);
1903  return;
1904  }
1905  a & x.m_mask;
1906  a & x.m_amount;
1907  if (ver < 2)
1908  {
1909  initialize_transfer_details(a, x, ver);
1910  return;
1911  }
1912  a & x.m_spent_height;
1913  if (ver < 3)
1914  {
1915  initialize_transfer_details(a, x, ver);
1916  return;
1917  }
1918  a & x.m_txid;
1919  if (ver < 4)
1920  {
1921  initialize_transfer_details(a, x, ver);
1922  return;
1923  }
1924  a & x.m_rct;
1925  if (ver < 5)
1926  {
1927  initialize_transfer_details(a, x, ver);
1928  return;
1929  }
1930  if (ver < 6)
1931  {
1932  // v5 did not properly initialize
1933  uint8_t u;
1934  a & u;
1935  x.m_key_image_known = true;
1936  return;
1937  }
1938  a & x.m_key_image_known;
1939  if (ver < 7)
1940  {
1941  initialize_transfer_details(a, x, ver);
1942  return;
1943  }
1944  a & x.m_pk_index;
1945  if (ver < 8)
1946  {
1947  initialize_transfer_details(a, x, ver);
1948  return;
1949  }
1950  a & x.m_subaddr_index;
1951  if (ver < 9)
1952  {
1953  initialize_transfer_details(a, x, ver);
1954  return;
1955  }
1956  a & x.m_multisig_info;
1957  a & x.m_multisig_k;
1958  a & x.m_key_image_partial;
1959  if (ver < 10)
1960  {
1961  initialize_transfer_details(a, x, ver);
1962  return;
1963  }
1964  a & x.m_key_image_request;
1965  if (ver < 11)
1966  {
1967  initialize_transfer_details(a, x, ver);
1968  return;
1969  }
1970  a & x.m_uses;
1971  if (ver < 12)
1972  {
1973  initialize_transfer_details(a, x, ver);
1974  return;
1975  }
1976  a & x.m_frozen;
1977  }
1978 
1979  template <class Archive>
1980  inline void serialize(Archive &a, tools::wallet2::multisig_info::LR &x, const boost::serialization::version_type ver)
1981  {
1982  a & x.m_L;
1983  a & x.m_R;
1984  }
1985 
1986  template <class Archive>
1987  inline void serialize(Archive &a, tools::wallet2::multisig_info &x, const boost::serialization::version_type ver)
1988  {
1989  a & x.m_signer;
1990  a & x.m_LR;
1991  a & x.m_partial_key_images;
1992  }
1993 
1994  template <class Archive>
1995  inline void serialize(Archive &a, tools::wallet2::multisig_tx_set &x, const boost::serialization::version_type ver)
1996  {
1997  a & x.m_ptx;
1998  a & x.m_signers;
1999  }
2000 
2001  template <class Archive>
2002  inline void serialize(Archive &a, tools::wallet2::unconfirmed_transfer_details &x, const boost::serialization::version_type ver)
2003  {
2004  a & x.m_change;
2005  a & x.m_sent_time;
2006  if (ver < 5)
2007  {
2009  a & tx;
2010  x.m_tx = (const cryptonote::transaction_prefix&)tx;
2011  }
2012  else
2013  {
2014  a & x.m_tx;
2015  }
2016  if (ver < 1)
2017  return;
2018  a & x.m_dests;
2019  a & x.m_payment_id;
2020  if (ver < 2)
2021  return;
2022  a & x.m_state;
2023  if (ver < 3)
2024  return;
2025  a & x.m_timestamp;
2026  if (ver < 4)
2027  return;
2028  a & x.m_amount_in;
2029  a & x.m_amount_out;
2030  if (ver < 6)
2031  {
2032  // v<6 may not have change accumulated in m_amount_out, which is a pain,
2033  // as it's readily understood to be sum of outputs.
2034  // We convert it to include change from v6
2035  if (!typename Archive::is_saving() && x.m_change != (uint64_t)-1)
2036  x.m_amount_out += x.m_change;
2037  }
2038  if (ver < 7)
2039  {
2040  x.m_subaddr_account = 0;
2041  return;
2042  }
2043  a & x.m_subaddr_account;
2044  a & x.m_subaddr_indices;
2045  if (ver < 8)
2046  return;
2047  a & x.m_rings;
2048  }
2049 
2050  template <class Archive>
2051  inline void serialize(Archive &a, tools::wallet2::confirmed_transfer_details &x, const boost::serialization::version_type ver)
2052  {
2053  a & x.m_amount_in;
2054  a & x.m_amount_out;
2055  a & x.m_change;
2056  a & x.m_block_height;
2057  if (ver < 1)
2058  return;
2059  a & x.m_dests;
2060  a & x.m_payment_id;
2061  if (ver < 2)
2062  return;
2063  a & x.m_timestamp;
2064  if (ver < 3)
2065  {
2066  // v<3 may not have change accumulated in m_amount_out, which is a pain,
2067  // as it's readily understood to be sum of outputs. Whether it got added
2068  // or not depends on whether it came from a unconfirmed_transfer_details
2069  // (not included) or not (included). We can't reliably tell here, so we
2070  // check whether either yields a "negative" fee, or use the other if so.
2071  // We convert it to include change from v3
2072  if (!typename Archive::is_saving() && x.m_change != (uint64_t)-1)
2073  {
2074  if (x.m_amount_in > (x.m_amount_out + x.m_change))
2075  x.m_amount_out += x.m_change;
2076  }
2077  }
2078  if (ver < 4)
2079  {
2080  if (!typename Archive::is_saving())
2081  x.m_unlock_time = 0;
2082  return;
2083  }
2084  a & x.m_unlock_time;
2085  if (ver < 5)
2086  {
2087  x.m_subaddr_account = 0;
2088  return;
2089  }
2090  a & x.m_subaddr_account;
2091  a & x.m_subaddr_indices;
2092  if (ver < 6)
2093  return;
2094  a & x.m_rings;
2095  }
2096 
2097  template <class Archive>
2098  inline void serialize(Archive& a, tools::wallet2::payment_details& x, const boost::serialization::version_type ver)
2099  {
2100  a & x.m_tx_hash;
2101  a & x.m_amount;
2102  a & x.m_block_height;
2103  a & x.m_unlock_time;
2104  if (ver < 1)
2105  return;
2106  a & x.m_timestamp;
2107  if (ver < 2)
2108  {
2109  x.m_coinbase = false;
2110  x.m_subaddr_index = {};
2111  return;
2112  }
2113  a & x.m_subaddr_index;
2114  if (ver < 3)
2115  {
2116  x.m_coinbase = false;
2117  x.m_fee = 0;
2118  return;
2119  }
2120  a & x.m_fee;
2121  if (ver < 4)
2122  {
2123  x.m_coinbase = false;
2124  return;
2125  }
2126  a & x.m_coinbase;
2127  if (ver < 5)
2128  return;
2129  a & x.m_amounts;
2130  }
2131 
2132  template <class Archive>
2133  inline void serialize(Archive& a, tools::wallet2::pool_payment_details& x, const boost::serialization::version_type ver)
2134  {
2135  a & x.m_pd;
2136  a & x.m_double_spend_seen;
2137  }
2138 
2139  template <class Archive>
2140  inline void serialize(Archive& a, tools::wallet2::address_book_row& x, const boost::serialization::version_type ver)
2141  {
2142  a & x.m_address;
2143  if (ver < 18)
2144  {
2145  crypto::hash payment_id;
2146  a & payment_id;
2147  x.m_has_payment_id = !(payment_id == crypto::null_hash);
2148  if (x.m_has_payment_id)
2149  {
2150  bool is_long = false;
2151  for (int i = 8; i < 32; ++i)
2152  is_long |= payment_id.data[i];
2153  if (is_long)
2154  {
2155  MWARNING("Long payment ID ignored on address book load");
2157  x.m_has_payment_id = false;
2158  }
2159  else
2160  memcpy(x.m_payment_id.data, payment_id.data, 8);
2161  }
2162  }
2163  a & x.m_description;
2164  if (ver < 17)
2165  {
2166  x.m_is_subaddress = false;
2167  return;
2168  }
2169  a & x.m_is_subaddress;
2170  if (ver < 18)
2171  return;
2172  a & x.m_has_payment_id;
2173  if (x.m_has_payment_id)
2174  a & x.m_payment_id;
2175  }
2176 
2177  template <class Archive>
2178  inline void serialize(Archive& a, tools::wallet2::reserve_proof_entry& x, const boost::serialization::version_type ver)
2179  {
2180  a & x.txid;
2181  a & x.index_in_tx;
2182  a & x.shared_secret;
2183  a & x.key_image;
2184  a & x.shared_secret_sig;
2185  a & x.key_image_sig;
2186  }
2187 
2188  template <class Archive>
2189  inline void serialize(Archive &a, tools::wallet2::unsigned_tx_set &x, const boost::serialization::version_type ver)
2190  {
2191  a & x.txes;
2192  a & x.transfers;
2193  }
2194 
2195  template <class Archive>
2196  inline void serialize(Archive &a, tools::wallet2::signed_tx_set &x, const boost::serialization::version_type ver)
2197  {
2198  a & x.ptx;
2199  a & x.key_images;
2200  if (ver < 1)
2201  return;
2202  a & x.tx_key_images.parent();
2203  }
2204 
2205  template <class Archive>
2206  inline void serialize(Archive &a, tools::wallet2::tx_construction_data &x, const boost::serialization::version_type ver)
2207  {
2208  a & x.sources;
2209  a & x.change_dts;
2210  a & x.splitted_dsts;
2211  if (ver < 2)
2212  {
2213  // load list to vector
2214  std::list<size_t> selected_transfers;
2215  a & selected_transfers;
2216  x.selected_transfers.clear();
2217  x.selected_transfers.reserve(selected_transfers.size());
2218  for (size_t t: selected_transfers)
2219  x.selected_transfers.push_back(t);
2220  }
2221  a & x.extra;
2222  a & x.unlock_time;
2223  a & x.use_rct;
2224  a & x.dests;
2225  if (ver < 1)
2226  {
2227  x.subaddr_account = 0;
2228  return;
2229  }
2230  a & x.subaddr_account;
2231  a & x.subaddr_indices;
2232  if (ver < 2)
2233  {
2234  if (!typename Archive::is_saving())
2236  return;
2237  }
2238  a & x.selected_transfers;
2239  if (ver < 3)
2240  {
2241  if (!typename Archive::is_saving())
2243  return;
2244  }
2245  if (ver < 4)
2246  {
2247  bool use_bulletproofs = x.rct_config.range_proof_type != rct::RangeProofBorromean;
2248  a & use_bulletproofs;
2249  if (!typename Archive::is_saving())
2250  x.rct_config = { use_bulletproofs ? rct::RangeProofBulletproof : rct::RangeProofBorromean, 0 };
2251  return;
2252  }
2253  a & x.rct_config;
2254  }
2255 
2256  template <class Archive>
2257  inline void serialize(Archive &a, tools::wallet2::multisig_sig &x, const boost::serialization::version_type ver)
2258  {
2259  a & x.sigs;
2260  a & x.ignore;
2261  a & x.used_L;
2262  a & x.signing_keys;
2263  a & x.msout;
2264  }
2265 
2266  template <class Archive>
2267  inline void serialize(Archive &a, tools::wallet2::pending_tx &x, const boost::serialization::version_type ver)
2268  {
2269  a & x.tx;
2270  a & x.dust;
2271  a & x.fee;
2272  a & x.dust_added_to_fee;
2273  a & x.change_dts;
2274  if (ver < 2)
2275  {
2276  // load list to vector
2277  std::list<size_t> selected_transfers;
2278  a & selected_transfers;
2279  x.selected_transfers.clear();
2280  x.selected_transfers.reserve(selected_transfers.size());
2281  for (size_t t: selected_transfers)
2282  x.selected_transfers.push_back(t);
2283  }
2284  a & x.key_images;
2285  a & x.tx_key;
2286  a & x.dests;
2287  a & x.construction_data;
2288  if (ver < 1)
2289  return;
2290  a & x.additional_tx_keys;
2291  if (ver < 2)
2292  return;
2293  a & x.selected_transfers;
2294  if (ver < 3)
2295  return;
2296  a & x.multisig_sigs;
2297  }
2298  }
2299 }
2300 
2301 namespace tools
2302 {
2303 
2304  namespace detail
2305  {
2306  //----------------------------------------------------------------------------------------------------
2307  inline void digit_split_strategy(const std::vector<cryptonote::tx_destination_entry>& dsts,
2308  const cryptonote::tx_destination_entry& change_dst, uint64_t dust_threshold,
2309  std::vector<cryptonote::tx_destination_entry>& splitted_dsts, std::vector<cryptonote::tx_destination_entry> &dust_dsts)
2310  {
2311  splitted_dsts.clear();
2312  dust_dsts.clear();
2313 
2314  for(auto& de: dsts)
2315  {
2317  [&](uint64_t chunk) { splitted_dsts.push_back(cryptonote::tx_destination_entry(chunk, de.addr, de.is_subaddress)); },
2318  [&](uint64_t a_dust) { splitted_dsts.push_back(cryptonote::tx_destination_entry(a_dust, de.addr, de.is_subaddress)); } );
2319  }
2320 
2322  [&](uint64_t chunk) {
2323  if (chunk <= dust_threshold)
2324  dust_dsts.push_back(cryptonote::tx_destination_entry(chunk, change_dst.addr, false));
2325  else
2326  splitted_dsts.push_back(cryptonote::tx_destination_entry(chunk, change_dst.addr, false));
2327  },
2328  [&](uint64_t a_dust) { dust_dsts.push_back(cryptonote::tx_destination_entry(a_dust, change_dst.addr, false)); } );
2329  }
2330  //----------------------------------------------------------------------------------------------------
2331  inline void null_split_strategy(const std::vector<cryptonote::tx_destination_entry>& dsts,
2332  const cryptonote::tx_destination_entry& change_dst, uint64_t dust_threshold,
2333  std::vector<cryptonote::tx_destination_entry>& splitted_dsts, std::vector<cryptonote::tx_destination_entry> &dust_dsts)
2334  {
2335  splitted_dsts = dsts;
2336 
2337  dust_dsts.clear();
2338  uint64_t change = change_dst.amount;
2339 
2340  if (0 != change)
2341  {
2342  splitted_dsts.push_back(cryptonote::tx_destination_entry(change, change_dst.addr, false));
2343  }
2344  }
2345  //----------------------------------------------------------------------------------------------------
2347  {
2348  std::string indexes;
2349  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) + " "; });
2350  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);
2351  }
2352  //----------------------------------------------------------------------------------------------------
2353  }
2354  //----------------------------------------------------------------------------------------------------
2355 }
#define s(x, c)
Definition: aesb.c:47
static void init(std::string cache_filename)
Definition: blockchain_blackball.cpp:221
Definition: account.h:76
A container for blockchain checkpoints.
Definition: checkpoints.h:53
Definition: cryptonote_basic.h:160
std::vector< tx_out > vout
Definition: cryptonote_basic.h:168
Definition: cryptonote_basic.h:194
Definition: device.hpp:71
Definition: device.hpp:87
device_type
Definition: device.hpp:105
Definition: device.hpp:77
Definition: message_store.h:267
Definition: http.h:45
std::unordered_map< K, V > & parent()
Definition: containers.h:52
Definition: containers.h:71
Definition: node_rpc_proxy.h:42
Definition: wallet2.h:98
const std::vector< uint64_t > & rct_offsets
Definition: wallet2.h:115
uint64_t num_rct_outputs
Definition: wallet2.h:117
double average_output_time
Definition: wallet2.h:118
const uint64_t * end
Definition: wallet2.h:116
std::gamma_distribution< double > gamma
Definition: wallet2.h:114
struct tools::gamma_picker::gamma_engine engine
const uint64_t * begin
Definition: wallet2.h:116
gamma_picker(const std::vector< uint64_t > &rct_offsets)
Definition: wallet2.cpp:1028
uint64_t pick()
Definition: wallet2.cpp:1030
Definition: wallet2.h:189
void crop(size_t height)
Definition: wallet2.h:200
void clear()
Definition: wallet2.h:201
bool is_in_bounds(size_t idx) const
Definition: wallet2.h:197
size_t offset() const
Definition: wallet2.h:194
crypto::hash & operator[](size_t idx)
Definition: wallet2.h:199
size_t m_offset
Definition: wallet2.h:222
void trim(size_t height)
Definition: wallet2.h:203
const crypto::hash & operator[](size_t idx) const
Definition: wallet2.h:198
void push_back(const crypto::hash &hash)
Definition: wallet2.h:196
bool empty() const
Definition: wallet2.h:202
hashchain()
Definition: wallet2.h:191
void serialize(t_archive &a, const unsigned int ver)
Definition: wallet2.h:207
void refill(const crypto::hash &hash)
Definition: wallet2.h:204
crypto::hash m_genesis
Definition: wallet2.h:223
const crypto::hash & genesis() const
Definition: wallet2.h:195
std::deque< crypto::hash > m_blockchain
Definition: wallet2.h:224
size_t size() const
Definition: wallet2.h:193
Definition: wallet2.h:136
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)
Definition: wallet2.h:142
virtual void on_device_button_pressed()
Definition: wallet2.h:152
virtual boost::optional< epee::wipeable_string > on_get_password(const char *reason)
Definition: wallet2.h:144
virtual void on_pool_tx_removed(const crypto::hash &txid)
Definition: wallet2.h:157
virtual void on_lw_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount)
Definition: wallet2.h:148
virtual void on_device_button_request(uint64_t code)
Definition: wallet2.h:151
virtual void on_lw_money_spent(uint64_t height, const crypto::hash &txid, uint64_t amount)
Definition: wallet2.h:149
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)
Definition: wallet2.h:141
virtual void on_new_block(uint64_t height, const cryptonote::block &block)
Definition: wallet2.h:139
virtual ~i_wallet2_callback()
Definition: wallet2.h:158
virtual boost::optional< epee::wipeable_string > on_device_passphrase_request(bool &on_device)
Definition: wallet2.h:154
virtual boost::optional< epee::wipeable_string > on_device_pin_request()
Definition: wallet2.h:153
virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction &tx)
Definition: wallet2.h:143
virtual void on_lw_money_received(uint64_t height, const crypto::hash &txid, uint64_t amount)
Definition: wallet2.h:147
virtual void on_lw_new_block(uint64_t height)
Definition: wallet2.h:146
virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction &tx, uint64_t amount, const cryptonote::subaddress_index &subaddr_index, bool is_change, uint64_t unlock_time)
Definition: wallet2.h:140
virtual void on_device_progress(const hw::device_progress &event)
Definition: wallet2.h:155
Definition: password.h:41
Definition: wallet2.h:229
uint64_t m_segregation_height
Definition: wallet2.h:1740
transfer_container m_transfers
Definition: wallet2.h:1683
bool m_confirm_non_default_ring_size
Definition: wallet2.h:1729
BackgroundMiningSetupType m_setup_background_mining
Definition: wallet2.h:1746
cryptonote::account_base m_account
Definition: wallet2.h:1668
void load_deprecated_formats(bool load)
Definition: wallet2.h:1240
NodeRPCProxy m_node_rpc_proxy
Definition: wallet2.h:1750
uint32_t get_confirm_backlog_threshold() const
Definition: wallet2.h:1208
bool segregate_pre_fork_outputs() const
Definition: wallet2.h:1213
void auto_mine_for_rpc_payment_threshold(float threshold)
Definition: wallet2.h:1243
void auto_refresh(bool r)
Definition: wallet2.h:1196
void key_reuse_mitigation2(bool value)
Definition: wallet2.h:1216
void ignore_outputs_below(uint64_t value)
Definition: wallet2.h:1226
bool m_merge_destinations
Definition: wallet2.h:1733
bool is_unattended() const
Definition: wallet2.h:1419
const std::vector< std::vector< rct::key > > * m_multisig_rescan_k
Definition: wallet2.h:1696
bool m_explicit_refresh_from_block_height
Definition: wallet2.h:1728
bool watch_only() const
Definition: wallet2.h:933
boost::optional< epee::net_utils::http::login > m_daemon_login
Definition: wallet2.h:1669
std::string m_device_derivation_path
Definition: wallet2.h:1754
boost::optional< crypto::chacha_key > m_ringdb_key
Definition: wallet2.h:1783
void set_rpc_client_secret_key(const crypto::secret_key &key)
Definition: wallet2.h:1246
void set_trusted_daemon(bool trusted)
Definition: wallet2.h:876
bool m_confirm_backlog
Definition: wallet2.h:1734
bool merge_destinations() const
Definition: wallet2.h:1204
void always_confirm_transfers(bool always)
Definition: wallet2.h:1186
void inactivity_lock_timeout(uint32_t seconds)
Definition: wallet2.h:1232
bool load_deprecated_formats() const
Definition: wallet2.h:1239
const std::vector< std::vector< tools::wallet2::multisig_info > > * m_multisig_rescan_info
Definition: wallet2.h:1695
boost::mutex m_decrypt_keys_lock
Definition: wallet2.h:1795
bool m_original_keys_available
Definition: wallet2.h:1789
void default_mixin(uint32_t m)
Definition: wallet2.h:1192
serializable_unordered_map< std::string, std::string > m_attributes
Definition: wallet2.h:1691
hw::device::device_type m_key_device_type
Definition: wallet2.h:1705
uint64_t m_last_block_reward
Definition: wallet2.h:1785
void track_uses(bool value)
Definition: wallet2.h:1228
void set_default_priority(uint32_t p)
Definition: wallet2.h:1194
std::string seed_language
Definition: wallet2.h:1708
bool m_ignore_fractional_outputs
Definition: wallet2.h:1741
bool m_print_ring_members
Definition: wallet2.h:1718
void enable_dns(bool enable)
Definition: wallet2.h:1547
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")
Definition: wallet2.h:1481
const std::string & device_derivation_path() const
Definition: wallet2.h:1235
void callback(i_wallet2_callback *callback)
Definition: wallet2.h:873
serializable_unordered_map< crypto::public_key, size_t > m_pub_keys
Definition: wallet2.h:1686
void merge_destinations(bool merge)
Definition: wallet2.h:1203
uint32_t m_multisig_rounds_passed
Definition: wallet2.h:1715
void set_tx_notify(const std::shared_ptr< tools::Notify > &notify)
Definition: wallet2.h:1541
std::vector< tools::wallet2::address_book_row > m_address_book
Definition: wallet2.h:1692
i_wallet2_callback * callback() const
Definition: wallet2.h:872
std::pair< size_t, size_t > get_subaddress_lookahead() const
Definition: wallet2.h:919
bool m_load_deprecated_formats
Definition: wallet2.h:1805
bool m_track_uses
Definition: wallet2.h:1744
uint64_t m_light_wallet_unlocked_balance
Definition: wallet2.h:1773
bool m_key_reuse_mitigation2
Definition: wallet2.h:1739
uint32_t m_multisig_threshold
Definition: wallet2.h:1712
std::atomic< bool > m_run
Definition: wallet2.h:1699
uint64_t get_min_output_value() const
Definition: wallet2.h:1202
uint32_t m_min_output_count
Definition: wallet2.h:1731
void explicit_refresh_from_block_height(bool expl)
Definition: wallet2.h:855
serializable_unordered_map< crypto::public_key, serializable_map< uint64_t, crypto::key_image > > m_key_image_cache
Definition: wallet2.h:1778
uint64_t segregation_height() const
Definition: wallet2.h:1217
uint64_t m_ignore_outputs_above
Definition: wallet2.h:1742
bool ignore_fractional_outputs() const
Definition: wallet2.h:1219
message_signature_type_t
Definition: wallet2.h:1348
void set_export_format(const ExportFormat &export_format)
Definition: wallet2.h:1238
uint64_t m_device_last_key_image_sync
Definition: wallet2.h:1755
std::pair< serializable_map< std::string, std::string >, std::vector< std::string > > m_account_tags
Definition: wallet2.h:1693
void ask_password(AskPasswordType ask)
Definition: wallet2.h:1198
bool m_unattended
Definition: wallet2.h:1798
BackgroundMiningSetupType setup_background_mining() const
Definition: wallet2.h:1229
serializable_unordered_map< crypto::hash, std::vector< crypto::secret_key > > m_additional_tx_keys
Definition: wallet2.h:1681
crypto::secret_key m_original_view_secret_key
Definition: wallet2.h:1791
uint64_t m_ignore_outputs_below
Definition: wallet2.h:1743
serializable_unordered_map< crypto::hash, crypto::secret_key > m_tx_keys
Definition: wallet2.h:1679
std::tuple< uint64_t, crypto::public_key, rct::key > get_outs_entry
Definition: wallet2.h:672
std::string m_daemon_address
Definition: wallet2.h:1670
size_t get_num_subaddress_accounts() const
Definition: wallet2.h:911
std::string m_wallet_file
Definition: wallet2.h:1671
payment_container m_payments
Definition: wallet2.h:1684
serializable_unordered_map< crypto::hash, std::string > m_tx_notes
Definition: wallet2.h:1690
hashchain m_blockchain
Definition: wallet2.h:1675
void device_name(const std::string &device_name)
Definition: wallet2.h:1234
void ignore_outputs_above(uint64_t value)
Definition: wallet2.h:1224
bool confirm_backlog() const
Definition: wallet2.h:1205
bool m_segregate_pre_fork_outputs
Definition: wallet2.h:1738
static std::string get_default_daemon_address()
Definition: wallet2.h:1553
AskPasswordType
Definition: wallet2.h:244
void set_min_output_count(uint32_t count)
Definition: wallet2.h:1199
void setup_background_mining(BackgroundMiningSetupType value)
Definition: wallet2.h:1230
uint64_t m_credits_target
Definition: wallet2.h:1761
std::string m_device_name
Definition: wallet2.h:1753
bool confirm_non_default_ring_size() const
Definition: wallet2.h:1221
void transfer_selected(const std::vector< cryptonote::tx_destination_entry > &dsts, const std::vector< size_t > &selected_transfers, size_t fake_outputs_count, std::vector< std::vector< tools::wallet2::get_outs_entry >> &outs, uint64_t unlock_time, 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)
std::vector< std::vector< std::string > > m_subaddress_labels
Definition: wallet2.h:1689
void set_light_wallet(bool light_wallet)
Definition: wallet2.h:888
static std::string default_daemon_address
Definition: wallet2.h:1808
size_t get_num_transfer_details() const
Definition: wallet2.h:1292
uint64_t ignore_outputs_above() const
Definition: wallet2.h:1223
bool m_light_wallet_connected
Definition: wallet2.h:1771
std::vector< address_book_row > get_address_book() const
GUI Address book get/store.
Definition: wallet2.h:1286
const mms::message_store & get_message_store() const
Definition: wallet2.h:1532
cryptonote::account_public_address m_original_address
Definition: wallet2.h:1790
void set_refresh_from_block_height(uint64_t height)
Definition: wallet2.h:852
bool persistent_rpc_client_id() const
Definition: wallet2.h:1241
bool print_ring_members() const
Definition: wallet2.h:1187
cryptonote::account_public_address m_account_public_address
Definition: wallet2.h:1687
uint64_t m_kdf_rounds
Definition: wallet2.h:1707
crypto::secret_key m_rpc_client_secret_key
Definition: wallet2.h:1759
std::shared_ptr< tools::Notify > m_tx_notify
Definition: wallet2.h:1801
void handle_payment_changes(const T &res, std::true_type)
Definition: wallet2.h:1427
AskPasswordType ask_password() const
Definition: wallet2.h:1197
uint64_t m_light_wallet_scanned_block_height
Definition: wallet2.h:1768
uint64_t m_light_wallet_blockchain_height
Definition: wallet2.h:1769
void device_derivation_path(const std::string &device_derivation_path)
Definition: wallet2.h:1236
std::vector< transfer_details > transfer_container
Definition: wallet2.h:517
void confirm_non_default_ring_size(bool always)
Definition: wallet2.h:1222
uint64_t get_light_wallet_blockchain_height() const
Definition: wallet2.h:890
bool m_is_initialized
Definition: wallet2.h:1749
bool track_uses() const
Definition: wallet2.h:1227
std::string m_ring_database
Definition: wallet2.h:1780
boost::recursive_mutex m_daemon_rpc_mutex
Definition: wallet2.h:1701
bool is_old_file_format
Definition: wallet2.h:1709
void credits_target(uint64_t threshold)
Definition: wallet2.h:1248
bool m_multisig
Definition: wallet2.h:1711
std::unique_ptr< tools::file_locker > m_keys_file_locker
Definition: wallet2.h:1786
std::unique_ptr< ringdb > m_ringdb
Definition: wallet2.h:1782
uint64_t get_last_block_reward() const
Definition: wallet2.h:1011
RefreshType
Definition: wallet2.h:237
@ RefreshFull
Definition: wallet2.h:238
@ RefreshOptimizeCoinbase
Definition: wallet2.h:239
@ RefreshNoCoinbase
Definition: wallet2.h:240
const std::string & device_name() const
Definition: wallet2.h:1233
cryptonote::checkpoints m_checkpoints
Definition: wallet2.h:1680
void confirm_backlog(bool always)
Definition: wallet2.h:1206
void stop()
Definition: wallet2.h:870
void set_refresh_type(RefreshType refresh_type)
Definition: wallet2.h:929
boost::optional< epee::wipeable_string > m_encrypt_keys_after_refresh
Definition: wallet2.h:1794
serializable_unordered_multimap< crypto::hash, pool_payment_details > m_unconfirmed_payments
Definition: wallet2.h:1678
const std::string get_ring_database() const
Definition: wallet2.h:1503
RefreshType m_refresh_type
Definition: wallet2.h:1722
uint64_t ignore_outputs_below() const
Definition: wallet2.h:1225
bool m_trusted_daemon
Definition: wallet2.h:1703
uint32_t m_default_mixin
Definition: wallet2.h:1720
bool key_reuse_mitigation2() const
Definition: wallet2.h:1215
uint64_t credits() const
Definition: wallet2.h:1550
bool m_offline
Definition: wallet2.h:1757
std::unique_ptr< wallet_device_callback > m_device_callback
Definition: wallet2.h:1802
uint64_t m_min_output_value
Definition: wallet2.h:1732
void persistent_rpc_client_id(bool persistent)
Definition: wallet2.h:1242
void auto_low_priority(bool value)
Definition: wallet2.h:1212
const std::unique_ptr< epee::net_utils::http::abstract_http_client > m_http_client
Definition: wallet2.h:1674
uint32_t get_default_priority() const
Definition: wallet2.h:1193
uint64_t m_light_wallet_balance
Definition: wallet2.h:1772
std::string m_mms_file
Definition: wallet2.h:1673
uint64_t get_device_last_key_image_sync() const
Definition: wallet2.h:1012
uint64_t m_upper_transaction_weight_limit
Definition: wallet2.h:1694
uint32_t get_min_output_count() const
Definition: wallet2.h:1200
bool m_confirm_export_overwrite
Definition: wallet2.h:1736
std::vector< crypto::public_key > get_subaddress_spend_public_keys(uint32_t account, uint32_t begin, uint32_t end) const
uint32_t m_default_priority
Definition: wallet2.h:1721
uint32_t m_confirm_backlog_threshold
Definition: wallet2.h:1735
void handle_payment_changes(const T &res, std::false_type)
Definition: wallet2.h:1436
serializable_unordered_map< crypto::public_key, cryptonote::subaddress_index > m_subaddresses
Definition: wallet2.h:1688
bool m_first_refresh_done
Definition: wallet2.h:1724
size_t get_num_subaddresses(uint32_t index_major) const
Definition: wallet2.h:912
cryptonote::network_type m_nettype
Definition: wallet2.h:1706
uint64_t get_blockchain_current_height() const
Definition: wallet2.h:1005
mms::message_store m_message_store
Definition: wallet2.h:1788
crypto::chacha_key m_cache_key
Definition: wallet2.h:1793
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)
bool store_tx_info() const
Definition: wallet2.h:1189
void serialize(t_archive &a, const unsigned int ver)
Definition: wallet2.h:1017
std::vector< crypto::public_key > m_multisig_signers
Definition: wallet2.h:1713
std::unordered_map< crypto::hash, address_tx > m_light_wallet_address_txs
Definition: wallet2.h:1776
std::vector< crypto::public_key > m_multisig_derivations
Definition: wallet2.h:1716
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)
bool m_light_wallet
Definition: wallet2.h:1767
serializable_unordered_map< crypto::hash, unconfirmed_transfer_details > m_unconfirmed_txs
Definition: wallet2.h:1676
RefreshType get_refresh_type() const
Definition: wallet2.h:930
size_t m_subaddress_lookahead_major
Definition: wallet2.h:1752
float m_auto_mine_for_rpc_payment_threshold
Definition: wallet2.h:1748
AskPasswordType m_ask_password
Definition: wallet2.h:1730
unsigned int m_decrypt_keys_lockers
Definition: wallet2.h:1796
uint64_t get_refresh_from_block_height() const
Definition: wallet2.h:853
BackgroundMiningSetupType
Definition: wallet2.h:250
bool key_on_device() const
Definition: wallet2.h:938
ExportFormat
Definition: wallet2.h:256
@ Ascii
Definition: wallet2.h:258
rpc_payment_state_t m_rpc_payment_state
Definition: wallet2.h:1760
void confirm_export_overwrite(bool always)
Definition: wallet2.h:1210
const ExportFormat & export_format() const
Definition: wallet2.h:1237
uint32_t m_rpc_version
Definition: wallet2.h:1758
bool m_use_dns
Definition: wallet2.h:1756
bool auto_refresh() const
Definition: wallet2.h:1195
serializable_unordered_map< crypto::hash, std::string > m_tx_device
Definition: wallet2.h:1764
bool is_trusted_daemon() const
Definition: wallet2.h:875
uint32_t m_inactivity_lock_timeout
Definition: wallet2.h:1745
void segregation_height(uint64_t height)
Definition: wallet2.h:1218
static boost::mutex default_daemon_address_lock
Definition: wallet2.h:1807
bool explicit_refresh_from_block_height() const
Definition: wallet2.h:856
bool confirm_export_overwrite() const
Definition: wallet2.h:1209
void segregate_pre_fork_outputs(bool value)
Definition: wallet2.h:1214
void store_tx_info(bool store)
Definition: wallet2.h:1190
uint64_t credits_target() const
Definition: wallet2.h:1247
hw::device::device_type get_device_type() const
Definition: wallet2.h:939
void set_confirm_backlog_threshold(uint32_t threshold)
Definition: wallet2.h:1207
serializable_unordered_map< crypto::public_key, crypto::key_image > m_cold_key_images
Definition: wallet2.h:1697
std::vector< uint64_t > amounts_container
Definition: wallet2.h:376
bool m_devices_registered
Definition: wallet2.h:1799
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")
Definition: wallet2.h:1488
i_wallet2_callback * m_callback
Definition: wallet2.h:1704
bool auto_low_priority() const
Definition: wallet2.h:1211
bool m_store_tx_info
Definition: wallet2.h:1719
serializable_unordered_map< crypto::key_image, size_t > m_key_images
Definition: wallet2.h:1685
cryptonote::account_base & get_account()
Definition: wallet2.h:844
void print_ring_members(bool value)
Definition: wallet2.h:1188
void credit_report(uint64_t &expected_spent, uint64_t &discrepancy) const
Definition: wallet2.h:1551
uint64_t m_refresh_from_block_height
Definition: wallet2.h:1725
mms::message_store & get_message_store()
Definition: wallet2.h:1531
bool m_auto_refresh
Definition: wallet2.h:1723
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")
Definition: wallet2.h:1495
std::string get_address_as_str() const
Definition: wallet2.h:908
bool m_ring_history_saved
Definition: wallet2.h:1781
const cryptonote::account_base & get_account() const
Definition: wallet2.h:845
bool m_persistent_rpc_client_id
Definition: wallet2.h:1747
uint32_t default_mixin() const
Definition: wallet2.h:1191
bool m_watch_only
Definition: wallet2.h:1710
uint64_t get_light_wallet_scanned_block_height() const
Definition: wallet2.h:889
void set_min_output_value(uint64_t value)
Definition: wallet2.h:1201
cryptonote::network_type nettype() const
Definition: wallet2.h:932
float auto_mine_for_rpc_payment_threshold() const
Definition: wallet2.h:1244
serializable_unordered_map< crypto::hash, confirmed_transfer_details > m_confirmed_txs
Definition: wallet2.h:1677
bool light_wallet() const
Checks if light wallet. A light wallet sends view key to a server where the blockchain is scanned.
Definition: wallet2.h:887
std::string m_keys_file
Definition: wallet2.h:1672
ExportFormat m_export_format
Definition: wallet2.h:1804
bool m_auto_low_priority
Definition: wallet2.h:1737
cryptonote::account_public_address get_address() const
Definition: wallet2.h:903
uint32_t inactivity_lock_timeout() const
Definition: wallet2.h:1231
crypto::secret_key get_rpc_client_secret_key() const
Definition: wallet2.h:1245
bool m_always_confirm_transfers
Definition: wallet2.h:1717
void ignore_fractional_outputs(bool value)
Definition: wallet2.h:1220
const boost::optional< epee::net_utils::http::login > & get_daemon_login() const
Definition: wallet2.h:1303
Definition: wallet2.h:162
boost::optional< epee::wipeable_string > on_passphrase_request(bool &on_device) override
Definition: wallet2.cpp:1124
void on_button_pressed() override
Definition: wallet2.cpp:1111
wallet2 * wallet
Definition: wallet2.h:171
void on_button_request(uint64_t code=0) override
Definition: wallet2.cpp:1105
wallet_device_callback(wallet2 *wallet)
Definition: wallet2.h:164
void on_progress(const hw::device_progress &event) override
Definition: wallet2.cpp:1133
boost::optional< epee::wipeable_string > on_pin_request() override
Definition: wallet2.cpp:1117
Definition: wallet2.h:122
crypto::chacha_key key
Definition: wallet2.h:130
static boost::mutex lockers_lock
Definition: wallet2.h:131
static unsigned int lockers
Definition: wallet2.h:132
bool locked
Definition: wallet2.h:129
~wallet_keys_unlocker()
Definition: wallet2.cpp:1083
wallet2 & w
Definition: wallet2.h:128
wallet_keys_unlocker(wallet2 &w, const boost::optional< tools::password_container > &password)
Definition: wallet2.cpp:1053
#define tr(x)
Definition: common_defines.h:4
#define CORE_RPC_STATUS_PAYMENT_REQUIRED
Definition: core_rpc_server_commands_defs.h:81
#define CORE_RPC_STATUS_OK
Definition: core_rpc_server_commands_defs.h:78
#define FEE_PER_KB
Definition: cryptonote_config.h:69
void * memcpy(void *a, const void *b, size_t c)
Definition: glibc_compat.cpp:16
const uint32_t T[512]
Definition: groestl_tables.h:36
string a
Definition: MakeCryptoOps.py:15
boost::optional< tools::password_container > password_prompter(const char *prompt, bool verify)
Definition: simplewallet.cpp:319
tools::wallet2::RefreshType refresh_type
Definition: simplewallet.cpp:418
int b
Definition: base.py:1
Definition: blocks.cpp:13
void load(Archive &a, std::unordered_map< h_key, hval > &x, const boost::serialization::version_type ver)
Definition: unordered_containers_boost_serialization.h:54
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)
Definition: wallet2.h:1837
Definition: unordered_containers_boost_serialization.h:38
const
Definition: build_protob.py:9
crypto namespace.
Definition: crypto.cpp:60
POD_CLASS signature
Definition: crypto.h:93
constexpr static crypto::hash null_hash
Definition: hash.h:92
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition: crypto.h:67
POD_CLASS hash8
Definition: hash.h:51
POD_CLASS key_derivation
Definition: crypto.h:83
POD_CLASS public_key
Definition: crypto.h:61
bool check_tx_proof(const hash &prefix_hash, const public_key &R, const public_key &A, const boost::optional< public_key > &B, const public_key &D, const signature &sig, const int version)
Definition: crypto.h:256
POD_CLASS key_image
Definition: crypto.h:87
constexpr static crypto::hash8 null_hash8
Definition: hash.h:93
POD_CLASS hash
Definition: hash.h:48
network_type
Definition: cryptonote_config.h:273
@ MAINNET
Definition: cryptonote_config.h:274
void decompose_amount_into_digits(uint64_t amount, uint64_t dust_threshold, const chunk_handler_t &chunk_handler, const dust_handler_t &dust_handler)
Definition: cryptonote_format_utils.h:210
std::string print_money(uint64_t amount, unsigned int decimal_point)
Definition: cryptonote_format_utils.cpp:1028
crypto::hash get_transaction_hash(const transaction &t)
Definition: cryptonote_format_utils.cpp:1058
std::string blobdata
Definition: blobdatatype.h:39
void init_options(boost::program_options::options_description &hidden_options, boost::program_options::options_description &normal_options)
Definition: posix_daemonizer.inl:56
declaration and default definition for the functions used the API
Definition: expect.cpp:34
tools::wallet2::tx_construction_data tx_construction_data
Definition: protocol.hpp:158
tools::wallet2::unsigned_tx_set unsigned_tx_set
Definition: protocol.hpp:159
std::shared_ptr< messages::monero::MoneroGetTxKeyRequest > get_tx_key(const hw::device_cold::tx_key_data_t &tx_data)
Definition: protocol.cpp:1098
mdb_size_t count(MDB_cursor *cur)
Definition: value_stream.cpp:39
error
Tracks LMDB error codes.
Definition: error.h:45
version
Supported socks variants.
Definition: socks.h:58
Definition: bulletproofs.cc:64
static void add(ge_p3 &p3, const ge_cached &other)
Definition: multiexp.cc:143
@ RangeProofBorromean
Definition: rctTypes.h:261
@ RangeProofBulletproof
Definition: rctTypes.h:261
key identity()
Definition: rctOps.h:73
Definition: binary_utils.h:36
char true_type
Definition: sfinae_helpers.h:39
Definition: blockchain_ancestry.cpp:72
void print_source_entry(const cryptonote::tx_source_entry &src)
Definition: wallet2.h:2346
void digit_split_strategy(const std::vector< cryptonote::tx_destination_entry > &dsts, const cryptonote::tx_destination_entry &change_dst, uint64_t dust_threshold, std::vector< cryptonote::tx_destination_entry > &splitted_dsts, std::vector< cryptonote::tx_destination_entry > &dust_dsts)
Definition: wallet2.h:2307
void null_split_strategy(const std::vector< cryptonote::tx_destination_entry > &dsts, const cryptonote::tx_destination_entry &change_dst, uint64_t dust_threshold, std::vector< cryptonote::tx_destination_entry > &splitted_dsts, std::vector< cryptonote::tx_destination_entry > &dust_dsts)
Definition: wallet2.h:2331
Various Tools.
Definition: apply_permutation.h:40
static const std::chrono::seconds rpc_timeout
Definition: node_rpc_proxy.cpp:52
static void check_rpc_cost(rpc_payment_state_t &rpc_payment_state, const char *call, uint64_t post_call_credits, uint64_t pre_call_credits, double expected_cost)
Definition: wallet_rpc_helpers.h:59
BOOST_CLASS_VERSION(nodetool::peerlist_types, nodetool::CURRENT_PEERLIST_STORAGE_ARCHIVE_VER)
static std::string decrypt(const std::string &ciphertext, const crypto::key_image &key_image, const crypto::chacha_key &key, uint8_t field)
Definition: ringdb.cpp:138
static std::string encrypt(const std::string &plaintext, const crypto::key_image &key_image, const crypto::chacha_key &key, uint8_t field)
Definition: ringdb.cpp:123
#define BEGIN_SERIALIZE_OBJECT()
begins the environment of the DSL \detailed for described the serialization of an object
Definition: serialization.h:191
#define FIELD(f)
tags the field with the variable name and then serializes it
Definition: serialization.h:244
#define VERSION_FIELD(v)
Definition: serialization.h:295
#define MAGIC_FIELD(m)
Definition: serialization.h:284
#define END_SERIALIZE()
self-explanatory
Definition: serialization.h:215
#define VARINT_FIELD(f)
tags and serializes the varint f
Definition: serialization.h:264
static const unsigned char iv[64]
Definition: sha512-hash.c:13
#define ts
Definition: skein.c:522
CXA_THROW_INFO_T * info
Definition: stack_trace.cpp:90
#define true
Definition: stdbool.h:36
Definition: core_rpc_server_commands_defs.h:191
Definition: cryptonote_basic.h:501
Definition: cryptonote_protocol_defs.h:133
Definition: cryptonote_basic.h:464
Definition: cryptonote_basic.h:528
Definition: subaddress_index.h:39
Definition: cryptonote_tx_utils.h:75
uint64_t amount
Definition: cryptonote_tx_utils.h:77
account_public_address addr
Definition: cryptonote_tx_utils.h:78
Definition: cryptonote_basic.h:143
Definition: cryptonote_tx_utils.h:43
uint64_t amount
Definition: cryptonote_tx_utils.h:51
size_t real_output
Definition: cryptonote_tx_utils.h:47
std::vector< output_entry > outputs
Definition: cryptonote_tx_utils.h:46
std::pair< uint64_t, rct::ctkey > output_entry
Definition: cryptonote_tx_utils.h:44
size_t real_output_in_tx_index
Definition: cryptonote_tx_utils.h:50
Definition: cryptonote_basic.h:77
crypto::public_key key
Definition: cryptonote_basic.h:80
Definition: message_store.h:241
Definition: rctTypes.h:262
RangeProofType range_proof_type
Definition: rctTypes.h:263
Definition: rctTypes.h:79
Definition: rctTypes.h:105
Definition: rctTypes.h:114
Definition: rctTypes.h:536
epee::misc_utils::struct_init< response_t > response
Definition: wallet_light_rpc.h:179
epee::misc_utils::struct_init< response_t > response
Definition: wallet_light_rpc.h:317
Definition: wallet2.h:106
static constexpr result_type min()
Definition: wallet2.h:108
result_type operator()()
Definition: wallet2.h:110
uint64_t result_type
Definition: wallet2.h:107
static constexpr result_type max()
Definition: wallet2.h:109
Definition: wallet_rpc_helpers.h:49
Definition: wallet2.h:175
bool add_to_fee
Definition: wallet2.h:177
cryptonote::account_public_address addr_for_dust
Definition: wallet2.h:178
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())
Definition: wallet2.h:180
uint64_t dust_threshold
Definition: wallet2.h:176
Definition: wallet2.h:635
bool m_is_subaddress
Definition: wallet2.h:639
crypto::hash8 m_payment_id
Definition: wallet2.h:637
bool m_has_payment_id
Definition: wallet2.h:640
std::string m_description
Definition: wallet2.h:638
cryptonote::account_public_address m_address
Definition: wallet2.h:636
Definition: wallet2.h:404
bool m_incoming
Definition: wallet2.h:406
bool m_mempool
Definition: wallet2.h:405
Definition: wallet2.h:623
crypto::chacha_iv iv
Definition: wallet2.h:624
std::string cache_data
Definition: wallet2.h:625
uint64_t m_amount_out
Definition: wallet2.h:457
std::vector< std::pair< crypto::key_image, std::vector< uint64_t > > > m_rings
Definition: wallet2.h:466
uint64_t m_block_height
Definition: wallet2.h:459
uint64_t m_change
Definition: wallet2.h:458
uint32_t m_subaddr_account
Definition: wallet2.h:464
uint64_t m_amount_in
Definition: wallet2.h:456
confirmed_transfer_details(const unconfirmed_transfer_details &utd, uint64_t height)
Definition: wallet2.h:469
crypto::hash m_payment_id
Definition: wallet2.h:461
confirmed_transfer_details()
Definition: wallet2.h:468
uint64_t m_timestamp
Definition: wallet2.h:462
std::set< uint32_t > m_subaddr_indices
Definition: wallet2.h:465
std::vector< cryptonote::tx_destination_entry > m_dests
Definition: wallet2.h:460
uint64_t m_unlock_time
Definition: wallet2.h:463
Definition: wallet2.h:684
std::vector< boost::optional< cryptonote::subaddress_receive_info > > received
Definition: wallet2.h:687
crypto::public_key pkey
Definition: wallet2.h:685
crypto::key_derivation derivation
Definition: wallet2.h:686
Definition: wallet2.h:612
std::string account_data
Definition: wallet2.h:614
crypto::chacha_iv iv
Definition: wallet2.h:613
bool old
Definition: wallet2.h:1350
Definition: wallet2.h:291
rct::key m_R
Definition: wallet2.h:293
rct::key m_L
Definition: wallet2.h:292
Definition: wallet2.h:289
crypto::public_key m_signer
Definition: wallet2.h:301
std::vector< crypto::key_image > m_partial_key_images
Definition: wallet2.h:303
std::vector< LR > m_LR
Definition: wallet2.h:302
Definition: wallet2.h:521
std::unordered_set< crypto::public_key > ignore
Definition: wallet2.h:523
rct::multisig_out msout
Definition: wallet2.h:526
rct::rctSig sigs
Definition: wallet2.h:522
std::unordered_set< crypto::public_key > signing_keys
Definition: wallet2.h:525
std::unordered_set< rct::key > used_L
Definition: wallet2.h:524
Definition: wallet2.h:601
std::unordered_set< crypto::public_key > m_signers
Definition: wallet2.h:603
std::vector< pending_tx > m_ptx
Definition: wallet2.h:602
Definition: wallet2.h:675
bool error
Definition: wallet2.h:680
cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices o_indices
Definition: wallet2.h:679
cryptonote::block block
Definition: wallet2.h:677
std::vector< cryptonote::transaction > txes
Definition: wallet2.h:678
crypto::hash hash
Definition: wallet2.h:676
Definition: wallet2.h:378
bool m_coinbase
Definition: wallet2.h:386
amounts_container m_amounts
Definition: wallet2.h:381
crypto::hash m_tx_hash
Definition: wallet2.h:379
uint64_t m_fee
Definition: wallet2.h:382
uint64_t m_timestamp
Definition: wallet2.h:385
uint64_t m_unlock_time
Definition: wallet2.h:384
uint64_t m_amount
Definition: wallet2.h:380
uint64_t m_block_height
Definition: wallet2.h:383
cryptonote::subaddress_index m_subaddr_index
Definition: wallet2.h:387
Definition: wallet2.h:542
tx_construction_data construction_data
Definition: wallet2.h:554
std::vector< size_t > selected_transfers
Definition: wallet2.h:547
bool dust_added_to_fee
Definition: wallet2.h:545
crypto::secret_key tx_key
Definition: wallet2.h:549
std::vector< cryptonote::tx_destination_entry > dests
Definition: wallet2.h:551
std::vector< multisig_sig > multisig_sigs
Definition: wallet2.h:552
cryptonote::transaction tx
Definition: wallet2.h:543
std::vector< crypto::secret_key > additional_tx_keys
Definition: wallet2.h:550
std::string key_images
Definition: wallet2.h:548
uint64_t fee
Definition: wallet2.h:544
cryptonote::tx_destination_entry change_dts
Definition: wallet2.h:546
uint64_t dust
Definition: wallet2.h:544
Definition: wallet2.h:410
bool m_double_spend_seen
Definition: wallet2.h:412
payment_details m_pd
Definition: wallet2.h:411
Definition: wallet2.h:653
crypto::public_key shared_secret
Definition: wallet2.h:656
crypto::signature key_image_sig
Definition: wallet2.h:659
crypto::signature shared_secret_sig
Definition: wallet2.h:658
uint64_t index_in_tx
Definition: wallet2.h:655
crypto::key_image key_image
Definition: wallet2.h:657
crypto::hash txid
Definition: wallet2.h:654
Definition: wallet2.h:587
serializable_unordered_map< crypto::public_key, crypto::key_image > tx_key_images
Definition: wallet2.h:590
std::vector< crypto::key_image > key_images
Definition: wallet2.h:589
std::vector< pending_tx > ptx
Definition: wallet2.h:588
Definition: wallet2.h:326
uint64_t m_amount
Definition: wallet2.h:337
bool m_key_image_request
Definition: wallet2.h:340
bool m_frozen
Definition: wallet2.h:333
rct::key m_mask
Definition: wallet2.h:336
bool m_spent
Definition: wallet2.h:332
uint64_t m_global_output_index
Definition: wallet2.h:331
crypto::key_image m_key_image
Definition: wallet2.h:335
uint64_t amount() const
Definition: wallet2.h:349
std::vector< std::pair< uint64_t, crypto::hash > > m_uses
Definition: wallet2.h:346
std::vector< multisig_info > m_multisig_info
Definition: wallet2.h:345
cryptonote::subaddress_index m_subaddr_index
Definition: wallet2.h:342
uint64_t m_spent_height
Definition: wallet2.h:334
uint64_t m_block_height
Definition: wallet2.h:327
const crypto::public_key & get_public_key() const
Definition: wallet2.h:350
size_t m_pk_index
Definition: wallet2.h:341
crypto::hash m_txid
Definition: wallet2.h:329
bool m_rct
Definition: wallet2.h:338
cryptonote::transaction_prefix m_tx
Definition: wallet2.h:328
bool is_rct() const
Definition: wallet2.h:348
bool m_key_image_partial
Definition: wallet2.h:343
bool m_key_image_known
Definition: wallet2.h:339
std::vector< rct::key > m_multisig_k
Definition: wallet2.h:344
size_t m_internal_output_index
Definition: wallet2.h:330
Definition: wallet2.h:691
std::vector< cryptonote::tx_extra_field > tx_extra_fields
Definition: wallet2.h:692
std::vector< is_out_data > primary
Definition: wallet2.h:693
bool empty() const
Definition: wallet2.h:696
std::vector< is_out_data > additional
Definition: wallet2.h:694
Definition: wallet2.h:489
std::vector< uint8_t > extra
Definition: wallet2.h:494
std::vector< cryptonote::tx_source_entry > sources
Definition: wallet2.h:490
std::vector< cryptonote::tx_destination_entry > splitted_dsts
Definition: wallet2.h:492
rct::RCTConfig rct_config
Definition: wallet2.h:497
std::vector< cryptonote::tx_destination_entry > dests
Definition: wallet2.h:498
uint64_t unlock_time
Definition: wallet2.h:495
std::vector< size_t > selected_transfers
Definition: wallet2.h:493
std::set< uint32_t > subaddr_indices
Definition: wallet2.h:500
uint32_t subaddr_account
Definition: wallet2.h:499
bool use_rct
Definition: wallet2.h:496
cryptonote::tx_destination_entry change_dts
Definition: wallet2.h:491
Definition: wallet2.h:313
boost::optional< cryptonote::subaddress_receive_info > received
Definition: wallet2.h:320
uint64_t amount
Definition: wallet2.h:317
rct::key mask
Definition: wallet2.h:316
cryptonote::keypair in_ephemeral
Definition: wallet2.h:314
uint64_t money_transfered
Definition: wallet2.h:318
tx_scan_info_t()
Definition: wallet2.h:322
bool error
Definition: wallet2.h:319
crypto::key_image ki
Definition: wallet2.h:315
uint32_t m_subaddr_account
Definition: wallet2.h:432
time_t m_sent_time
Definition: wallet2.h:427
uint64_t m_amount_out
Definition: wallet2.h:425
enum tools::wallet2::unconfirmed_transfer_details::@14 m_state
uint64_t m_timestamp
Definition: wallet2.h:431
crypto::hash m_payment_id
Definition: wallet2.h:429
cryptonote::transaction_prefix m_tx
Definition: wallet2.h:423
std::vector< std::pair< crypto::key_image, std::vector< uint64_t > > > m_rings
Definition: wallet2.h:434
std::vector< cryptonote::tx_destination_entry > m_dests
Definition: wallet2.h:428
uint64_t m_amount_in
Definition: wallet2.h:424
std::set< uint32_t > m_subaddr_indices
Definition: wallet2.h:433
uint64_t m_change
Definition: wallet2.h:426
Definition: wallet2.h:575
std::vector< tx_construction_data > txes
Definition: wallet2.h:576
std::pair< size_t, wallet2::transfer_container > transfers
Definition: wallet2.h:577