Electroneum
wallet2.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2018, The Electroneum Project
2 // Copyrights(c) 2014-2017, The Monero Project
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without modification, are
7 // permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this list of
10 // conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 // of conditions and the following disclaimer in the documentation and/or other
14 // materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its contributors may be
17 // used to endorse or promote products derived from this software without specific
18 // prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31 
32 #pragma once
33 
34 #include <memory>
35 
36 #include <boost/program_options/options_description.hpp>
37 #include <boost/program_options/variables_map.hpp>
38 #include <boost/serialization/list.hpp>
39 #include <boost/serialization/vector.hpp>
40 #include <atomic>
41 
42 #include "include_base_utils.h"
46 #include "net/http_client.h"
47 #include "storages/http_abstract_invoke.h"
52 #include "crypto/chacha8.h"
53 #include "crypto/hash.h"
54 #include "ringct/rctTypes.h"
55 #include "ringct/rctOps.h"
56 
57 #include "wallet_errors.h"
58 #include "common/password.h"
59 #include "node_rpc_proxy.h"
60 
61 #include <iostream>
62 
63 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
64 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "wallet.wallet2"
65 
66 class Serialization_portability_wallet_Test;
67 
68 namespace tools
69 {
71  {
72  public:
73  virtual void on_new_block(uint64_t height, const cryptonote::block& block) {}
74  virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount) {}
75  virtual void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount) {}
76  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) {}
77  virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx) {}
78  virtual ~i_wallet2_callback() {}
79  };
80 
82  {
83  uint64_t dust_threshold;
84  bool add_to_fee;
86 
87  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())
88  : dust_threshold(a_dust_threshold)
89  , add_to_fee(an_add_to_fee)
90  , addr_for_dust(an_addr_for_dust)
91  {
92  }
93  };
94 
95  class wallet2
96  {
97  friend class ::Serialization_portability_wallet_Test;
98  public:
99  static constexpr const std::chrono::seconds rpc_timeout = std::chrono::minutes(3) + std::chrono::seconds(30);
100 
101  enum RefreshType {
106  };
107 
108  private:
110 
111  public:
112  static const char* tr(const char* str);
113 
114  static bool has_testnet_option(const boost::program_options::variables_map& vm);
115  static void init_options(boost::program_options::options_description& desc_params);
116 
118  static boost::optional<password_container> password_prompt(const bool new_password);
119 
121  static std::unique_ptr<wallet2> make_from_json(const boost::program_options::variables_map& vm, const std::string& json_file);
122 
124  static std::pair<std::unique_ptr<wallet2>, password_container>
125  make_from_file(const boost::program_options::variables_map& vm, const std::string& wallet_file);
126 
128  static std::pair<std::unique_ptr<wallet2>, password_container> make_new(const boost::program_options::variables_map& vm);
129 
131  static std::unique_ptr<wallet2> make_dummy(const boost::program_options::variables_map& vm);
132 
133  static bool verify_password(const std::string& keys_file_name, const std::string& password, bool watch_only);
134 
136 
138  {
139  uint64_t m_block_height;
144  bool m_spent;
145  uint64_t m_spent_height;
146  crypto::key_image m_key_image; //TODO: key_image stored twice :(
148  uint64_t m_amount;
149  bool m_rct;
151  size_t m_pk_index;
152 
153  bool is_rct() const { return m_rct; }
154  uint64_t amount() const { return m_amount; }
155  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; }
156 
159  FIELD(m_tx)
160  FIELD(m_txid)
163  FIELD(m_spent)
166  FIELD(m_mask)
167  FIELD(m_amount)
168  FIELD(m_rct)
171  END_SERIALIZE()
172  };
173 
175  {
177  uint64_t m_amount;
178  uint64_t m_block_height;
179  uint64_t m_unlock_time;
180  uint64_t m_timestamp;
181  };
182 
184  {
186  uint64_t m_amount_in;
187  uint64_t m_amount_out;
188  uint64_t m_change;
189  time_t m_sent_time;
190  std::vector<cryptonote::tx_destination_entry> m_dests;
192  enum { pending, pending_not_in_pool, failed } m_state;
193  uint64_t m_timestamp;
194  };
195 
197  {
198  uint64_t m_amount_in;
199  uint64_t m_amount_out;
200  uint64_t m_change;
201  uint64_t m_block_height;
202  std::vector<cryptonote::tx_destination_entry> m_dests;
204  uint64_t m_timestamp;
205  uint64_t m_unlock_time;
206 
207  confirmed_transfer_details(): m_amount_in(0), m_amount_out(0), m_change((uint64_t)-1), m_block_height(0), m_payment_id(cryptonote::null_hash), m_timestamp(0), m_unlock_time(0) {}
209  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) {}
210  };
211 
213  {
214  std::vector<cryptonote::tx_source_entry> sources;
216  std::vector<cryptonote::tx_destination_entry> splitted_dsts; // split, includes change
217  std::list<size_t> selected_transfers;
218  std::vector<uint8_t> extra;
219  uint64_t unlock_time;
220  bool use_rct;
221  std::vector<cryptonote::tx_destination_entry> dests; // original setup, does not include change
222  };
223 
224  typedef std::vector<transfer_details> transfer_container;
225  typedef std::unordered_multimap<crypto::hash, payment_details> payment_container;
226 
227  // The convention for destinations is:
228  // dests does not include change
229  // splitted_dsts (in construction_data) does
230  struct pending_tx
231  {
233  uint64_t dust, fee;
236  std::list<size_t> selected_transfers;
237  std::string key_images;
239  std::vector<cryptonote::tx_destination_entry> dests;
240 
242  };
243 
244  // The term "Unsigned tx" is not really a tx since it's not signed yet.
245  // It doesnt have tx hash, key and the integrated address is not separated into addr + payment id.
247  {
248  std::vector<tx_construction_data> txes;
250  };
251 
253  {
254  std::vector<pending_tx> ptx;
255  std::vector<crypto::key_image> key_images;
256  };
257 
259  {
260  crypto::chacha8_iv iv;
261  std::string account_data;
262 
264  FIELD(iv)
265  FIELD(account_data)
266  END_SERIALIZE()
267  };
268 
270  {
271  crypto::chacha8_iv iv;
272  std::string cache_data;
273 
275  FIELD(iv)
276  FIELD(cache_data)
277  END_SERIALIZE()
278  };
279 
280  // GUI Address book
282  {
285  std::string m_description;
286  };
287 
288  typedef std::tuple<uint64_t, crypto::public_key, rct::key> get_outs_entry;
289 
299  crypto::secret_key generate(const std::string& wallet, const std::string& password,
300  const crypto::secret_key& recovery_param = crypto::secret_key(), bool recover = false,
301  bool two_random = false);
309  void generate(const std::string& wallet, const std::string& password,
310  const cryptonote::account_public_address &account_public_address,
311  const crypto::secret_key& spendkey, const crypto::secret_key& viewkey);
318  void generate(const std::string& wallet, const std::string& password,
319  const cryptonote::account_public_address &account_public_address,
320  const crypto::secret_key& viewkey = crypto::secret_key());
326  void rewrite(const std::string& wallet_name, const std::string& password);
327  void write_watch_only_wallet(const std::string& wallet_name, const std::string& password);
328  void load(const std::string& wallet, const std::string& password);
329  void store();
335  void store_to(const std::string &path, const std::string &password);
336 
337  std::string path() const;
338 
342  bool verify_password(const std::string& password) const;
345 
348 
349  // upper_transaction_size_limit as defined below is set to
350  // approximately 125% of the fixed minimum allowable penalty
351  // free block size. TODO: fix this so that it actually takes
352  // into account the current median block size rather than
353  // the minimum block size.
354  bool deinit();
355  bool init(std::string daemon_address = "http://localhost:8080",
356  boost::optional<epee::net_utils::http::login> daemon_login = boost::none, uint64_t upper_transaction_size_limit = 0);
357 
358  void stop() { m_run.store(false, std::memory_order_relaxed); }
359 
362 
366  bool is_deterministic() const;
367  bool get_seed(std::string& electrum_words) const;
371  const std::string &get_seed_language() const;
375  void set_seed_language(const std::string &language);
379  bool is_deprecated() const;
380  void refresh();
381  void refresh(uint64_t start_height, uint64_t & blocks_fetched);
382  void refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& received_money);
383  bool refresh(uint64_t & blocks_fetched, bool& received_money, bool& ok);
384 
387 
388  bool testnet() const { return m_testnet; }
389  bool restricted() const { return m_restricted; }
390  bool watch_only() const { return m_watch_only; }
391 
392  uint64_t balance() const;
393  uint64_t unlocked_balance() const;
394  uint64_t unlocked_dust_balance(const tx_dust_policy &dust_policy) const;
395  template<typename T>
396  void transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, const size_t fake_outputs_count, const std::vector<size_t> &unused_transfers_indices, uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, bool trusted_daemon);
397  template<typename T>
398  void transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, const size_t fake_outputs_count, const std::vector<size_t> &unused_transfers_indices, 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, bool trusted_daemon);
399  void transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, const size_t fake_outputs_count, const std::vector<size_t> &unused_transfers_indices, uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, bool trusted_daemon);
400  void transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, const size_t fake_outputs_count, const std::vector<size_t> &unused_transfers_indices, uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx& ptx, bool trusted_daemon);
401  template<typename T>
402  void transfer_selected(const std::vector<cryptonote::tx_destination_entry>& dsts, const std::list<size_t> selected_transfers, size_t fake_outputs_count,
403  std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs,
404  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);
405  void transfer_selected_rct(std::vector<cryptonote::tx_destination_entry> dsts, const std::list<size_t> selected_transfers, size_t fake_outputs_count,
406  std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs,
407  uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx &ptx);
408 
409  void commit_tx(pending_tx& ptx_vector);
410  void commit_tx(std::vector<pending_tx>& ptx_vector);
411  bool save_tx(const std::vector<pending_tx>& ptx_vector, const std::string &filename);
412  // load unsigned tx from file and sign it. Takes confirmation callback as argument. Used by the cli wallet
413  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);
414  // sign unsigned tx. Takes unsigned_tx_set as argument. Used by GUI
415  bool sign_tx(unsigned_tx_set &exported_txs, const std::string &signed_filename, std::vector<wallet2::pending_tx> &ptx);
416  // load unsigned_tx_set from file.
417  bool load_unsigned_tx(const std::string &unsigned_filename, unsigned_tx_set &exported_txs);
418  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);
419  std::vector<pending_tx> create_transactions(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, bool trusted_daemon);
420  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, bool trusted_daemon);
421  std::vector<wallet2::pending_tx> create_transactions_all(uint64_t below, const cryptonote::account_public_address &address, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t> extra, bool trusted_daemon);
422  std::vector<wallet2::pending_tx> create_transactions_from(const cryptonote::account_public_address &address, 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, bool trusted_daemon);
423  std::vector<pending_tx> create_unmixable_sweep_transactions(bool trusted_daemon);
424  bool check_connection(uint32_t *version = NULL, uint32_t timeout = 200000);
425  void get_transfers(wallet2::transfer_container& incoming_transfers) const;
426  void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height = 0) const;
427  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;
428  void get_payments_out(std::list<std::pair<crypto::hash,wallet2::confirmed_transfer_details>>& confirmed_payments,
429  uint64_t min_height, uint64_t max_height = (uint64_t)-1) const;
430  void get_unconfirmed_payments_out(std::list<std::pair<crypto::hash,wallet2::unconfirmed_transfer_details>>& unconfirmed_payments) const;
431  void get_unconfirmed_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& unconfirmed_payments) const;
432 
434  void rescan_spent();
435  void rescan_blockchain(bool refresh = true);
436  bool is_transfer_unlocked(const transfer_details& td) const;
437  template <class t_archive>
438  inline void serialize(t_archive &a, const unsigned int ver)
439  {
440  uint64_t dummy_refresh_height = 0; // moved to keys file
441  if(ver < 5)
442  return;
443  a & m_blockchain;
444  a & m_transfers;
446  a & m_key_images;
447  if(ver < 6)
448  return;
450  if(ver < 7)
451  return;
452  a & m_payments;
453  if(ver < 8)
454  return;
455  a & m_tx_keys;
456  if(ver < 9)
457  return;
458  a & m_confirmed_txs;
459  if(ver < 11)
460  return;
461  a & dummy_refresh_height;
462  if(ver < 12)
463  return;
464  a & m_tx_notes;
465  if(ver < 13)
466  return;
467  if (ver < 17)
468  {
469  // we're loading an old version, where m_unconfirmed_payments was a std::map
470  std::unordered_map<crypto::hash, payment_details> m;
471  a & m;
472  for (std::unordered_map<crypto::hash, payment_details>::const_iterator i = m.begin(); i != m.end(); ++i)
473  m_unconfirmed_payments.insert(*i);
474  }
475  if(ver < 14)
476  return;
477  if(ver < 15)
478  {
479  // we're loading an older wallet without a pubkey map, rebuild it
480  for (size_t i = 0; i < m_transfers.size(); ++i)
481  {
482  const transfer_details &td = m_transfers[i];
484  const cryptonote::txout_to_key &o = boost::get<const cryptonote::txout_to_key>(out.target);
485  m_pub_keys.emplace(o.key, i);
486  }
487  return;
488  }
489  a & m_pub_keys;
490  if(ver < 16)
491  return;
492  a & m_address_book;
493  if(ver < 17)
494  return;
496  if(ver < 18)
497  return;
498  a & m_scanned_pool_txs[0];
499  a & m_scanned_pool_txs[1];
500  }
501 
508  static void wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exists);
514  static bool wallet_valid_path_format(const std::string& file_path);
515  static bool parse_long_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);
516  static bool parse_short_payment_id(const std::string& payment_id_str, crypto::hash8& payment_id);
517  static bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);
518 
520  void always_confirm_transfers(bool always) { m_always_confirm_transfers = always; }
521  bool print_ring_members() const { return m_print_ring_members; }
522  void print_ring_members(bool value) { m_print_ring_members = value; }
523  bool store_tx_info() const { return m_store_tx_info; }
525  uint32_t default_mixin() const { return m_default_mixin; }
526  void default_mixin(uint32_t m) { m_default_mixin = m; }
527  uint32_t get_default_priority() const { return m_default_priority; }
528  void set_default_priority(uint32_t p) { m_default_priority = p; }
529  bool auto_refresh() const { return m_auto_refresh; }
530  void auto_refresh(bool r) { m_auto_refresh = r; }
533  bool ask_password() const { return m_ask_password; }
534  void ask_password(bool always) { m_ask_password = always; }
535  void set_default_decimal_point(unsigned int decimal_point);
536  unsigned int get_default_decimal_point() const;
537  void set_min_output_count(uint32_t count) { m_min_output_count = count; }
538  uint32_t get_min_output_count() const { return m_min_output_count; }
539  void set_min_output_value(uint64_t value) { m_min_output_value = value; }
540  uint64_t get_min_output_value() const { return m_min_output_value; }
541  void merge_destinations(bool merge) { m_merge_destinations = merge; }
542  bool merge_destinations() const { return m_merge_destinations; }
543  bool confirm_backlog() const { return m_confirm_backlog; }
544  void confirm_backlog(bool always) { m_confirm_backlog = always; }
547 
548  bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key) const;
549 
553  std::vector<address_book_row> get_address_book() const { return m_address_book; }
554  bool add_address_book_row(const cryptonote::account_public_address &address, const crypto::hash &payment_id, const std::string &description);
555  bool delete_address_book_row(std::size_t row_id);
556 
557  uint64_t get_num_rct_outputs();
558  const transfer_details &get_transfer_details(size_t idx) const;
559 
560  void get_hard_fork_info(uint8_t version, uint64_t &earliest_height);
561  bool use_fork_rules(uint8_t version, int64_t early_blocks = 0);
562  int get_fee_algorithm();
563 
564  std::string get_wallet_file() const;
565  std::string get_keys_file() const;
566  std::string get_daemon_address() const;
567  const boost::optional<epee::net_utils::http::login>& get_daemon_login() const { return m_daemon_login; }
568  uint64_t get_daemon_blockchain_height(std::string& err);
569  uint64_t get_daemon_blockchain_target_height(std::string& err);
573  uint64_t get_approximate_blockchain_height() const;
574  std::vector<size_t> select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool allow_rct, bool trusted_daemon);
575  std::vector<size_t> select_available_outputs(const std::function<bool(const transfer_details &td)> &f);
576  std::vector<size_t> select_available_unmixable_outputs(bool trusted_daemon);
577  std::vector<size_t> select_available_mixable_outputs(bool trusted_daemon);
578 
579  size_t pop_best_value_from(const transfer_container &transfers, std::vector<size_t> &unused_dust_indices, const std::list<size_t>& selected_transfers, bool smallest = false) const;
580  size_t pop_best_value(std::vector<size_t> &unused_dust_indices, const std::list<size_t>& selected_transfers, bool smallest = false) const;
581 
582  void set_tx_note(const crypto::hash &txid, const std::string &note);
583  std::string get_tx_note(const crypto::hash &txid) const;
584 
585  std::string sign(const std::string &data) const;
586  bool verify(const std::string &data, const cryptonote::account_public_address &address, const std::string &signature) const;
587 
588  std::vector<tools::wallet2::transfer_details> export_outputs() const;
589  size_t import_outputs(const std::vector<tools::wallet2::transfer_details> &outputs);
590 
591  bool export_key_images(const std::string filename);
592  std::vector<std::pair<crypto::key_image, crypto::signature>> export_key_images() const;
593  uint64_t import_key_images(const std::vector<std::pair<crypto::key_image, crypto::signature>> &signed_key_images, uint64_t &spent, uint64_t &unspent);
594  uint64_t import_key_images(const std::string &filename, uint64_t &spent, uint64_t &unspent);
595 
596  void update_pool_state(bool refreshed = false);
597 
598  std::string encrypt(const std::string &plaintext, const crypto::secret_key &skey, bool authenticated = true) const;
599  std::string encrypt_with_view_secret_key(const std::string &plaintext, bool authenticated = true) const;
600  std::string decrypt(const std::string &ciphertext, const crypto::secret_key &skey, bool authenticated = true) const;
601  std::string decrypt_with_view_secret_key(const std::string &ciphertext, bool authenticated = true) const;
602 
603  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);
604  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);
605 
606  uint64_t get_blockchain_height_by_date(uint16_t year, uint8_t month, uint8_t day); // 1<=month<=12, 1<=day<=31
607 
608  bool is_synced() const;
609 
610  std::vector<std::pair<uint64_t, uint64_t>> estimate_backlog(uint64_t min_blob_size, uint64_t max_blob_size, const std::vector<uint64_t> &fees);
611 
612  uint64_t get_fee_multiplier(uint32_t priority, int fee_algorithm = -1);
613  uint64_t get_per_kb_fee();
614 
615  private:
623  bool store_keys(const std::string& keys_file_name, const std::string& password, bool watch_only = false);
629  bool load_keys(const std::string& keys_file_name, const std::string& password);
630  void process_new_transaction(const crypto::hash &txid, const cryptonote::transaction& tx, const std::vector<uint64_t> &o_indices, uint64_t height, uint64_t ts, bool miner_tx, bool pool);
632  void detach_blockchain(uint64_t height);
633  void get_short_chain_history(std::list<crypto::hash>& ids) const;
634  bool is_tx_spendtime_unlocked(uint64_t unlock_time, uint64_t block_height) const;
635  bool clear();
636  void pull_blocks(uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::list<cryptonote::block_complete_entry> &blocks, std::vector<cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices> &o_indices);
637  void pull_hashes(uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::list<crypto::hash> &hashes);
638  void fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history);
639  void pull_next_blocks(uint64_t start_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history, const std::list<cryptonote::block_complete_entry> &prev_blocks, std::list<cryptonote::block_complete_entry> &blocks, std::vector<cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices> &o_indices, bool &error);
640  void process_blocks(uint64_t start_height, const std::list<cryptonote::block_complete_entry> &blocks, const std::vector<cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices> &o_indices, uint64_t& blocks_added);
641  uint64_t select_transfers(uint64_t needed_money, std::vector<size_t> unused_transfers_indices, std::list<size_t>& selected_transfers, bool trusted_daemon);
642  bool prepare_file_names(const std::string& file_path);
643  void process_unconfirmed(const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t height);
644  void process_outgoing(const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t height, uint64_t ts, uint64_t spent, uint64_t received);
645  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);
647  void check_genesis(const crypto::hash& genesis_hash) const; //throws
648  bool generate_chacha8_key_from_secret_keys(crypto::chacha8_key &key) const;
649  crypto::hash get_payment_id(const pending_tx &ptx) const;
650  crypto::hash8 get_short_payment_id(const pending_tx &ptx) const;
651  void check_acc_out_precomp(const crypto::public_key &spend_public_key, const cryptonote::tx_out &o, const crypto::key_derivation &derivation, size_t i, bool &received, uint64_t &money_transfered, bool &error) const;
652  void check_acc_out_precomp_once(const crypto::public_key &spend_public_key, const cryptonote::tx_out &o, const crypto::key_derivation &derivation, size_t i, bool &received, uint64_t &money_transfered, bool &error, bool &already_seen) const;
653  void parse_block_round(const cryptonote::blobdata &blob, cryptonote::block &bl, crypto::hash &bl_id, bool &error) const;
655  std::vector<uint64_t> get_unspent_amounts_vector();
657  float get_output_relatedness(const transfer_details &td0, const transfer_details &td1) const;
658  std::vector<size_t> pick_preferred_rct_inputs(uint64_t needed_money) const;
659  void set_spent(size_t idx, uint64_t height);
660  void set_unspent(size_t idx);
661  void get_outs(std::vector<std::vector<get_outs_entry>> &outs, const std::list<size_t> &selected_transfers, size_t fake_outputs_count);
662  bool wallet_generate_key_image_helper(const cryptonote::account_keys& ack, const crypto::public_key& tx_public_key, size_t real_output_index, cryptonote::keypair& in_ephemeral, crypto::key_image& ki);
664  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;
665  std::vector<size_t> get_only_rct(const std::vector<size_t> &unused_dust_indices, const std::vector<size_t> &unused_transfers_indices) const;
666 
668  boost::optional<epee::net_utils::http::login> m_daemon_login;
669  std::string m_daemon_address;
670  std::string m_wallet_file;
671  std::string m_keys_file;
672  epee::net_utils::http::http_simple_client m_http_client;
673  std::vector<crypto::hash> m_blockchain;
674  std::atomic<uint64_t> m_local_bc_height; //temporary workaround
675  std::unordered_map<crypto::hash, unconfirmed_transfer_details> m_unconfirmed_txs;
676  std::unordered_map<crypto::hash, confirmed_transfer_details> m_confirmed_txs;
677  std::unordered_multimap<crypto::hash, payment_details> m_unconfirmed_payments;
678  std::unordered_map<crypto::hash, crypto::secret_key> m_tx_keys;
679 
682  std::unordered_map<crypto::key_image, size_t> m_key_images;
683  std::unordered_map<crypto::public_key, size_t> m_pub_keys;
685  std::unordered_map<crypto::hash, std::string> m_tx_notes;
686  std::vector<tools::wallet2::address_book_row> m_address_book;
687  uint64_t m_upper_transaction_size_limit; //TODO: auto-calc this value or request from daemon, now use some fixed value
688 
689  std::atomic<bool> m_run;
690 
691  boost::mutex m_daemon_rpc_mutex;
692 
694  bool m_testnet;
696  std::string seed_language;
702  uint32_t m_default_mixin;
716  std::unordered_set<crypto::hash> m_scanned_pool_txs[2];
717  };
718 }
720 BOOST_CLASS_VERSION(tools::wallet2::transfer_details, 7)
721 BOOST_CLASS_VERSION(tools::wallet2::payment_details, 1)
722 BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 6)
723 BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 4)
724 BOOST_CLASS_VERSION(tools::wallet2::address_book_row, 16)
725 BOOST_CLASS_VERSION(tools::wallet2::unsigned_tx_set, 0)
726 BOOST_CLASS_VERSION(tools::wallet2::signed_tx_set, 0)
727 BOOST_CLASS_VERSION(tools::wallet2::tx_construction_data, 0)
728 BOOST_CLASS_VERSION(tools::wallet2::pending_tx, 0)
729 
730 namespace boost
731 {
732  namespace serialization
733  {
734  template <class Archive>
735  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)
736  {
737  }
738  template <class Archive>
739  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)
740  {
741  if (ver < 1)
742  {
743  x.m_mask = rct::identity();
744  x.m_amount = x.m_tx.vout[x.m_internal_output_index].amount;
745  }
746  if (ver < 2)
747  {
748  x.m_spent_height = 0;
749  }
750  if (ver < 4)
751  {
752  x.m_rct = x.m_tx.vout[x.m_internal_output_index].amount == 0;
753  }
754  if (ver < 6)
755  {
756  x.m_key_image_known = true;
757  }
758  if (ver < 7)
759  {
760  x.m_pk_index = 0;
761  }
762  }
763 
764  template <class Archive>
765  inline void serialize(Archive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
766  {
767  a & x.m_block_height;
770  if (ver < 3)
771  {
773  a & tx;
774  x.m_tx = (const cryptonote::transaction_prefix&)tx;
776  }
777  else
778  {
779  a & x.m_tx;
780  }
781  a & x.m_spent;
782  a & x.m_key_image;
783  if (ver < 1)
784  {
785  // ensure mask and amount are set
787  return;
788  }
789  a & x.m_mask;
790  a & x.m_amount;
791  if (ver < 2)
792  {
794  return;
795  }
796  a & x.m_spent_height;
797  if (ver < 3)
798  {
800  return;
801  }
802  a & x.m_txid;
803  if (ver < 4)
804  {
806  return;
807  }
808  a & x.m_rct;
809  if (ver < 5)
810  {
812  return;
813  }
814  if (ver < 6)
815  {
816  // v5 did not properly initialize
817  uint8_t u;
818  a & u;
819  x.m_key_image_known = true;
820  return;
821  }
822  a & x.m_key_image_known;
823  if (ver < 7)
824  {
826  return;
827  }
828  a & x.m_pk_index;
829  }
830 
831  template <class Archive>
832  inline void serialize(Archive &a, tools::wallet2::unconfirmed_transfer_details &x, const boost::serialization::version_type ver)
833  {
834  a & x.m_change;
835  a & x.m_sent_time;
836  if (ver < 5)
837  {
839  a & tx;
840  x.m_tx = (const cryptonote::transaction_prefix&)tx;
841  }
842  else
843  {
844  a & x.m_tx;
845  }
846  if (ver < 1)
847  return;
848  a & x.m_dests;
849  a & x.m_payment_id;
850  if (ver < 2)
851  return;
852  a & x.m_state;
853  if (ver < 3)
854  return;
855  a & x.m_timestamp;
856  if (ver < 4)
857  return;
858  a & x.m_amount_in;
859  a & x.m_amount_out;
860  if (ver < 6)
861  {
862  // v<6 may not have change accumulated in m_amount_out, which is a pain,
863  // as it's readily understood to be sum of outputs.
864  // We convert it to include change from v6
865  if (!typename Archive::is_saving() && x.m_change != (uint64_t)-1)
866  x.m_amount_out += x.m_change;
867  }
868  }
869 
870  template <class Archive>
871  inline void serialize(Archive &a, tools::wallet2::confirmed_transfer_details &x, const boost::serialization::version_type ver)
872  {
873  a & x.m_amount_in;
874  a & x.m_amount_out;
875  a & x.m_change;
876  a & x.m_block_height;
877  if (ver < 1)
878  return;
879  a & x.m_dests;
880  a & x.m_payment_id;
881  if (ver < 2)
882  return;
883  a & x.m_timestamp;
884  if (ver < 3)
885  {
886  // v<3 may not have change accumulated in m_amount_out, which is a pain,
887  // as it's readily understood to be sum of outputs. Whether it got added
888  // or not depends on whether it came from a unconfirmed_transfer_details
889  // (not included) or not (included). We can't reliably tell here, so we
890  // check whether either yields a "negative" fee, or use the other if so.
891  // We convert it to include change from v3
892  if (!typename Archive::is_saving() && x.m_change != (uint64_t)-1)
893  {
894  if (x.m_amount_in > (x.m_amount_out + x.m_change))
895  x.m_amount_out += x.m_change;
896  }
897  }
898  if (ver < 4)
899  {
900  if (!typename Archive::is_saving())
901  x.m_unlock_time = 0;
902  return;
903  }
904  a & x.m_unlock_time;
905  }
906 
907  template <class Archive>
908  inline void serialize(Archive& a, tools::wallet2::payment_details& x, const boost::serialization::version_type ver)
909  {
910  a & x.m_tx_hash;
911  a & x.m_amount;
912  a & x.m_block_height;
913  a & x.m_unlock_time;
914  if (ver < 1)
915  return;
916  a & x.m_timestamp;
917  }
918 
919  template <class Archive>
920  inline void serialize(Archive& a, cryptonote::tx_destination_entry& x, const boost::serialization::version_type ver)
921  {
922  a & x.amount;
923  a & x.addr;
924  }
925 
926  template <class Archive>
927  inline void serialize(Archive& a, tools::wallet2::address_book_row& x, const boost::serialization::version_type ver)
928  {
929  a & x.m_address;
930  a & x.m_payment_id;
931  a & x.m_description;
932  }
933 
934  template <class Archive>
935  inline void serialize(Archive &a, tools::wallet2::unsigned_tx_set &x, const boost::serialization::version_type ver)
936  {
937  a & x.txes;
938  a & x.transfers;
939  }
940 
941  template <class Archive>
942  inline void serialize(Archive &a, tools::wallet2::signed_tx_set &x, const boost::serialization::version_type ver)
943  {
944  a & x.ptx;
945  a & x.key_images;
946  }
947 
948  template <class Archive>
949  inline void serialize(Archive &a, tools::wallet2::tx_construction_data &x, const boost::serialization::version_type ver)
950  {
951  a & x.sources;
952  a & x.change_dts;
953  a & x.splitted_dsts;
954  a & x.selected_transfers;
955  a & x.extra;
956  a & x.unlock_time;
957  a & x.use_rct;
958  a & x.dests;
959  }
960 
961  template <class Archive>
962  inline void serialize(Archive &a, tools::wallet2::pending_tx &x, const boost::serialization::version_type ver)
963  {
964  a & x.tx;
965  a & x.dust;
966  a & x.fee;
967  a & x.dust_added_to_fee;
968  a & x.change_dts;
969  a & x.selected_transfers;
970  a & x.key_images;
971  a & x.tx_key;
972  a & x.dests;
973  a & x.construction_data;
974  }
975  }
976 }
977 
978 namespace tools
979 {
980 
981  namespace detail
982  {
983  //----------------------------------------------------------------------------------------------------
984  inline void digit_split_strategy(const std::vector<cryptonote::tx_destination_entry>& dsts,
985  const cryptonote::tx_destination_entry& change_dst, uint64_t dust_threshold,
986  std::vector<cryptonote::tx_destination_entry>& splitted_dsts, std::vector<cryptonote::tx_destination_entry> &dust_dsts)
987  {
988  splitted_dsts.clear();
989  dust_dsts.clear();
990 
991  for(auto& de: dsts)
992  {
994  [&](uint64_t chunk) { splitted_dsts.push_back(cryptonote::tx_destination_entry(chunk, de.addr)); },
995  [&](uint64_t a_dust) { splitted_dsts.push_back(cryptonote::tx_destination_entry(a_dust, de.addr)); } );
996  }
997 
999  [&](uint64_t chunk) {
1000  if (chunk <= dust_threshold)
1001  dust_dsts.push_back(cryptonote::tx_destination_entry(chunk, change_dst.addr));
1002  else
1003  splitted_dsts.push_back(cryptonote::tx_destination_entry(chunk, change_dst.addr));
1004  },
1005  [&](uint64_t a_dust) { dust_dsts.push_back(cryptonote::tx_destination_entry(a_dust, change_dst.addr)); } );
1006  }
1007  //----------------------------------------------------------------------------------------------------
1008  inline void null_split_strategy(const std::vector<cryptonote::tx_destination_entry>& dsts,
1009  const cryptonote::tx_destination_entry& change_dst, uint64_t dust_threshold,
1010  std::vector<cryptonote::tx_destination_entry>& splitted_dsts, std::vector<cryptonote::tx_destination_entry> &dust_dsts)
1011  {
1012  splitted_dsts = dsts;
1013 
1014  dust_dsts.clear();
1015  uint64_t change = change_dst.amount;
1016 
1017  if (0 != change)
1018  {
1019  splitted_dsts.push_back(cryptonote::tx_destination_entry(change, change_dst.addr));
1020  }
1021  }
1022  //----------------------------------------------------------------------------------------------------
1024  {
1025  std::string indexes;
1026  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) + " "; });
1027  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);
1028  }
1029  //----------------------------------------------------------------------------------------------------
1030  }
1031  //----------------------------------------------------------------------------------------------------
1032  template<typename T>
1033  void wallet2::transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, const size_t fake_outs_count, const std::vector<size_t> &unused_transfers_indices,
1034  uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, bool trusted_daemon)
1035  {
1036  pending_tx ptx;
1038  transfer(dsts, fake_outs_count, unused_transfers_indices, unlock_time, fee, extra, destination_split_strategy, dust_policy, tx, ptx, trusted_daemon);
1039  }
1040 
1041  template<typename T>
1042  void wallet2::transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, size_t fake_outputs_count, const std::vector<size_t> &unused_transfers_indices,
1043  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, bool trusted_daemon)
1044  {
1045  using namespace cryptonote;
1046  // throw if attempting a transaction with no destinations
1048 
1049  uint64_t upper_transaction_size_limit = get_upper_transaction_size_limit();
1050  uint64_t needed_money = fee;
1051 
1052  // calculate total amount being sent to all destinations
1053  // throw if total amount overflows uint64_t
1054  for(auto& dt: dsts)
1055  {
1057  needed_money += dt.amount;
1058  THROW_WALLET_EXCEPTION_IF(needed_money < dt.amount, error::tx_sum_overflow, dsts, fee, m_testnet);
1059  }
1060 
1061  // randomly select inputs for transaction
1062  // throw if requested send amount is greater than amount available to send
1063  std::list<size_t> selected_transfers;
1064  uint64_t found_money = select_transfers(needed_money, unused_transfers_indices, selected_transfers, trusted_daemon);
1065  THROW_WALLET_EXCEPTION_IF(found_money < needed_money, error::not_enough_money, found_money, needed_money - fee, fee);
1066 
1068  typedef cryptonote::tx_source_entry::output_entry tx_output_entry;
1069 
1070  COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response daemon_resp = AUTO_VAL_INIT(daemon_resp);
1071  if(fake_outputs_count)
1072  {
1073  COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request req = AUTO_VAL_INIT(req);
1074  req.outs_count = fake_outputs_count + 1;// add one to make possible (if need) to skip real output key
1075  for(size_t idx: selected_transfers)
1076  {
1077  const transfer_container::const_iterator it = m_transfers.begin() + idx;
1078  THROW_WALLET_EXCEPTION_IF(it->m_tx.vout.size() <= it->m_internal_output_index, error::wallet_internal_error,
1079  "m_internal_output_index = " + std::to_string(it->m_internal_output_index) +
1080  " is greater or equal to outputs count = " + std::to_string(it->m_tx.vout.size()));
1081  req.amounts.push_back(it->amount());
1082  }
1083 
1084  m_daemon_rpc_mutex.lock();
1085  bool r = epee::net_utils::invoke_http_bin("/getrandom_outs.bin", req, daemon_resp, m_http_client, rpc_timeout);
1086  m_daemon_rpc_mutex.unlock();
1087  THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "getrandom_outs.bin");
1088  THROW_WALLET_EXCEPTION_IF(daemon_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "getrandom_outs.bin");
1090  THROW_WALLET_EXCEPTION_IF(daemon_resp.outs.size() != selected_transfers.size(), error::wallet_internal_error,
1091  "daemon returned wrong response for getrandom_outs.bin, wrong amounts count = " +
1092  std::to_string(daemon_resp.outs.size()) + ", expected " + std::to_string(selected_transfers.size()));
1093 
1094  std::unordered_map<uint64_t, uint64_t> scanty_outs;
1096  {
1097  if (amount_outs.outs.size() < fake_outputs_count)
1098  {
1099  scanty_outs[amount_outs.amount] = amount_outs.outs.size();
1100  }
1101  }
1102  THROW_WALLET_EXCEPTION_IF(!scanty_outs.empty(), error::not_enough_outs_to_mix, scanty_outs, fake_outputs_count);
1103  }
1104 
1105  //prepare inputs
1106  size_t i = 0;
1107  std::vector<cryptonote::tx_source_entry> sources;
1108  for(size_t idx: selected_transfers)
1109  {
1110  sources.resize(sources.size()+1);
1111  cryptonote::tx_source_entry& src = sources.back();
1112  const transfer_details& td = m_transfers[idx];
1113  src.amount = td.amount();
1114  src.rct = false;
1115  //paste mixin transaction
1116  if(daemon_resp.outs.size())
1117  {
1118  daemon_resp.outs[i].outs.sort([](const out_entry& a, const out_entry& b){return a.global_amount_index < b.global_amount_index;});
1119  for(out_entry& daemon_oe: daemon_resp.outs[i].outs)
1120  {
1121  if(td.m_global_output_index == daemon_oe.global_amount_index)
1122  continue;
1123  tx_output_entry oe;
1124  oe.first = daemon_oe.global_amount_index;
1125  oe.second.dest = rct::pk2rct(daemon_oe.out_key);
1126  oe.second.mask = rct::identity();
1127  src.outputs.push_back(oe);
1128  if(src.outputs.size() >= fake_outputs_count)
1129  break;
1130  }
1131  }
1132 
1133  //paste real transaction to the random index
1134  auto it_to_insert = std::find_if(src.outputs.begin(), src.outputs.end(), [&](const tx_output_entry& a)
1135  {
1136  return a.first >= td.m_global_output_index;
1137  });
1138  //size_t real_index = src.outputs.size() ? (rand() % src.outputs.size() ):0;
1139  tx_output_entry real_oe;
1140  real_oe.first = td.m_global_output_index;
1141  real_oe.second.dest = rct::pk2rct(boost::get<txout_to_key>(td.m_tx.vout[td.m_internal_output_index].target).key);
1142  real_oe.second.mask = rct::identity();
1143  auto interted_it = src.outputs.insert(it_to_insert, real_oe);
1145  src.real_output = interted_it - src.outputs.begin();
1148  ++i;
1149  }
1150 
1151  cryptonote::tx_destination_entry change_dts = AUTO_VAL_INIT(change_dts);
1152  if (needed_money < found_money)
1153  {
1154  change_dts.addr = m_account.get_keys().m_account_address;
1155  change_dts.amount = found_money - needed_money;
1156  }
1157 
1158  std::vector<cryptonote::tx_destination_entry> splitted_dsts, dust_dsts;
1159  uint64_t dust = 0;
1160  destination_split_strategy(dsts, change_dts, dust_policy.dust_threshold, splitted_dsts, dust_dsts);
1161  for(auto& d: dust_dsts) {
1162  THROW_WALLET_EXCEPTION_IF(dust_policy.dust_threshold < d.amount, error::wallet_internal_error, "invalid dust value: dust = " +
1163  std::to_string(d.amount) + ", dust_threshold = " + std::to_string(dust_policy.dust_threshold));
1164  }
1165  for(auto& d: dust_dsts) {
1166  if (!dust_policy.add_to_fee)
1167  splitted_dsts.push_back(cryptonote::tx_destination_entry(d.amount, dust_policy.addr_for_dust));
1168  dust += d.amount;
1169  }
1170 
1171  crypto::secret_key tx_key;
1172  bool r = cryptonote::construct_tx_and_get_tx_key(m_account.get_keys(), sources, splitted_dsts, extra, tx, unlock_time, tx_key);
1173  THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time, m_testnet);
1174  THROW_WALLET_EXCEPTION_IF(upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, upper_transaction_size_limit);
1175 
1176  std::string key_images;
1177  bool all_are_txin_to_key = std::all_of(tx.vin.begin(), tx.vin.end(), [&](const txin_v& s_e) -> bool
1178  {
1179  CHECKED_GET_SPECIFIC_VARIANT(s_e, const txin_to_key, in, false);
1180  key_images += boost::to_string(in.k_image) + " ";
1181  return true;
1182  });
1183  THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, tx);
1184 
1185  bool dust_sent_elsewhere = (dust_policy.addr_for_dust.m_view_public_key != change_dts.addr.m_view_public_key
1186  || dust_policy.addr_for_dust.m_spend_public_key != change_dts.addr.m_spend_public_key);
1187 
1188  if (dust_policy.add_to_fee || dust_sent_elsewhere) change_dts.amount -= dust;
1189 
1190  ptx.key_images = key_images;
1191  ptx.fee = (dust_policy.add_to_fee ? fee+dust : fee);
1192  ptx.dust = ((dust_policy.add_to_fee || dust_sent_elsewhere) ? dust : 0);
1193  ptx.dust_added_to_fee = dust_policy.add_to_fee;
1194  ptx.tx = tx;
1195  ptx.change_dts = change_dts;
1196  ptx.selected_transfers = selected_transfers;
1197  ptx.tx_key = tx_key;
1198  ptx.dests = dsts;
1199  ptx.construction_data.sources = sources;
1200  ptx.construction_data.change_dts = change_dts;
1201  ptx.construction_data.splitted_dsts = splitted_dsts;
1202  ptx.construction_data.selected_transfers = selected_transfers;
1203  ptx.construction_data.extra = tx.extra;
1204  ptx.construction_data.unlock_time = unlock_time;
1205  ptx.construction_data.use_rct = false;
1206  ptx.construction_data.dests = dsts;
1207  }
1208 
1209 
1210 }
void transfer_selected(const std::vector< cryptonote::tx_destination_entry > &dsts, const std::list< 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::list< size_t > selected_transfers
Definition: wallet2.h:217
bool watch_only() const
Definition: wallet2.h:390
uint64_t unlock_time
Definition: wallet2.h:219
static bool parse_long_payment_id(const std::string &payment_id_str, crypto::hash &payment_id)
Definition: wallet2.cpp:2444
void rescan_spent()
Definition: wallet2.cpp:2830
Definition: binary_utils.h:37
bool display_progress_indicator() const
Definition: wallet2.h:545
void process_new_blockchain_entry(const cryptonote::block &b, const cryptonote::block_complete_entry &bche, const crypto::hash &bl_id, uint64_t height, const cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices &o_indices)
Definition: wallet2.cpp:1155
epee::net_utils::http::http_simple_client m_http_client
Definition: wallet2.h:672
std::vector< crypto::key_image > key_images
Definition: wallet2.h:255
void fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list< crypto::hash > &short_chain_history)
Definition: wallet2.cpp:1665
void set_unspent(size_t idx)
Definition: wallet2.cpp:595
void rewrite(const std::string &wallet_name, const std::string &password)
Rewrites to the wallet file for wallet upgrade (doesn't generate key, assumes it's already there)
Definition: wallet2.cpp:2405
cryptonote::transaction tx
Definition: wallet2.h:232
Definition: wallet_errors.h:446
bool generate_chacha8_key_from_secret_keys(crypto::chacha8_key &key) const
Definition: wallet2.cpp:2534
bool m_always_confirm_transfers
Definition: wallet2.h:699
void callback(i_wallet2_callback *callback)
Definition: wallet2.h:361
uint64_t get_dynamic_per_kb_fee_estimate()
Definition: wallet2.cpp:3555
Definition: wallet2.h:252
const boost::optional< epee::net_utils::http::login > & get_daemon_login() const
Definition: wallet2.h:567
const uint32_t T[512]
Definition: groestl_tables.h:34
bool testnet() const
Definition: wallet2.h:388
Definition: wallet_errors.h:660
std::string cache_data
Definition: wallet2.h:272
std::vector< size_t > select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool allow_rct, bool trusted_daemon)
Definition: wallet2.cpp:4978
crypto::public_key real_out_tx_key
Definition: cryptonote_tx_utils.h:49
Definition: core_rpc_server_commands_defs.h:339
crypto::public_key get_tx_pub_key_from_received_outs(const tools::wallet2::transfer_details &td) const
Definition: wallet2.cpp:5220
std::atomic< bool > m_run
Definition: wallet2.h:689
void store_to(const std::string &path, const std::string &password)
store_to - stores wallet to another file(s), deleting old ones
Definition: wallet2.cpp:2663
crypto::secret_key generate(const std::string &wallet, const std::string &password, const crypto::secret_key &recovery_param=crypto::secret_key(), bool recover=false, bool two_random=false)
Generates a wallet or restores one.
Definition: wallet2.cpp:2263
uint64_t m_block_height
Definition: wallet2.h:178
Definition: wallet_errors.h:416
void get_hard_fork_info(uint8_t version, uint64_t &earliest_height)
Definition: wallet2.cpp:4915
bool add_address_book_row(const cryptonote::account_public_address &address, const crypto::hash &payment_id, const std::string &description)
Definition: wallet2.cpp:1721
uint64_t m_unlock_time
Definition: wallet2.h:179
size_t pop_best_value_from(const transfer_container &transfers, std::vector< size_t > &unused_dust_indices, const std::list< size_t > &selected_transfers, bool smallest=false) const
Definition: wallet2.cpp:3014
void commit_tx(pending_tx &ptx_vector)
Definition: wallet2.cpp:3212
bool is_old_file_format
Definition: wallet2.h:697
Definition: unordered_containers_boost_serialization.h:38
const std::string & get_seed_language() const
Gets the seed language.
Definition: wallet2.cpp:567
void pull_next_blocks(uint64_t start_height, uint64_t &blocks_start_height, std::list< crypto::hash > &short_chain_history, const std::list< cryptonote::block_complete_entry > &prev_blocks, std::list< cryptonote::block_complete_entry > &blocks, std::vector< cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices > &o_indices, bool &error)
Definition: wallet2.cpp:1418
uint64_t m_change
Definition: wallet2.h:200
size_t import_outputs(const std::vector< tools::wallet2::transfer_details > &outputs)
Definition: wallet2.cpp:5495
bool m_ask_password
Definition: wallet2.h:708
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)
Definition: wallet2.cpp:3358
Definition: wallet2.h:95
Definition: node_rpc_proxy.h:40
bool dust_added_to_fee
Definition: wallet2.h:234
static void wallet_exists(const std::string &file_path, bool &keys_file_exists, bool &wallet_file_exists)
Check if wallet keys and bin files exist.
Definition: wallet2.cpp:2429
void confirm_missing_payment_id(bool always)
Definition: wallet2.h:532
Definition: wallet2.h:174
Definition: cryptonote_basic.h:422
void default_mixin(uint32_t m)
Definition: wallet2.h:526
uint64_t get_approximate_blockchain_height() const
Calculates the approximate blockchain height from current date/time.
Definition: wallet2.cpp:5160
void parse_block_round(const cryptonote::blobdata &blob, cryptonote::block &bl, crypto::hash &bl_id, bool &error) const
Definition: wallet2.cpp:1223
Definition: cryptonote_protocol_defs.h:110
static const unsigned char iv[64]
Definition: sha512-hash.c:13
uint64_t balance() const
Definition: wallet2.cpp:2764
std::vector< cryptonote::tx_destination_entry > dests
Definition: wallet2.h:239
#define CHECKED_GET_SPECIFIC_VARIANT(variant_var, specific_type, variable_name, fail_return_val)
Definition: cryptonote_format_utils.h:216
void auto_refresh(bool r)
Definition: wallet2.h:530
void get_payments_out(std::list< std::pair< crypto::hash, wallet2::confirmed_transfer_details >> &confirmed_payments, uint64_t min_height, uint64_t max_height=(uint64_t) -1) const
Definition: wallet2.cpp:2806
void get_unconfirmed_payments(std::list< std::pair< crypto::hash, wallet2::payment_details >> &unconfirmed_payments) const
Definition: wallet2.cpp:2823
POD_CLASS key_derivation
Definition: crypto.h:82
Definition: cryptonote_basic.h:372
unsigned int get_default_decimal_point() const
Definition: wallet2.cpp:2489
void merge_destinations(bool merge)
Definition: wallet2.h:541
std::string path() const
Definition: wallet2.cpp:2653
bool is_transfer_unlocked(const transfer_details &td) const
Definition: wallet2.cpp:2896
void pull_blocks(uint64_t start_height, uint64_t &blocks_start_height, const std::list< crypto::hash > &short_chain_history, std::list< cryptonote::block_complete_entry > &blocks, std::vector< cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices > &o_indices)
Definition: wallet2.cpp:1230
size_t get_object_blobsize(const t_object &o)
Definition: cryptonote_format_utils.h:139
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)
Definition: wallet2.cpp:5638
static bool verify_password(const std::string &keys_file_name, const std::string &password, bool watch_only)
verify password for specified wallet keys file.
Definition: wallet2.cpp:2215
std::string sign(const std::string &data) const
Definition: wallet2.cpp:5187
static constexpr const std::chrono::seconds rpc_timeout
Definition: wallet2.h:99
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:166
Definition: core_rpc_server_commands_defs.h:321
Definition: wallet_errors.h:128
uint64_t height
Definition: blockchain.cpp:87
void process_unconfirmed(const crypto::hash &txid, const cryptonote::transaction &tx, uint64_t height)
Definition: wallet2.cpp:1103
void stop()
Definition: wallet2.h:358
#define CORE_RPC_STATUS_BUSY
Definition: core_rpc_server_commands_defs.h:42
bool save_tx(const std::vector< pending_tx > &ptx_vector, const std::string &filename)
Definition: wallet2.cpp:3275
uint64_t dust
Definition: wallet2.h:233
const cryptonote::account_base & get_account() const
Definition: wallet2.h:344
bool is_synced() const
Definition: wallet2.cpp:5810
std::string key_images
Definition: wallet2.h:237
uint64_t m_timestamp
Definition: wallet2.h:180
std::string get_daemon_address() const
Definition: wallet2.cpp:5108
bool m_restricted
Definition: wallet2.h:695
rct::key m_mask
Definition: wallet2.h:147
std::vector< pending_tx > ptx
Definition: wallet2.h:254
cryptonote::tx_destination_entry change_dts
Definition: wallet2.h:215
static const crypto::hash null_hash
Definition: cryptonote_basic.h:58
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)
Definition: wallet2.h:76
void print_source_entry(const cryptonote::tx_source_entry &src)
Definition: wallet2.h:1023
void store_tx_info(bool store)
Definition: wallet2.h:524
void get_payments(const crypto::hash &payment_id, std::list< wallet2::payment_details > &payments, uint64_t min_height=0) const
Definition: wallet2.cpp:2784
std::vector< pending_tx > create_transactions(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, bool trusted_daemon)
Definition: wallet2.cpp:3594
crypto::hash m_txid
Definition: wallet2.h:141
static std::pair< std::unique_ptr< wallet2 >, password_container > make_from_file(const boost::program_options::variables_map &vm, const std::string &wallet_file)
Uses stdin and stdout. Returns a wallet2 and password for wallet_file if no errors.
Definition: wallet2.cpp:491
std::string get_keys_file() const
Definition: wallet2.cpp:5103
uint64_t m_min_output_value
Definition: wallet2.h:710
cryptonote::account_public_address m_address
Definition: wallet2.h:283
Definition: wallet2.h:81
uint64_t m_timestamp
Definition: wallet2.h:204
void rescan_blockchain(bool refresh=true)
Definition: wallet2.cpp:2882
Definition: cryptonote_basic.h:83
std::vector< cryptonote::tx_destination_entry > m_dests
Definition: wallet2.h:202
uint64_t get_per_kb_fee()
Definition: wallet2.cpp:3565
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)
Definition: wallet2.cpp:3450
void pull_hashes(uint64_t start_height, uint64_t &blocks_start_height, const std::list< crypto::hash > &short_chain_history, std::list< crypto::hash > &hashes)
Definition: wallet2.cpp:1280
uint64_t m_amount_out
Definition: wallet2.h:187
std::string account_data
Definition: wallet2.h:261
std::unordered_multimap< crypto::hash, payment_details > payment_container
Definition: wallet2.h:225
crypto::hash m_tx_hash
Definition: wallet2.h:176
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:1008
Definition: wallet_errors.h:160
bool rct
Definition: cryptonote_tx_utils.h:52
bool check_connection(uint32_t *version=NULL, uint32_t timeout=200000)
Definition: wallet2.cpp:2500
uint32_t m_default_mixin
Definition: wallet2.h:702
Definition: wallet_errors.h:582
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)
Definition: wallet2.cpp:3087
tools::wallet2::RefreshType refresh_type
Definition: simplewallet.cpp:182
uint64_t amount
Definition: cryptonote_tx_utils.h:51
std::string m_daemon_address
Definition: wallet2.h:669
std::vector< size_t > pick_preferred_rct_inputs(uint64_t needed_money) const
Definition: wallet2.cpp:4272
cryptonote::account_public_address addr_for_dust
Definition: wallet2.h:85
bool m_merge_destinations
Definition: wallet2.h:711
Definition: d.py:1
bool clear()
Definition: wallet2.cpp:1924
std::unordered_map< crypto::hash, confirmed_transfer_details > m_confirmed_txs
Definition: wallet2.h:676
uint64_t m_amount_in
Definition: wallet2.h:198
std::string get_tx_note(const crypto::hash &txid) const
Definition: wallet2.cpp:5179
bool add_to_fee
Definition: wallet2.h:84
void confirm_backlog(bool always)
Definition: wallet2.h:544
size_t real_output
Definition: cryptonote_tx_utils.h:48
std::unordered_map< crypto::hash, crypto::secret_key > m_tx_keys
Definition: wallet2.h:678
bool print_ring_members() const
Definition: wallet2.h:521
void set_seed_language(const std::string &language)
Sets the seed language.
Definition: wallet2.cpp:575
uint64_t unlocked_dust_balance(const tx_dust_policy &dust_policy) const
Definition: wallet2.cpp:4900
RefreshType
Definition: wallet2.h:101
#define CORE_RPC_STATUS_OK
Definition: core_rpc_server_commands_defs.h:41
float get_output_relatedness(const transfer_details &td0, const transfer_details &td1) const
Definition: wallet2.cpp:2987
Definition: wallet2.h:70
bool always_confirm_transfers() const
Definition: wallet2.h:519
#define END_SERIALIZE()
self-explanatory
Definition: serialization.h:205
std::vector< cryptonote::tx_destination_entry > m_dests
Definition: wallet2.h:190
std::vector< cryptonote::tx_source_entry > sources
Definition: wallet2.h:214
std::atomic< uint64_t > m_local_bc_height
Definition: wallet2.h:674
std::vector< std::pair< crypto::key_image, crypto::signature > > export_key_images() const
Definition: wallet2.cpp:5288
const account_keys & get_keys() const
Definition: account.cpp:127
void load(const std::string &wallet, const std::string &password)
Definition: wallet2.cpp:2548
uint64_t unlocked_balance() const
Definition: wallet2.cpp:2754
static const rct::key pk2rct(const crypto::public_key &pk)
Definition: rctTypes.h:428
std::unordered_multimap< crypto::hash, payment_details > m_unconfirmed_payments
Definition: wallet2.h:677
Definition: cryptonote_basic.h:162
BOOST_CLASS_VERSION(nodetool::node_server< cryptonote::t_cryptonote_protocol_handler< cryptonote::core > >, 1)
std::vector< tx_out > vout
Definition: cryptonote_basic.h:171
crypto::chacha8_iv iv
Definition: wallet2.h:271
bool is_deprecated() const
Tells if the wallet file is deprecated.
Definition: wallet2.cpp:582
std::vector< tx_construction_data > txes
Definition: wallet2.h:248
Holds cryptonote related classes and helpers.
Definition: db_bdb.cpp:225
uint64_t select_transfers(uint64_t needed_money, std::vector< size_t > unused_transfers_indices, std::list< size_t > &selected_transfers, bool trusted_daemon)
Definition: wallet2.cpp:3072
bool m_testnet
Definition: wallet2.h:694
std::vector< tools::wallet2::address_book_row > m_address_book
Definition: wallet2.h:686
virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction &tx)
Definition: wallet2.h:77
Definition: core_rpc_server_commands_defs.h:310
NodeRPCProxy m_node_rpc_proxy
Definition: wallet2.h:715
std::unordered_map< crypto::public_key, size_t > m_pub_keys
Definition: wallet2.h:683
size_t m_pk_index
Definition: wallet2.h:151
i_wallet2_callback * m_callback
Definition: wallet2.h:693
uint64_t amount() const
Definition: wallet2.h:154
void detach_blockchain(uint64_t height)
Definition: wallet2.cpp:1862
bool m_confirm_backlog
Definition: wallet2.h:712
crypto::public_key m_spend_public_key
Definition: cryptonote_basic.h:408
bool m_key_image_known
Definition: wallet2.h:150
Definition: wallet2.h:212
void get_outs(std::vector< std::vector< get_outs_entry >> &outs, const std::list< size_t > &selected_transfers, size_t fake_outputs_count)
Definition: wallet2.cpp:3698
std::vector< crypto::hash > m_blockchain
Definition: wallet2.h:673
void set_refresh_type(RefreshType refresh_type)
Definition: wallet2.h:385
Definition: wallet2.h:102
std::vector< transfer_details > transfer_container
Definition: wallet2.h:224
uint64_t m_amount_out
Definition: wallet2.h:199
uint64_t amount
Definition: core_rpc_server_commands_defs.h:330
declaration and default definition for the functions used the API
std::vector< size_t > select_available_mixable_outputs(bool trusted_daemon)
Definition: wallet2.cpp:5054
std::vector< uint64_t > amounts
Definition: core_rpc_server_commands_defs.h:312
crypto::public_key m_view_public_key
Definition: cryptonote_basic.h:409
std::vector< pending_tx > create_unmixable_sweep_transactions(bool trusted_daemon)
Definition: wallet2.cpp:5059
bool wallet_generate_key_image_helper(const cryptonote::account_keys &ack, const crypto::public_key &tx_public_key, size_t real_output_index, cryptonote::keypair &in_ephemeral, crypto::key_image &ki)
Definition: wallet2.cpp:664
crypto::hash m_payment_id
Definition: wallet2.h:191
bool is_tx_spendtime_unlocked(uint64_t unlock_time, uint64_t block_height) const
Definition: wallet2.cpp:2907
std::unordered_set< crypto::hash > m_scanned_pool_txs[2]
Definition: wallet2.h:716
size_t m_internal_output_index
Definition: wallet2.h:142
uint32_t get_min_output_count() const
Definition: wallet2.h:538
uint64_t outs_count
Definition: core_rpc_server_commands_defs.h:313
uint32_t m_min_output_count
Definition: wallet2.h:709
uint64_t m_timestamp
Definition: wallet2.h:193
bool auto_refresh() const
Definition: wallet2.h:529
Definition: wallet_errors.h:152
Various Tools.
Definition: base58.cpp:43
boost::optional< epee::net_utils::http::login > m_daemon_login
Definition: wallet2.h:668
confirmed_transfer_details(const unconfirmed_transfer_details &utd, uint64_t height)
Definition: wallet2.h:208
uint64_t m_global_output_index
Definition: wallet2.h:143
wallet2::transfer_container transfers
Definition: wallet2.h:249
void set_tx_note(const crypto::hash &txid, const std::string &note)
Definition: wallet2.cpp:5174
Definition: cryptonote_tx_utils.h:43
Definition: account.h:57
uint64_t m_unlock_time
Definition: wallet2.h:205
uint64_t get_refresh_from_block_height() const
Definition: wallet2.h:347
uint64_t get_min_output_value() const
Definition: wallet2.h:540
Definition: wallet2.h:105
bool load_keys(const std::string &keys_file_name, const std::string &password)
Load wallet information from wallet file.
Definition: wallet2.cpp:2065
Definition: rctTypes.h:82
#define ts
Definition: skein.c:522
int b
Definition: base.py:1
void process_blocks(uint64_t start_height, const std::list< cryptonote::block_complete_entry > &blocks, const std::vector< cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices > &o_indices, uint64_t &blocks_added)
Definition: wallet2.cpp:1298
std::vector< cryptonote::tx_destination_entry > splitted_dsts
Definition: wallet2.h:216
void write_watch_only_wallet(const std::string &wallet_name, const std::string &password)
Writes to a file named based on the normal wallet (doesn't generate key, assumes it's already there)
Definition: wallet2.cpp:2418
std::string encrypt(const std::string &plaintext, const crypto::secret_key &skey, bool authenticated=true) const
Definition: wallet2.cpp:5526
Definition: cryptonote_basic.h:130
crypto::hash8 get_short_payment_id(const pending_tx &ptx) const
Definition: wallet2.cpp:3193
#define BEGIN_SERIALIZE_OBJECT()
begins the environment of the DSL \detailed for described the serialization of an object
Definition: serialization.h:186
bool get_seed(std::string &electrum_words) const
Definition: wallet2.cpp:546
void generate_genesis(cryptonote::block &b)
Definition: wallet2.cpp:5883
uint64_t get_upper_transaction_size_limit()
Definition: wallet2.cpp:4937
Definition: password.h:39
crypto::public_key get_tx_pub_key_from_extra(const std::vector< uint8_t > &tx_extra, size_t pk_index)
Definition: cryptonote_format_utils.cpp:251
bool store_tx_info() const
Definition: wallet2.h:523
std::string status
Definition: core_rpc_server_commands_defs.h:342
cryptonote::transaction_prefix m_tx
Definition: wallet2.h:140
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
Definition: wallet2.cpp:4332
uint64_t amount
Definition: cryptonote_tx_utils.h:60
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:87
void get_short_chain_history(std::list< crypto::hash > &ids) const
Definition: wallet2.cpp:1196
std::list< size_t > selected_transfers
Definition: wallet2.h:236
#define false
Definition: stdbool.h:38
std::string m_wallet_file
Definition: wallet2.h:670
std::string seed_language
Definition: wallet2.h:696
std::string decrypt_with_view_secret_key(const std::string &ciphertext, bool authenticated=true) const
Definition: wallet2.cpp:5577
std::string get_wallet_file() const
Definition: wallet2.cpp:5098
uint64_t m_block_height
Definition: wallet2.h:139
static void init_options(boost::program_options::options_description &desc_params)
Definition: wallet2.cpp:460
void check_acc_out_precomp_once(const crypto::public_key &spend_public_key, const cryptonote::tx_out &o, const crypto::key_derivation &derivation, size_t i, bool &received, uint64_t &money_transfered, bool &error, bool &already_seen) const
Definition: wallet2.cpp:623
std::vector< tools::wallet2::transfer_details > export_outputs() const
Definition: wallet2.cpp:5480
void display_progress_indicator(bool always)
Definition: wallet2.h:546
std::vector< uint8_t > extra
Definition: wallet2.h:218
Definition: account.h:41
std::tuple< uint64_t, crypto::public_key, rct::key > get_outs_entry
Definition: wallet2.h:288
void store()
Definition: wallet2.cpp:2658
void check_acc_out_precomp(const crypto::public_key &spend_public_key, const cryptonote::tx_out &o, const crypto::key_derivation &derivation, size_t i, bool &received, uint64_t &money_transfered, bool &error) const
Definition: wallet2.cpp:603
crypto::hash get_payment_id(const pending_tx &ptx) const
Definition: wallet2.cpp:3168
uint64_t import_key_images(const std::vector< std::pair< crypto::key_image, crypto::signature >> &signed_key_images, uint64_t &spent, uint64_t &unspent)
Definition: wallet2.cpp:5402
tx_construction_data construction_data
Definition: wallet2.h:241
size_t pop_best_value(std::vector< size_t > &unused_dust_indices, const std::list< size_t > &selected_transfers, bool smallest=false) const
Definition: wallet2.cpp:3063
POD_CLASS public_key
Definition: crypto.h:58
uint64_t get_num_rct_outputs()
Definition: wallet2.cpp:5019
bool deinit()
Definition: wallet2.cpp:1918
static bool wallet_valid_path_format(const std::string &file_path)
Check if wallet file path is valid format.
Definition: wallet2.cpp:2439
cryptonote::account_base m_account
Definition: wallet2.h:667
bool m_display_progress_indicator
Definition: wallet2.h:713
bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key) const
Definition: wallet2.cpp:5089
bool m_store_tx_info
Definition: wallet2.h:701
bool ask_password() const
Definition: wallet2.h:533
crypto::chacha8_iv iv
Definition: wallet2.h:260
std::vector< uint64_t > get_unspent_amounts_vector()
Definition: wallet2.cpp:4961
static bool parse_short_payment_id(const std::string &payment_id_str, crypto::hash8 &payment_id)
Definition: wallet2.cpp:2457
void set_refresh_from_block_height(uint64_t height)
Definition: wallet2.h:346
uint8_t version
Definition: blockchain.cpp:86
Definition: wallet2.h:246
payment_container m_payments
Definition: wallet2.h:681
void set_min_output_value(uint64_t value)
Definition: wallet2.h:539
std::string m_keys_file
Definition: wallet2.h:671
bool m_watch_only
Definition: wallet2.h:698
std::string m_description
Definition: wallet2.h:285
account_public_address addr
Definition: cryptonote_tx_utils.h:61
cryptonote::transaction_prefix m_tx
Definition: wallet2.h:185
std::string blobdata
Definition: blobdatatype.h:36
const transfer_details & get_transfer_details(size_t idx) const
Definition: wallet2.cpp:5041
virtual void on_new_block(uint64_t height, const cryptonote::block &block)
Definition: wallet2.h:73
#define blocks
Definition: sha512-hash.c:11
bool confirm_backlog() const
Definition: wallet2.h:543
bool is_deterministic() const
Checks if deterministic wallet.
Definition: wallet2.cpp:537
account_public_address m_account_address
Definition: account.h:43
uint64_t get_daemon_blockchain_height(std::string &err)
Definition: wallet2.cpp:5113
bool use_fork_rules(uint8_t version, int64_t early_blocks=0)
Definition: wallet2.cpp:4921
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:984
POD_CLASS signature
Definition: crypto.h:92
void process_new_transaction(const crypto::hash &txid, const cryptonote::transaction &tx, const std::vector< uint64_t > &o_indices, uint64_t height, uint64_t ts, bool miner_tx, bool pool)
Definition: wallet2.cpp:671
Definition: wallet_errors.h:610
Definition: wallet2.h:269
Definition: cryptonote_basic.h:406
cryptonote::account_public_address m_account_public_address
Definition: wallet2.h:684
Definition: wallet_errors.h:652
key identity()
Definition: rctOps.h:75
void set_default_decimal_point(unsigned int decimal_point)
Definition: wallet2.cpp:2484
POD_CLASS hash8
Definition: hash.h:49
bool restricted() const
Definition: wallet2.h:389
uint64_t m_block_height
Definition: wallet2.h:201
Definition: wallet_errors.h:360
crypto::public_key key
Definition: cryptonote_basic.h:87
void transfer(const std::vector< cryptonote::tx_destination_entry > &dsts, const size_t fake_outputs_count, const std::vector< size_t > &unused_transfers_indices, uint64_t unlock_time, uint64_t fee, const std::vector< uint8_t > &extra, T destination_split_strategy, const tx_dust_policy &dust_policy, bool trusted_daemon)
Definition: wallet2.h:1033
bool prepare_file_names(const std::string &file_path)
Definition: wallet2.cpp:2494
bool m_rct
Definition: wallet2.h:149
void check_genesis(const crypto::hash &genesis_hash) const
Definition: wallet2.cpp:2647
POD_CLASS key_image
Definition: crypto.h:86
virtual void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction &tx, uint64_t amount)
Definition: wallet2.h:75
bool confirm_missing_payment_id() const
Definition: wallet2.h:531
uint64_t get_blockchain_height_by_date(uint16_t year, uint8_t month, uint8_t day)
Definition: wallet2.cpp:5724
static const char * tr(const char *str)
Definition: wallet2.cpp:453
void process_outgoing(const crypto::hash &txid, const cryptonote::transaction &tx, uint64_t height, uint64_t ts, uint64_t spent, uint64_t received)
Definition: wallet2.cpp:1123
bool merge_destinations() const
Definition: wallet2.h:542
POD_CLASS secret_key
Definition: crypto.h:62
#define THROW_WALLET_EXCEPTION_IF(cond, err_type,...)
Definition: wallet_errors.h:742
uint64_t m_change
Definition: wallet2.h:188
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)
Definition: wallet2.cpp:5582
i_wallet2_callback * callback() const
Definition: wallet2.h:360
txout_target_v target
Definition: cryptonote_basic.h:152
std::vector< cryptonote::tx_destination_entry > dests
Definition: wallet2.h:221
std::unordered_map< crypto::hash, std::string > m_tx_notes
Definition: wallet2.h:685
crypto::hash m_payment_id
Definition: wallet2.h:284
size_t real_output_in_tx_index
Definition: cryptonote_tx_utils.h:50
string a
Definition: MakeCryptoOps.py:15
static bool has_testnet_option(const boost::program_options::variables_map &vm)
Definition: wallet2.cpp:455
crypto::hash get_transaction_hash(const transaction &t)
Definition: cryptonote_format_utils.cpp:583
std::vector< outs_for_amount > outs
Definition: core_rpc_server_commands_defs.h:341
void always_confirm_transfers(bool always)
Definition: wallet2.h:520
bool construct_tx_and_get_tx_key(const account_keys &sender_account_keys, const std::vector< tx_source_entry > &sources, const std::vector< tx_destination_entry > &destinations, std::vector< uint8_t > extra, transaction &tx, uint64_t unlock_time, crypto::secret_key &tx_key, bool rct)
Definition: cryptonote_tx_utils.cpp:160
confirmed_transfer_details()
Definition: wallet2.h:207
bool store_keys(const std::string &keys_file_name, const std::string &password, bool watch_only=false)
Stores wallet information to wallet file.
Definition: wallet2.cpp:1949
void set_spent(size_t idx, uint64_t height)
Definition: wallet2.cpp:587
bool verify(const std::string &data, const cryptonote::account_public_address &address, const std::string &signature) const
Definition: wallet2.cpp:5197
wallet2(bool testnet=false, bool restricted=false)
Definition: wallet2.h:135
uint64_t m_refresh_from_block_height
Definition: wallet2.h:706
crypto::key_image m_key_image
Definition: wallet2.h:146
bool init(std::string daemon_address="http://localhost:8080", boost::optional< epee::net_utils::http::login > daemon_login=boost::none, uint64_t upper_transaction_size_limit=0)
Definition: wallet2.cpp:526
std::vector< output_entry > outputs
Definition: cryptonote_tx_utils.h:47
std::vector< address_book_row > get_address_book() const
GUI Address book get/store.
Definition: wallet2.h:553
std::vector< size_t > select_available_unmixable_outputs(bool trusted_daemon)
Definition: wallet2.cpp:5047
RefreshType get_refresh_type() const
Definition: wallet2.h:386
Definition: cryptonote_tx_utils.h:58
void get_unconfirmed_payments_out(std::list< std::pair< crypto::hash, wallet2::unconfirmed_transfer_details >> &unconfirmed_payments) const
Definition: wallet2.cpp:2816
uint64_t dust_threshold
Definition: wallet2.h:83
static boost::optional< password_container > password_prompt(const bool new_password)
Definition: wallet2.cpp:473
std::vector< size_t > select_available_outputs(const std::function< bool(const transfer_details &td)> &f)
Definition: wallet2.cpp:4945
uint64_t get_fee_multiplier(uint32_t priority, int fee_algorithm=-1)
Definition: wallet2.cpp:3516
Definition: wallet2.h:230
std::unordered_map< crypto::hash, unconfirmed_transfer_details > m_unconfirmed_txs
Definition: wallet2.h:675
bool m_print_ring_members
Definition: wallet2.h:700
bool delete_address_book_row(std::size_t row_id)
Definition: wallet2.cpp:1735
boost::variant< txin_gen, txin_to_script, txin_to_scripthash, txin_to_key > txin_v
Definition: cryptonote_basic.h:144
cryptonote::account_base & get_account()
Definition: wallet2.h:343
POD_CLASS hash
Definition: hash.h:46
uint64_t m_amount
Definition: wallet2.h:177
cryptonote::tx_destination_entry change_dts
Definition: wallet2.h:235
uint64_t get_blockchain_current_height() const
Definition: wallet2.h:433
crypto::secret_key tx_key
Definition: wallet2.h:238
Definition: wallet2.h:258
std::string to_string(t_connection_type type)
Definition: connection_basic.cpp:96
void print_ring_members(bool value)
Definition: wallet2.h:522
uint32_t m_default_priority
Definition: wallet2.h:703
std::vector< size_t > get_only_rct(const std::vector< size_t > &unused_dust_indices, const std::vector< size_t > &unused_transfers_indices) const
Definition: wallet2.cpp:4365
std::pair< uint64_t, rct::ctkey > output_entry
Definition: cryptonote_tx_utils.h:45
std::string print_money(uint64_t amount, unsigned int decimal_point)
Definition: cryptonote_format_utils.cpp:562
std::string decrypt(const std::string &ciphertext, const crypto::secret_key &skey, bool authenticated=true) const
Definition: wallet2.cpp:5552
Definition: cryptonote_basic.h:149
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:739
static std::unique_ptr< wallet2 > make_dummy(const boost::program_options::variables_map &vm)
Just parses variables.
Definition: wallet2.cpp:519
transfer_container m_transfers
Definition: wallet2.h:680
bool is_rct() const
Definition: wallet2.h:153
#define FIELD(f)
tags the field with the variable name and then serializes it
Definition: serialization.h:234
uint32_t get_default_priority() const
Definition: wallet2.h:527
virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction &tx, uint64_t amount)
Definition: wallet2.h:74
uint64_t m_amount_in
Definition: wallet2.h:186
bool load_unsigned_tx(const std::string &unsigned_filename, unsigned_tx_set &exported_txs)
Definition: wallet2.cpp:3320
RefreshType m_refresh_type
Definition: wallet2.h:704
std::unordered_map< crypto::key_image, size_t > m_key_images
Definition: wallet2.h:682
bool m_confirm_missing_payment_id
Definition: wallet2.h:707
Definition: wallet2.h:104
std::list< out_entry > outs
Definition: core_rpc_server_commands_defs.h:331
uint64_t m_upper_transaction_size_limit
Definition: wallet2.h:687
Definition: core_rpc_server_commands_defs.h:101
std::vector< std::pair< uint64_t, uint64_t > > estimate_backlog(uint64_t min_blob_size, uint64_t max_blob_size, const std::vector< uint64_t > &fees)
Definition: wallet2.cpp:5819
crypto::hash m_payment_id
Definition: wallet2.h:203
uint32_t default_mixin() const
Definition: wallet2.h:525
static std::pair< std::unique_ptr< wallet2 >, password_container > make_new(const boost::program_options::variables_map &vm)
Uses stdin and stdout. Returns a wallet2 and password for wallet with no file if no errors.
Definition: wallet2.cpp:508
const crypto::public_key & get_public_key() const
Definition: wallet2.h:155
std::vector< wallet2::pending_tx > create_transactions_from(const cryptonote::account_public_address &address, 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, bool trusted_daemon)
Definition: wallet2.cpp:4764
time_t m_sent_time
Definition: wallet2.h:189
bool m_is_initialized
Definition: wallet2.h:714
Definition: cryptonote_basic.h:188
void transfer_selected_rct(std::vector< cryptonote::tx_destination_entry > dsts, const std::list< 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, cryptonote::transaction &tx, pending_tx &ptx)
Definition: wallet2.cpp:4076
void set_default_priority(uint32_t p)
Definition: wallet2.h:528
std::string encrypt_with_view_secret_key(const std::string &plaintext, bool authenticated=true) const
Definition: wallet2.cpp:5547
#define true
Definition: stdbool.h:37
void set_min_output_count(uint32_t count)
Definition: wallet2.h:537
Definition: wallet_errors.h:545
enum tools::wallet2::unconfirmed_transfer_details::@13 m_state
virtual ~i_wallet2_callback()
Definition: wallet2.h:78
boost::mutex m_daemon_rpc_mutex
Definition: wallet2.h:691
void update_pool_state(bool refreshed=false)
Definition: wallet2.cpp:1444
static bool parse_payment_id(const std::string &payment_id_str, crypto::hash &payment_id)
Definition: wallet2.cpp:2470
bool use_rct
Definition: wallet2.h:220
uint64_t m_amount
Definition: wallet2.h:148
bool m_spent
Definition: wallet2.h:144
static std::unique_ptr< wallet2 > make_from_json(const boost::program_options::variables_map &vm, const std::string &json_file)
Uses stdin and stdout. Returns a wallet2 if no errors.
Definition: wallet2.cpp:485
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, bool trusted_daemon)
Definition: wallet2.cpp:4401
uint64_t m_spent_height
Definition: wallet2.h:145
uint64_t fee
Definition: wallet2.h:233
void refresh()
Definition: wallet2.cpp:1406
Definition: wallet2.h:281
uint64_t get_daemon_blockchain_target_height(std::string &err)
Definition: wallet2.cpp:5128
wallet2(const wallet2 &)
Definition: wallet2.h:109
bool m_auto_refresh
Definition: wallet2.h:705
int get_fee_algorithm()
Definition: wallet2.cpp:3578
Definition: wallet2.h:137
void serialize(t_archive &a, const unsigned int ver)
Definition: wallet2.h:438
void ask_password(bool always)
Definition: wallet2.h:534
void get_transfers(wallet2::transfer_container &incoming_transfers) const
Definition: wallet2.cpp:2779
std::vector< wallet2::pending_tx > create_transactions_all(uint64_t below, const cryptonote::account_public_address &address, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector< uint8_t > extra, bool trusted_daemon)
Definition: wallet2.cpp:4735