Electroneum
wallet2.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2019, 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 
62 
63 #include <iostream>
64 
65 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
66 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "wallet.wallet2"
67 
68 class Serialization_portability_wallet_Test;
69 
70 namespace tools
71 {
73  {
74  public:
75  virtual void on_new_block(uint64_t height, const cryptonote::block& block) {}
76  virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount) {}
77  virtual void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount) {}
78  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) {}
79  virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx) {}
80  virtual ~i_wallet2_callback() {}
81  };
82 
84  {
85  uint64_t dust_threshold;
86  bool add_to_fee;
88 
89  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())
90  : dust_threshold(a_dust_threshold)
91  , add_to_fee(an_add_to_fee)
92  , addr_for_dust(an_addr_for_dust)
93  {
94  }
95  };
96 
97  class wallet2
98  {
99  friend class ::Serialization_portability_wallet_Test;
100  public:
101  static constexpr const std::chrono::seconds rpc_timeout = std::chrono::minutes(3) + std::chrono::seconds(30);
102 
103  enum RefreshType {
108  };
109 
110  private:
112 
113  public:
114  static const char* tr(const char* str);
115 
116  static bool has_testnet_option(const boost::program_options::variables_map& vm);
117  static void init_options(boost::program_options::options_description& desc_params);
118 
120  static boost::optional<password_container> password_prompt(const bool new_password);
121 
123  static std::unique_ptr<wallet2> make_from_json(const boost::program_options::variables_map& vm, const std::string& json_file, etneg::MicroCore* core = nullptr, cryptonote::Blockchain* blockchain_storage = nullptr);
124 
126  static std::pair<std::unique_ptr<wallet2>, password_container>
127  make_from_file(const boost::program_options::variables_map& vm, const std::string& wallet_file, etneg::MicroCore* core = nullptr, cryptonote::Blockchain* blockchain_storage = nullptr);
128 
130  static std::pair<std::unique_ptr<wallet2>, password_container> make_new(const boost::program_options::variables_map& vm, etneg::MicroCore* core = nullptr, cryptonote::Blockchain* blockchain_storage = nullptr);
131 
133  static std::unique_ptr<wallet2> make_dummy(const boost::program_options::variables_map& vm, etneg::MicroCore* core = nullptr, cryptonote::Blockchain* blockchain_storage = nullptr);
134 
135  static bool verify_password(const std::string& keys_file_name, const std::string& password, bool watch_only);
136 
138 
140  {
141  uint64_t m_block_height;
146  bool m_spent;
147  uint64_t m_spent_height;
148  crypto::key_image m_key_image; //TODO: key_image stored twice :(
150  uint64_t m_amount;
151  bool m_rct;
153  size_t m_pk_index;
154 
155  bool is_rct() const { return m_rct; }
156  uint64_t amount() const { return m_amount; }
157  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; }
158 
161  FIELD(m_tx)
162  FIELD(m_txid)
165  FIELD(m_spent)
168  FIELD(m_mask)
169  FIELD(m_amount)
170  FIELD(m_rct)
173  END_SERIALIZE()
174  };
175 
177  {
179  uint64_t m_amount;
180  uint64_t m_block_height;
181  uint64_t m_unlock_time;
182  uint64_t m_timestamp;
183  };
184 
186  {
188  uint64_t m_amount_in;
189  uint64_t m_amount_out;
190  uint64_t m_change;
191  time_t m_sent_time;
192  std::vector<cryptonote::tx_destination_entry> m_dests;
194  enum { pending, pending_not_in_pool, failed } m_state;
195  uint64_t m_timestamp;
196  };
197 
199  {
200  uint64_t m_amount_in;
201  uint64_t m_amount_out;
202  uint64_t m_change;
203  uint64_t m_block_height;
204  std::vector<cryptonote::tx_destination_entry> m_dests;
206  uint64_t m_timestamp;
207  uint64_t m_unlock_time;
208 
209  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) {}
211  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) {}
212  };
213 
215  {
216  std::vector<cryptonote::tx_source_entry> sources;
218  std::vector<cryptonote::tx_destination_entry> splitted_dsts; // split, includes change
219  std::list<size_t> selected_transfers;
220  std::vector<uint8_t> extra;
221  uint64_t unlock_time;
222  bool use_rct;
223  std::vector<cryptonote::tx_destination_entry> dests; // original setup, does not include change
224 
226  FIELD(sources)
227  FIELD(change_dts)
228  FIELD(splitted_dsts)
229  FIELD(selected_transfers)
230  FIELD(extra)
231  FIELD(unlock_time)
232  FIELD(use_rct)
233  FIELD(dests)
234  END_SERIALIZE()
235  };
236 
238  typedef std::unordered_multimap<crypto::hash, payment_details> payment_container;
239 
240  // The convention for destinations is:
241  // dests does not include change
242  // splitted_dsts (in construction_data) does
243  struct pending_tx
244  {
246  uint64_t dust, fee;
249  std::list<size_t> selected_transfers;
250  std::string key_images;
252  std::vector<crypto::secret_key> additional_tx_keys;
253  std::vector<cryptonote::tx_destination_entry> dests;
254 
256 
258  FIELD(tx)
259  FIELD(dust)
260  FIELD(fee)
261  FIELD(dust_added_to_fee)
262  FIELD(change_dts)
263  FIELD(selected_transfers)
264  FIELD(key_images)
265  FIELD(tx_key)
266  FIELD(additional_tx_keys)
267  FIELD(dests)
268  FIELD(construction_data)
269  END_SERIALIZE()
270  };
271 
272  // The term "Unsigned tx" is not really a tx since it's not signed yet.
273  // It doesnt have tx hash, key and the integrated address is not separated into addr + payment id.
275  {
276  std::vector<tx_construction_data> txes;
278  };
279 
281  {
282  std::vector<pending_tx> ptx;
283  std::vector<crypto::key_image> key_images;
284  };
285 
287  {
288  crypto::chacha8_iv iv;
289  std::string account_data;
290 
292  FIELD(iv)
293  FIELD(account_data)
294  END_SERIALIZE()
295  };
296 
298  {
299  crypto::chacha8_iv iv;
300  std::string cache_data;
301 
303  FIELD(iv)
304  FIELD(cache_data)
305  END_SERIALIZE()
306  };
307 
308  // GUI Address book
310  {
313  std::string m_description;
314  };
315 
316  typedef std::tuple<uint64_t, crypto::public_key, rct::key> get_outs_entry;
317 
327  crypto::secret_key generate(const std::string& wallet, const std::string& password,
328  const crypto::secret_key& recovery_param = crypto::secret_key(), bool recover = false,
329  bool two_random = false);
337  void generate(const std::string& wallet, const std::string& password,
338  const cryptonote::account_public_address &account_public_address,
339  const crypto::secret_key& spendkey, const crypto::secret_key& viewkey);
346  void generate(const std::string& wallet, const std::string& password,
347  const cryptonote::account_public_address &account_public_address,
348  const crypto::secret_key& viewkey = crypto::secret_key());
354  void rewrite(const std::string& wallet_name, const std::string& password);
355  void write_watch_only_wallet(const std::string& wallet_name, const std::string& password);
356  void load(const std::string& wallet, const std::string& password);
357  void store();
363  void store_to(const std::string &path, const std::string &password);
364 
365  std::string path() const;
366 
370  bool verify_password(const std::string& password) const;
373 
376 
377  // upper_transaction_size_limit as defined below is set to
378  // approximately 125% of the fixed minimum allowable penalty
379  // free block size. TODO: fix this so that it actually takes
380  // into account the current median block size rather than
381  // the minimum block size.
382  bool deinit();
383  bool init(std::string daemon_address = "http://localhost:8080",
384  boost::optional<epee::net_utils::http::login> daemon_login = boost::none, std::string blockchain_db_path = "", uint64_t upper_transaction_size_limit = 0);
385 
386  void stop() { m_run.store(false, std::memory_order_relaxed); }
387 
390 
394  bool is_deterministic() const;
395  bool get_seed(std::string& electrum_words) const;
399  const std::string &get_seed_language() const;
403  void set_seed_language(const std::string &language);
407  bool is_deprecated() const;
408  void refresh();
409  void refresh(uint64_t start_height, uint64_t & blocks_fetched);
410  void refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& received_money);
411  bool refresh(uint64_t & blocks_fetched, bool& received_money, bool& ok);
412 
415 
416  bool testnet() const { return m_testnet; }
417  bool restricted() const { return m_restricted; }
418  bool watch_only() const { return m_watch_only; }
419 
420  uint64_t balance() const;
421  uint64_t unlocked_balance() const;
422  uint64_t unlocked_dust_balance(const tx_dust_policy &dust_policy) const;
423  template<typename T>
424  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);
425  template<typename T>
426  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);
427  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);
428  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);
429  template<typename T>
430  void transfer_selected(const std::vector<cryptonote::tx_destination_entry>& dsts, const std::list<size_t> selected_transfers, size_t fake_outputs_count,
431  std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs,
432  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);
433  void transfer_selected_rct(std::vector<cryptonote::tx_destination_entry> dsts, const std::list<size_t> selected_transfers, size_t fake_outputs_count,
434  std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs,
435  uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx &ptx);
436 
437  void commit_tx(pending_tx& ptx_vector);
438  void commit_tx(std::vector<pending_tx>& ptx_vector);
439  bool save_tx(const std::vector<pending_tx>& ptx_vector, const std::string &filename);
440  // load unsigned tx from file and sign it. Takes confirmation callback as argument. Used by the cli wallet
441  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);
442  // sign unsigned tx. Takes unsigned_tx_set as argument. Used by GUI
443  bool sign_tx(unsigned_tx_set &exported_txs, const std::string &signed_filename, std::vector<wallet2::pending_tx> &ptx);
444  // load unsigned_tx_set from file.
445  bool load_unsigned_tx(const std::string &unsigned_filename, unsigned_tx_set &exported_txs);
446  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);
447  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);
448  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);
449  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);
450  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);
451  std::vector<pending_tx> create_unmixable_sweep_transactions(bool trusted_daemon);
452  bool check_connection(uint32_t *version = NULL, uint32_t timeout = 200000);
453  void get_transfers(wallet2::transfer_container& incoming_transfers) const;
454  void save_transfers_to_csv(bool in, bool out, uint64_t min_height, uint64_t max_height);
455  void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height = 0) const;
456  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;
457  void get_payments_out(std::list<std::pair<crypto::hash,wallet2::confirmed_transfer_details>>& confirmed_payments,
458  uint64_t min_height, uint64_t max_height = (uint64_t)-1) const;
459  void get_unconfirmed_payments_out(std::list<std::pair<crypto::hash,wallet2::unconfirmed_transfer_details>>& unconfirmed_payments) const;
460  void get_unconfirmed_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& unconfirmed_payments) const;
461 
463  void rescan_spent();
464  void rescan_blockchain(bool refresh = true);
465  bool is_transfer_unlocked(const transfer_details& td) const;
466  template <class t_archive>
467  inline void serialize(t_archive &a, const unsigned int ver)
468  {
469  uint64_t dummy_refresh_height = 0; // moved to keys file
470  if(ver < 5)
471  return;
472  a & m_blockchain;
473  a & m_transfers;
475  a & m_key_images;
476  if(ver < 6)
477  return;
479  if(ver < 7)
480  return;
481  a & m_payments;
482  if(ver < 8)
483  return;
484  a & m_tx_keys;
485  if(ver < 9)
486  return;
487  a & m_confirmed_txs;
488  if(ver < 11)
489  return;
490  a & dummy_refresh_height;
491  if(ver < 12)
492  return;
493  a & m_tx_notes;
494  if(ver < 13)
495  return;
496  if (ver < 17)
497  {
498  // we're loading an old version, where m_unconfirmed_payments was a std::map
499  std::unordered_map<crypto::hash, payment_details> m;
500  a & m;
501  for (std::unordered_map<crypto::hash, payment_details>::const_iterator i = m.begin(); i != m.end(); ++i)
502  m_unconfirmed_payments.insert(*i);
503  }
504  if(ver < 14)
505  return;
506  if(ver < 15)
507  {
508  // we're loading an older wallet without a pubkey map, rebuild it
509  for (size_t i = 0; i < m_transfers.size(); ++i)
510  {
511  const transfer_details &td = m_transfers[i];
513  const cryptonote::txout_to_key &o = boost::get<const cryptonote::txout_to_key>(out.target);
514  m_pub_keys.emplace(o.key, i);
515  }
516  return;
517  }
518  a & m_pub_keys;
519  if(ver < 16)
520  return;
521  a & m_address_book;
522  if(ver < 17)
523  return;
525  if(ver < 18)
526  return;
527  a & m_scanned_pool_txs[0];
528  a & m_scanned_pool_txs[1];
529  }
530 
537  static void wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exists);
543  static std::string get_human_readable_timestamp(uint64_t ts)
544  {
545  char buffer[64];
546  if (ts < 1234567890)
547  return "<unknown>";
548  time_t tt = ts;
549  struct tm tm;
550  #ifdef WIN32
551  gmtime_s(&tm, &tt);
552  #else
553  gmtime_r(&tt, &tm);
554  #endif
555  uint64_t now = time(NULL);
556  uint64_t diff = ts > now ? ts - now : now - ts;
557  if (diff > 24*3600)
558  strftime(buffer, sizeof(buffer), "%Y-%m-%d", &tm);
559  else
560  strftime(buffer, sizeof(buffer), "%I:%M:%S %p", &tm);
561  return std::string(buffer);
562 }
563 //----------------------------------------------------------------------------------------------------
564  static bool wallet_valid_path_format(const std::string& file_path);
565  static bool parse_long_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);
566  static bool parse_short_payment_id(const std::string& payment_id_str, crypto::hash8& payment_id);
567  static bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);
568 
570  void always_confirm_transfers(bool always) { m_always_confirm_transfers = always; }
571  bool print_ring_members() const { return m_print_ring_members; }
572  void print_ring_members(bool value) { m_print_ring_members = value; }
573  bool store_tx_info() const { return m_store_tx_info; }
575  uint32_t get_default_priority() const { return m_default_priority; }
576  void set_default_priority(uint32_t p) { m_default_priority = p; }
577  bool auto_refresh() const { return m_auto_refresh; }
578  void auto_refresh(bool r) { m_auto_refresh = r; }
581  bool ask_password() const { return m_ask_password; }
582  void ask_password(bool always) { m_ask_password = always; }
583  void set_default_decimal_point(unsigned int decimal_point);
584  unsigned int get_default_decimal_point() const;
585  void set_min_output_count(uint32_t count) { m_min_output_count = count; }
586  uint32_t get_min_output_count() const { return m_min_output_count; }
587  void set_min_output_value(uint64_t value) { m_min_output_value = value; }
588  uint64_t get_min_output_value() const { return m_min_output_value; }
589  void merge_destinations(bool merge) { m_merge_destinations = merge; }
590  bool merge_destinations() const { return m_merge_destinations; }
591  bool confirm_backlog() const { return m_confirm_backlog; }
592  void confirm_backlog(bool always) { m_confirm_backlog = always; }
595 
596  bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key) const;
597 
601  std::vector<address_book_row> get_address_book() const { return m_address_book; }
602  bool add_address_book_row(const cryptonote::account_public_address &address, const crypto::hash &payment_id, const std::string &description);
603  bool delete_address_book_row(std::size_t row_id);
604 
605  uint64_t get_num_rct_outputs();
606  const transfer_details &get_transfer_details(size_t idx) const;
607 
608  void get_hard_fork_info(uint8_t version, uint64_t &earliest_height);
609  bool use_fork_rules(uint8_t version, int64_t early_blocks = 0);
610  int get_fee_algorithm();
611 
612  std::string get_wallet_file() const;
613  std::string get_keys_file() const;
614  std::string get_daemon_address() const;
615  const boost::optional<epee::net_utils::http::login>& get_daemon_login() const { return m_daemon_login; }
616  uint64_t get_daemon_blockchain_height(std::string& err);
617  uint64_t get_daemon_blockchain_target_height(std::string& err);
621  uint64_t get_approximate_blockchain_height() const;
622  std::vector<size_t> select_available_outputs_from_histogram(uint64_t count, bool atleast, bool unlocked, bool allow_rct, bool trusted_daemon);
623  std::vector<size_t> select_available_outputs(const std::function<bool(const transfer_details &td)> &f);
624  std::vector<size_t> select_available_unmixable_outputs(bool trusted_daemon);
625  std::vector<size_t> select_available_mixable_outputs(bool trusted_daemon);
626 
627  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;
628  size_t pop_best_value(std::vector<size_t> &unused_dust_indices, const std::list<size_t>& selected_transfers, bool smallest = false) const;
629 
630  void set_tx_note(const crypto::hash &txid, const std::string &note);
631  std::string get_tx_note(const crypto::hash &txid) const;
632 
633  std::string sign(const std::string &data) const;
634  bool verify(const std::string &data, const cryptonote::account_public_address &address, const std::string &signature) const;
635 
636  std::vector<tools::wallet2::transfer_details> export_outputs() const;
637  size_t import_outputs(const std::vector<tools::wallet2::transfer_details> &outputs);
638 
639  bool export_key_images(const std::string filename);
640  std::vector<std::pair<crypto::key_image, crypto::signature>> export_key_images() const;
641  uint64_t import_key_images(const std::vector<std::pair<crypto::key_image, crypto::signature>> &signed_key_images, uint64_t &spent, uint64_t &unspent);
642  uint64_t import_key_images(const std::string &filename, uint64_t &spent, uint64_t &unspent);
643 
644  void update_pool_state(bool refreshed = false);
645 
646  std::string encrypt(const std::string &plaintext, const crypto::secret_key &skey, bool authenticated = true) const;
647  std::string encrypt_with_view_secret_key(const std::string &plaintext, bool authenticated = true) const;
648  std::string decrypt(const std::string &ciphertext, const crypto::secret_key &skey, bool authenticated = true) const;
649  std::string decrypt_with_view_secret_key(const std::string &ciphertext, bool authenticated = true) const;
650 
651  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);
652  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);
653 
654  uint64_t get_blockchain_height_by_date(uint16_t year, uint8_t month, uint8_t day); // 1<=month<=12, 1<=day<=31
655 
656  bool is_synced() const;
657 
658  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);
659 
660  uint64_t get_fee_multiplier(uint32_t priority, int fee_algorithm = -1);
661  uint64_t get_per_kb_fee();
662 
663  void set_blockchain_storage(etneg::MicroCore* core = nullptr, cryptonote::Blockchain* blockchain_storage = nullptr);
664 
665  etneg::MicroCore* get_core() const { return m_core; }
667 
668  private:
676  bool store_keys(const std::string& keys_file_name, const std::string& password, bool watch_only = false);
682  bool load_keys(const std::string& keys_file_name, const std::string& password);
683  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);
685  void detach_blockchain(uint64_t height);
686  void get_short_chain_history(std::list<crypto::hash>& ids) const;
687  bool is_tx_spendtime_unlocked(uint64_t unlock_time, uint64_t block_height) const;
688  bool clear();
689  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);
690  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);
691  void fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history);
692  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);
693  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);
694  uint64_t select_transfers(uint64_t needed_money, std::vector<size_t> unused_transfers_indices, std::list<size_t>& selected_transfers, bool trusted_daemon);
695  bool prepare_file_names(const std::string& file_path);
696  void process_unconfirmed(const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t height);
697  void process_outgoing(const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t height, uint64_t ts, uint64_t spent, uint64_t received);
698  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);
700  void check_genesis(const crypto::hash& genesis_hash) const; //throws
701  bool generate_chacha8_key_from_secret_keys(crypto::chacha8_key &key) const;
702  crypto::hash get_payment_id(const pending_tx &ptx) const;
703  crypto::hash8 get_short_payment_id(const pending_tx &ptx) const;
704  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;
705  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;
706  void parse_block_round(const cryptonote::blobdata &blob, cryptonote::block &bl, crypto::hash &bl_id, bool &error) const;
708  std::vector<uint64_t> get_unspent_amounts_vector();
710  float get_output_relatedness(const transfer_details &td0, const transfer_details &td1) const;
711  std::vector<size_t> pick_preferred_rct_inputs(uint64_t needed_money) const;
712  void set_spent(size_t idx, uint64_t height);
713  void set_unspent(size_t idx);
714  void get_outs(std::vector<std::vector<get_outs_entry>> &outs, const std::list<size_t> &selected_transfers, size_t fake_outputs_count);
715  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);
717  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;
718  std::vector<size_t> get_only_rct(const std::vector<size_t> &unused_dust_indices, const std::vector<size_t> &unused_transfers_indices) const;
721  void load_database(const std::string blockchain_db_path);
723 
725  boost::optional<epee::net_utils::http::login> m_daemon_login;
726  std::string m_daemon_address;
727  std::string m_wallet_file;
728  std::string m_keys_file;
729  epee::net_utils::http::http_simple_client m_http_client;
730  std::vector<crypto::hash> m_blockchain;
731  std::atomic<uint64_t> m_local_bc_height; //temporary workaround
732  std::unordered_map<crypto::hash, unconfirmed_transfer_details> m_unconfirmed_txs;
733  std::unordered_map<crypto::hash, confirmed_transfer_details> m_confirmed_txs;
734  std::unordered_multimap<crypto::hash, payment_details> m_unconfirmed_payments;
735  std::unordered_map<crypto::hash, crypto::secret_key> m_tx_keys;
736 
739  std::unordered_map<crypto::key_image, size_t> m_key_images;
740  std::unordered_map<crypto::public_key, size_t> m_pub_keys;
742  std::unordered_map<crypto::hash, std::string> m_tx_notes;
743  std::vector<tools::wallet2::address_book_row> m_address_book;
744  uint64_t m_upper_transaction_size_limit; //TODO: auto-calc this value or request from daemon, now use some fixed value
745 
746  std::atomic<bool> m_run;
747 
748  boost::mutex m_daemon_rpc_mutex;
749 
751  bool m_testnet;
753  std::string seed_language;
772  std::unordered_set<crypto::hash> m_scanned_pool_txs[2];
773 
777  bool is_connected_to_db = false;
778  };
779 }
781 BOOST_CLASS_VERSION(tools::wallet2::transfer_details, 7)
782 BOOST_CLASS_VERSION(tools::wallet2::payment_details, 1)
783 BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 6)
784 BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 4)
785 BOOST_CLASS_VERSION(tools::wallet2::address_book_row, 16)
786 BOOST_CLASS_VERSION(tools::wallet2::unsigned_tx_set, 0)
787 BOOST_CLASS_VERSION(tools::wallet2::signed_tx_set, 0)
788 BOOST_CLASS_VERSION(tools::wallet2::tx_construction_data, 0)
789 BOOST_CLASS_VERSION(tools::wallet2::pending_tx, 0)
790 
791 namespace boost
792 {
793  namespace serialization
794  {
795  template <class Archive>
796  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)
797  {
798  }
799  template <class Archive>
800  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)
801  {
802  if (ver < 1)
803  {
804  x.m_mask = rct::identity();
805  x.m_amount = x.m_tx.vout[x.m_internal_output_index].amount;
806  }
807  if (ver < 2)
808  {
809  x.m_spent_height = 0;
810  }
811  if (ver < 4)
812  {
813  x.m_rct = x.m_tx.vout[x.m_internal_output_index].amount == 0;
814  }
815  if (ver < 6)
816  {
817  x.m_key_image_known = true;
818  }
819  if (ver < 7)
820  {
821  x.m_pk_index = 0;
822  }
823  }
824 
825  template <class Archive>
826  inline void serialize(Archive &a, tools::wallet2::transfer_details &x, const boost::serialization::version_type ver)
827  {
828  a & x.m_block_height;
831  if (ver < 3)
832  {
834  a & tx;
835  x.m_tx = (const cryptonote::transaction_prefix&)tx;
837  }
838  else
839  {
840  a & x.m_tx;
841  }
842  a & x.m_spent;
843  a & x.m_key_image;
844  if (ver < 1)
845  {
846  // ensure mask and amount are set
848  return;
849  }
850  a & x.m_mask;
851  a & x.m_amount;
852  if (ver < 2)
853  {
855  return;
856  }
857  a & x.m_spent_height;
858  if (ver < 3)
859  {
861  return;
862  }
863  a & x.m_txid;
864  if (ver < 4)
865  {
867  return;
868  }
869  a & x.m_rct;
870  if (ver < 5)
871  {
873  return;
874  }
875  if (ver < 6)
876  {
877  // v5 did not properly initialize
878  uint8_t u;
879  a & u;
880  x.m_key_image_known = true;
881  return;
882  }
883  a & x.m_key_image_known;
884  if (ver < 7)
885  {
887  return;
888  }
889  a & x.m_pk_index;
890  }
891 
892  template <class Archive>
893  inline void serialize(Archive &a, tools::wallet2::unconfirmed_transfer_details &x, const boost::serialization::version_type ver)
894  {
895  a & x.m_change;
896  a & x.m_sent_time;
897  if (ver < 5)
898  {
900  a & tx;
901  x.m_tx = (const cryptonote::transaction_prefix&)tx;
902  }
903  else
904  {
905  a & x.m_tx;
906  }
907  if (ver < 1)
908  return;
909  a & x.m_dests;
910  a & x.m_payment_id;
911  if (ver < 2)
912  return;
913  a & x.m_state;
914  if (ver < 3)
915  return;
916  a & x.m_timestamp;
917  if (ver < 4)
918  return;
919  a & x.m_amount_in;
920  a & x.m_amount_out;
921  if (ver < 6)
922  {
923  // v<6 may not have change accumulated in m_amount_out, which is a pain,
924  // as it's readily understood to be sum of outputs.
925  // We convert it to include change from v6
926  if (!typename Archive::is_saving() && x.m_change != (uint64_t)-1)
927  x.m_amount_out += x.m_change;
928  }
929  }
930 
931  template <class Archive>
932  inline void serialize(Archive &a, tools::wallet2::confirmed_transfer_details &x, const boost::serialization::version_type ver)
933  {
934  a & x.m_amount_in;
935  a & x.m_amount_out;
936  a & x.m_change;
937  a & x.m_block_height;
938  if (ver < 1)
939  return;
940  a & x.m_dests;
941  a & x.m_payment_id;
942  if (ver < 2)
943  return;
944  a & x.m_timestamp;
945  if (ver < 3)
946  {
947  // v<3 may not have change accumulated in m_amount_out, which is a pain,
948  // as it's readily understood to be sum of outputs. Whether it got added
949  // or not depends on whether it came from a unconfirmed_transfer_details
950  // (not included) or not (included). We can't reliably tell here, so we
951  // check whether either yields a "negative" fee, or use the other if so.
952  // We convert it to include change from v3
953  if (!typename Archive::is_saving() && x.m_change != (uint64_t)-1)
954  {
955  if (x.m_amount_in > (x.m_amount_out + x.m_change))
956  x.m_amount_out += x.m_change;
957  }
958  }
959  if (ver < 4)
960  {
961  if (!typename Archive::is_saving())
962  x.m_unlock_time = 0;
963  return;
964  }
965  a & x.m_unlock_time;
966  }
967 
968  template <class Archive>
969  inline void serialize(Archive& a, tools::wallet2::payment_details& x, const boost::serialization::version_type ver)
970  {
971  a & x.m_tx_hash;
972  a & x.m_amount;
973  a & x.m_block_height;
974  a & x.m_unlock_time;
975  if (ver < 1)
976  return;
977  a & x.m_timestamp;
978  }
979 
980  template <class Archive>
981  inline void serialize(Archive& a, cryptonote::tx_destination_entry& x, const boost::serialization::version_type ver)
982  {
983  a & x.amount;
984  a & x.addr;
985  }
986 
987  template <class Archive>
988  inline void serialize(Archive& a, tools::wallet2::address_book_row& x, const boost::serialization::version_type ver)
989  {
990  a & x.m_address;
991  a & x.m_payment_id;
992  a & x.m_description;
993  }
994 
995  template <class Archive>
996  inline void serialize(Archive &a, tools::wallet2::unsigned_tx_set &x, const boost::serialization::version_type ver)
997  {
998  a & x.txes;
999  a & x.transfers;
1000  }
1001 
1002  template <class Archive>
1003  inline void serialize(Archive &a, tools::wallet2::signed_tx_set &x, const boost::serialization::version_type ver)
1004  {
1005  a & x.ptx;
1006  a & x.key_images;
1007  }
1008 
1009  template <class Archive>
1010  inline void serialize(Archive &a, tools::wallet2::tx_construction_data &x, const boost::serialization::version_type ver)
1011  {
1012  a & x.sources;
1013  a & x.change_dts;
1014  a & x.splitted_dsts;
1015  a & x.selected_transfers;
1016  a & x.extra;
1017  a & x.unlock_time;
1018  a & x.use_rct;
1019  a & x.dests;
1020  }
1021 
1022  template <class Archive>
1023  inline void serialize(Archive &a, tools::wallet2::pending_tx &x, const boost::serialization::version_type ver)
1024  {
1025  a & x.tx;
1026  a & x.dust;
1027  a & x.fee;
1028  a & x.dust_added_to_fee;
1029  a & x.change_dts;
1030  a & x.selected_transfers;
1031  a & x.key_images;
1032  a & x.tx_key;
1033  a & x.dests;
1034  a & x.construction_data;
1035  }
1036  }
1037 }
1038 
1039 namespace tools
1040 {
1041 
1042  namespace detail
1043  {
1044  //----------------------------------------------------------------------------------------------------
1045  inline void digit_split_strategy(const std::vector<cryptonote::tx_destination_entry>& dsts,
1046  const cryptonote::tx_destination_entry& change_dst, uint64_t dust_threshold,
1047  std::vector<cryptonote::tx_destination_entry>& splitted_dsts, std::vector<cryptonote::tx_destination_entry> &dust_dsts)
1048  {
1049  splitted_dsts.clear();
1050  dust_dsts.clear();
1051 
1052  for(auto& de: dsts)
1053  {
1055  [&](uint64_t chunk) { splitted_dsts.push_back(cryptonote::tx_destination_entry(chunk, de.addr)); },
1056  [&](uint64_t a_dust) { splitted_dsts.push_back(cryptonote::tx_destination_entry(a_dust, de.addr)); } );
1057  }
1058 
1060  [&](uint64_t chunk) {
1061  if (chunk <= dust_threshold)
1062  dust_dsts.push_back(cryptonote::tx_destination_entry(chunk, change_dst.addr));
1063  else
1064  splitted_dsts.push_back(cryptonote::tx_destination_entry(chunk, change_dst.addr));
1065  },
1066  [&](uint64_t a_dust) { dust_dsts.push_back(cryptonote::tx_destination_entry(a_dust, change_dst.addr)); } );
1067  }
1068  //----------------------------------------------------------------------------------------------------
1069  inline void null_split_strategy(const std::vector<cryptonote::tx_destination_entry>& dsts,
1070  const cryptonote::tx_destination_entry& change_dst, uint64_t dust_threshold,
1071  std::vector<cryptonote::tx_destination_entry>& splitted_dsts, std::vector<cryptonote::tx_destination_entry> &dust_dsts)
1072  {
1073  splitted_dsts = dsts;
1074 
1075  dust_dsts.clear();
1076  uint64_t change = change_dst.amount;
1077 
1078  if (0 != change)
1079  {
1080  splitted_dsts.push_back(cryptonote::tx_destination_entry(change, change_dst.addr));
1081  }
1082  }
1083  //----------------------------------------------------------------------------------------------------
1085  {
1086  std::string indexes;
1087  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) + " "; });
1088  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);
1089  }
1090  //----------------------------------------------------------------------------------------------------
1091  }
1092  //----------------------------------------------------------------------------------------------------
1093  template<typename T>
1094  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,
1095  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)
1096  {
1097  pending_tx ptx;
1099  transfer(dsts, fake_outs_count, unused_transfers_indices, unlock_time, fee, extra, destination_split_strategy, dust_policy, tx, ptx, trusted_daemon);
1100  }
1101 
1102  template<typename T>
1103  void wallet2::transfer(const std::vector<cryptonote::tx_destination_entry>& dsts, size_t fake_outputs_count, const std::vector<size_t> &unused_transfers_indices,
1104  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)
1105  {
1106  using namespace cryptonote;
1107  // throw if attempting a transaction with no destinations
1109 
1110  uint64_t upper_transaction_size_limit = get_upper_transaction_size_limit();
1111  uint64_t needed_money = fee;
1112 
1113  // calculate total amount being sent to all destinations
1114  // throw if total amount overflows uint64_t
1115  for(auto& dt: dsts)
1116  {
1118  needed_money += dt.amount;
1119  THROW_WALLET_EXCEPTION_IF(needed_money < dt.amount, error::tx_sum_overflow, dsts, fee, m_testnet);
1120  }
1121 
1122  // randomly select inputs for transaction
1123  // throw if requested send amount is greater than amount available to send
1124  std::list<size_t> selected_transfers;
1125  uint64_t found_money = select_transfers(needed_money, unused_transfers_indices, selected_transfers, trusted_daemon);
1126  THROW_WALLET_EXCEPTION_IF(found_money < needed_money, error::not_enough_money, found_money, needed_money - fee, fee);
1127 
1129  typedef cryptonote::tx_source_entry::output_entry tx_output_entry;
1130 
1131  COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response daemon_resp = AUTO_VAL_INIT(daemon_resp);
1132  if(fake_outputs_count)
1133  {
1134  COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request req = AUTO_VAL_INIT(req);
1135  req.outs_count = fake_outputs_count + 1;// add one to make possible (if need) to skip real output key
1136  for(size_t idx: selected_transfers)
1137  {
1138  const transfer_container::const_iterator it = m_transfers.begin() + idx;
1139  THROW_WALLET_EXCEPTION_IF(it->m_tx.vout.size() <= it->m_internal_output_index, error::wallet_internal_error,
1140  "m_internal_output_index = " + std::to_string(it->m_internal_output_index) +
1141  " is greater or equal to outputs count = " + std::to_string(it->m_tx.vout.size()));
1142  req.amounts.push_back(it->amount());
1143  }
1144 
1145  m_daemon_rpc_mutex.lock();
1146  bool r = epee::net_utils::invoke_http_bin("/getrandom_outs.bin", req, daemon_resp, m_http_client, rpc_timeout);
1147  m_daemon_rpc_mutex.unlock();
1148  THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "getrandom_outs.bin");
1149  THROW_WALLET_EXCEPTION_IF(daemon_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "getrandom_outs.bin");
1151  THROW_WALLET_EXCEPTION_IF(daemon_resp.outs.size() != selected_transfers.size(), error::wallet_internal_error,
1152  "daemon returned wrong response for getrandom_outs.bin, wrong amounts count = " +
1153  std::to_string(daemon_resp.outs.size()) + ", expected " + std::to_string(selected_transfers.size()));
1154 
1155  std::unordered_map<uint64_t, uint64_t> scanty_outs;
1157  {
1158  if (amount_outs.outs.size() < fake_outputs_count)
1159  {
1160  scanty_outs[amount_outs.amount] = amount_outs.outs.size();
1161  }
1162  }
1163  THROW_WALLET_EXCEPTION_IF(!scanty_outs.empty(), error::not_enough_outs_to_mix, scanty_outs, fake_outputs_count);
1164  }
1165 
1166  //prepare inputs
1167  size_t i = 0;
1168  std::vector<cryptonote::tx_source_entry> sources;
1169  for(size_t idx: selected_transfers)
1170  {
1171  sources.resize(sources.size()+1);
1172  cryptonote::tx_source_entry& src = sources.back();
1173  const transfer_details& td = m_transfers[idx];
1174  src.amount = td.amount();
1175  src.rct = false;
1176  //paste mixin transaction
1177  if(daemon_resp.outs.size())
1178  {
1179  daemon_resp.outs[i].outs.sort([](const out_entry& a, const out_entry& b){return a.global_amount_index < b.global_amount_index;});
1180  for(out_entry& daemon_oe: daemon_resp.outs[i].outs)
1181  {
1182  if(td.m_global_output_index == daemon_oe.global_amount_index)
1183  continue;
1184  tx_output_entry oe;
1185  oe.first = daemon_oe.global_amount_index;
1186  oe.second.dest = rct::pk2rct(daemon_oe.out_key);
1187  oe.second.mask = rct::identity();
1188  src.outputs.push_back(oe);
1189  if(src.outputs.size() >= fake_outputs_count)
1190  break;
1191  }
1192  }
1193 
1194  //paste real transaction to the random index
1195  auto it_to_insert = std::find_if(src.outputs.begin(), src.outputs.end(), [&](const tx_output_entry& a)
1196  {
1197  return a.first >= td.m_global_output_index;
1198  });
1199  //size_t real_index = src.outputs.size() ? (rand() % src.outputs.size() ):0;
1200  tx_output_entry real_oe;
1201  real_oe.first = td.m_global_output_index;
1202  real_oe.second.dest = rct::pk2rct(boost::get<txout_to_key>(td.m_tx.vout[td.m_internal_output_index].target).key);
1203  real_oe.second.mask = rct::identity();
1204  auto interted_it = src.outputs.insert(it_to_insert, real_oe);
1206  src.real_output = interted_it - src.outputs.begin();
1209  ++i;
1210  }
1211 
1212  cryptonote::tx_destination_entry change_dts = AUTO_VAL_INIT(change_dts);
1213  if (needed_money < found_money)
1214  {
1215  change_dts.addr = m_account.get_keys().m_account_address;
1216  change_dts.amount = found_money - needed_money;
1217  }
1218 
1219  std::vector<cryptonote::tx_destination_entry> splitted_dsts, dust_dsts;
1220  uint64_t dust = 0;
1221  destination_split_strategy(dsts, change_dts, dust_policy.dust_threshold, splitted_dsts, dust_dsts);
1222  for(auto& d: dust_dsts) {
1223  THROW_WALLET_EXCEPTION_IF(dust_policy.dust_threshold < d.amount, error::wallet_internal_error, "invalid dust value: dust = " +
1224  std::to_string(d.amount) + ", dust_threshold = " + std::to_string(dust_policy.dust_threshold));
1225  }
1226  for(auto& d: dust_dsts) {
1227  if (!dust_policy.add_to_fee)
1228  splitted_dsts.push_back(cryptonote::tx_destination_entry(d.amount, dust_policy.addr_for_dust));
1229  dust += d.amount;
1230  }
1231 
1232  crypto::secret_key tx_key;
1233  bool r = cryptonote::construct_tx_and_get_tx_key(m_account.get_keys(), sources, splitted_dsts, extra, tx, unlock_time, tx_key);
1234  THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time, m_testnet);
1235  THROW_WALLET_EXCEPTION_IF(upper_transaction_size_limit <= get_object_blobsize(tx), error::tx_too_big, tx, upper_transaction_size_limit);
1236 
1237  std::string key_images;
1238  bool all_are_txin_to_key = std::all_of(tx.vin.begin(), tx.vin.end(), [&](const txin_v& s_e) -> bool
1239  {
1240  CHECKED_GET_SPECIFIC_VARIANT(s_e, const txin_to_key, in, false);
1241  key_images += boost::to_string(in.k_image) + " ";
1242  return true;
1243  });
1244  THROW_WALLET_EXCEPTION_IF(!all_are_txin_to_key, error::unexpected_txin_type, tx);
1245 
1246  bool dust_sent_elsewhere = (dust_policy.addr_for_dust.m_view_public_key != change_dts.addr.m_view_public_key
1247  || dust_policy.addr_for_dust.m_spend_public_key != change_dts.addr.m_spend_public_key);
1248 
1249  if (dust_policy.add_to_fee || dust_sent_elsewhere) change_dts.amount -= dust;
1250 
1251  ptx.key_images = key_images;
1252  ptx.fee = (dust_policy.add_to_fee ? fee+dust : fee);
1253  ptx.dust = ((dust_policy.add_to_fee || dust_sent_elsewhere) ? dust : 0);
1254  ptx.dust_added_to_fee = dust_policy.add_to_fee;
1255  ptx.tx = tx;
1256  ptx.change_dts = change_dts;
1257  ptx.selected_transfers = selected_transfers;
1258  ptx.tx_key = tx_key;
1259  ptx.dests = dsts;
1260  ptx.construction_data.sources = sources;
1261  ptx.construction_data.change_dts = change_dts;
1262  ptx.construction_data.splitted_dsts = splitted_dsts;
1263  ptx.construction_data.selected_transfers = selected_transfers;
1264  ptx.construction_data.extra = tx.extra;
1265  ptx.construction_data.unlock_time = unlock_time;
1266  ptx.construction_data.use_rct = false;
1267  ptx.construction_data.dests = dsts;
1268  }
1269 
1270 
1271 }
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:219
bool watch_only() const
Definition: wallet2.h:418
uint64_t unlock_time
Definition: wallet2.h:221
static bool parse_long_payment_id(const std::string &payment_id_str, crypto::hash &payment_id)
Definition: wallet2.cpp:2580
void rescan_spent()
Definition: wallet2.cpp:2966
Definition: binary_utils.h:37
bool display_progress_indicator() const
Definition: wallet2.h:593
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:1164
epee::net_utils::http::http_simple_client m_http_client
Definition: wallet2.h:729
std::vector< crypto::key_image > key_images
Definition: wallet2.h:283
void fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list< crypto::hash > &short_chain_history)
Definition: wallet2.cpp:1805
void set_unspent(size_t idx)
Definition: wallet2.cpp:617
void rewrite(const std::string &wallet_name, const std::string &password)
Rewrites to the wallet file for wallet upgrade (doesn&#39;t generate key, assumes it&#39;s already there) ...
Definition: wallet2.cpp:2541
cryptonote::transaction tx
Definition: wallet2.h:245
Definition: wallet_errors.h:446
bool generate_chacha8_key_from_secret_keys(crypto::chacha8_key &key) const
Definition: wallet2.cpp:2670
bool m_always_confirm_transfers
Definition: wallet2.h:756
void callback(i_wallet2_callback *callback)
Definition: wallet2.h:389
uint64_t get_dynamic_per_kb_fee_estimate()
Definition: wallet2.cpp:3694
Definition: wallet2.h:280
const boost::optional< epee::net_utils::http::login > & get_daemon_login() const
Definition: wallet2.h:615
const uint32_t T[512]
Definition: groestl_tables.h:34
bool testnet() const
Definition: wallet2.h:416
Definition: wallet_errors.h:660
std::string cache_data
Definition: wallet2.h:300
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:5117
crypto::public_key real_out_tx_key
Definition: cryptonote_tx_utils.h:49
Definition: core_rpc_server_commands_defs.h:339
enum tools::wallet2::unconfirmed_transfer_details::@31 m_state
crypto::public_key get_tx_pub_key_from_received_outs(const tools::wallet2::transfer_details &td) const
Definition: wallet2.cpp:5462
std::atomic< bool > m_run
Definition: wallet2.h:746
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:2799
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:2399
uint64_t m_block_height
Definition: wallet2.h:180
Definition: wallet_errors.h:416
void get_hard_fork_info(uint8_t version, uint64_t &earliest_height)
Definition: wallet2.cpp:5054
bool add_address_book_row(const cryptonote::account_public_address &address, const crypto::hash &payment_id, const std::string &description)
Definition: wallet2.cpp:1861
uint64_t m_unlock_time
Definition: wallet2.h:181
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:3153
void commit_tx(pending_tx &ptx_vector)
Definition: wallet2.cpp:3351
bool is_old_file_format
Definition: wallet2.h:754
Definition: unordered_containers_boost_serialization.h:38
const std::string & get_seed_language() const
Gets the seed language.
Definition: wallet2.cpp:589
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:1536
uint64_t m_change
Definition: wallet2.h:202
size_t import_outputs(const std::vector< tools::wallet2::transfer_details > &outputs)
Definition: wallet2.cpp:5737
bool m_ask_password
Definition: wallet2.h:764
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:3497
Definition: wallet2.h:97
Definition: node_rpc_proxy.h:40
bool dust_added_to_fee
Definition: wallet2.h:247
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:2565
void confirm_missing_payment_id(bool always)
Definition: wallet2.h:580
void load_database(const std::string blockchain_db_path)
Definition: wallet2.cpp:1783
Definition: wallet2.h:176
Definition: cryptonote_basic.h:437
uint64_t get_approximate_blockchain_height() const
Calculates the approximate blockchain height from current date/time.
Definition: wallet2.cpp:5402
void parse_block_round(const cryptonote::blobdata &blob, cryptonote::block &bl, crypto::hash &bl_id, bool &error) const
Definition: wallet2.cpp:1232
Definition: cryptonote_protocol_defs.h:110
static const unsigned char iv[64]
Definition: sha512-hash.c:13
uint64_t balance() const
Definition: wallet2.cpp:2900
std::vector< cryptonote::tx_destination_entry > dests
Definition: wallet2.h:253
std::vector< crypto::secret_key > additional_tx_keys
Definition: wallet2.h:252
#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:578
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:2942
void get_unconfirmed_payments(std::list< std::pair< crypto::hash, wallet2::payment_details >> &unconfirmed_payments) const
Definition: wallet2.cpp:2959
POD_CLASS key_derivation
Definition: crypto.h:89
Definition: cryptonote_basic.h:382
unsigned int get_default_decimal_point() const
Definition: wallet2.cpp:2625
void merge_destinations(bool merge)
Definition: wallet2.h:589
std::string path() const
Definition: wallet2.cpp:2789
bool is_transfer_unlocked(const transfer_details &td) const
Definition: wallet2.cpp:3032
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:1239
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:5880
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:2351
std::string sign(const std::string &data) const
Definition: wallet2.cpp:5429
static constexpr const std::chrono::seconds rpc_timeout
Definition: wallet2.h:101
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
bool init(std::string daemon_address="http://localhost:8080", boost::optional< epee::net_utils::http::login > daemon_login=boost::none, std::string blockchain_db_path="", uint64_t upper_transaction_size_limit=0)
Definition: wallet2.cpp:545
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:1115
bool m_physical_refresh
Definition: wallet2.h:774
void stop()
Definition: wallet2.h:386
#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:3414
uint64_t dust
Definition: wallet2.h:246
const cryptonote::account_base & get_account() const
Definition: wallet2.h:372
bool is_synced() const
Definition: wallet2.cpp:6052
std::string key_images
Definition: wallet2.h:250
uint64_t m_timestamp
Definition: wallet2.h:182
std::string get_daemon_address() const
Definition: wallet2.cpp:5350
bool m_restricted
Definition: wallet2.h:752
rct::key m_mask
Definition: wallet2.h:149
std::vector< pending_tx > ptx
Definition: wallet2.h:282
cryptonote::tx_destination_entry change_dts
Definition: wallet2.h:217
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:78
Definition: core_rpc_server_commands_defs.h:110
void print_source_entry(const cryptonote::tx_source_entry &src)
Definition: wallet2.h:1084
crypto namespace.
Definition: crypto.cpp:47
void store_tx_info(bool store)
Definition: wallet2.h:574
void get_payments(const crypto::hash &payment_id, std::list< wallet2::payment_details > &payments, uint64_t min_height=0) const
Definition: wallet2.cpp:2920
Definition: block_queue.cpp:41
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:3733
crypto::hash m_txid
Definition: wallet2.h:143
std::string get_keys_file() const
Definition: wallet2.cpp:5345
uint64_t m_min_output_value
Definition: wallet2.h:766
cryptonote::account_public_address m_address
Definition: wallet2.h:311
Definition: wallet2.h:83
uint64_t m_timestamp
Definition: wallet2.h:206
void rescan_blockchain(bool refresh=true)
Definition: wallet2.cpp:3018
Definition: cryptonote_basic.h:83
std::vector< cryptonote::tx_destination_entry > m_dests
Definition: wallet2.h:204
uint64_t get_per_kb_fee()
Definition: wallet2.cpp:3704
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:3589
static std::unique_ptr< wallet2 > make_from_json(const boost::program_options::variables_map &vm, const std::string &json_file, etneg::MicroCore *core=nullptr, cryptonote::Blockchain *blockchain_storage=nullptr)
Uses stdin and stdout. Returns a wallet2 if no errors.
Definition: wallet2.cpp:494
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:1373
uint64_t m_amount_out
Definition: wallet2.h:189
std::string account_data
Definition: wallet2.h:289
std::unordered_multimap< crypto::hash, payment_details > payment_container
Definition: wallet2.h:238
crypto::hash m_tx_hash
Definition: wallet2.h:178
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:1069
Definition: wallet_errors.h:160
bool rct
Definition: cryptonote_tx_utils.h:53
bool check_connection(uint32_t *version=NULL, uint32_t timeout=200000)
Definition: wallet2.cpp:2636
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:3226
tools::wallet2::RefreshType refresh_type
Definition: simplewallet.cpp:181
uint64_t amount
Definition: cryptonote_tx_utils.h:52
std::string m_daemon_address
Definition: wallet2.h:726
std::vector< size_t > pick_preferred_rct_inputs(uint64_t needed_money) const
Definition: wallet2.cpp:4411
cryptonote::account_public_address addr_for_dust
Definition: wallet2.h:87
bool is_connected_to_db
Definition: wallet2.h:777
bool m_merge_destinations
Definition: wallet2.h:767
Definition: d.py:1
bool clear()
Definition: wallet2.cpp:2064
std::unordered_map< crypto::hash, confirmed_transfer_details > m_confirmed_txs
Definition: wallet2.h:733
uint64_t m_amount_in
Definition: wallet2.h:200
std::string get_tx_note(const crypto::hash &txid) const
Definition: wallet2.cpp:5421
Definition: MicroCore.h:23
bool add_to_fee
Definition: wallet2.h:86
void confirm_backlog(bool always)
Definition: wallet2.h:592
size_t real_output
Definition: cryptonote_tx_utils.h:48
cryptonote::blobdata get_pruned_tx_blob(const cryptonote::blobdata &blobdata)
Definition: wallet2.cpp:1356
cryptonote::Blockchain * get_storage() const
Definition: wallet2.h:666
std::unordered_map< crypto::hash, crypto::secret_key > m_tx_keys
Definition: wallet2.h:735
bool print_ring_members() const
Definition: wallet2.h:571
void set_seed_language(const std::string &language)
Sets the seed language.
Definition: wallet2.cpp:597
bool get_hashes_from_db(const cryptonote::COMMAND_RPC_GET_HASHES_FAST::request &req, cryptonote::COMMAND_RPC_GET_HASHES_FAST::response &res)
Definition: wallet2.cpp:1398
uint64_t unlocked_dust_balance(const tx_dust_policy &dust_policy) const
Definition: wallet2.cpp:5039
RefreshType
Definition: wallet2.h:103
static std::string get_human_readable_timestamp(uint64_t ts)
Check if wallet file path is valid format.
Definition: wallet2.h:543
#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:3126
Definition: wallet2.h:72
bool always_confirm_transfers() const
Definition: wallet2.h:569
#define END_SERIALIZE()
self-explanatory
Definition: serialization.h:207
std::vector< cryptonote::tx_destination_entry > m_dests
Definition: wallet2.h:192
std::vector< cryptonote::tx_source_entry > sources
Definition: wallet2.h:216
std::atomic< uint64_t > m_local_bc_height
Definition: wallet2.h:731
std::vector< std::pair< crypto::key_image, crypto::signature > > export_key_images() const
Definition: wallet2.cpp:5530
const account_keys & get_keys() const
Definition: account.cpp:127
void load(const std::string &wallet, const std::string &password)
Definition: wallet2.cpp:2684
uint64_t unlocked_balance() const
Definition: wallet2.cpp:2890
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:734
Definition: cryptonote_basic.h:172
BOOST_CLASS_VERSION(nodetool::node_server< cryptonote::t_cryptonote_protocol_handler< cryptonote::core > >, 1)
std::vector< tx_out > vout
Definition: cryptonote_basic.h:181
crypto::chacha8_iv iv
Definition: wallet2.h:299
bool is_deprecated() const
Tells if the wallet file is deprecated.
Definition: wallet2.cpp:604
std::vector< tx_construction_data > txes
Definition: wallet2.h:276
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:3211
bool m_testnet
Definition: wallet2.h:751
std::vector< tools::wallet2::address_book_row > m_address_book
Definition: wallet2.h:743
virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction &tx)
Definition: wallet2.h:79
Definition: core_rpc_server_commands_defs.h:310
NodeRPCProxy m_node_rpc_proxy
Definition: wallet2.h:771
std::unordered_map< crypto::public_key, size_t > m_pub_keys
Definition: wallet2.h:740
size_t m_pk_index
Definition: wallet2.h:153
i_wallet2_callback * m_callback
Definition: wallet2.h:750
uint64_t amount() const
Definition: wallet2.h:156
void detach_blockchain(uint64_t height)
Definition: wallet2.cpp:2002
bool m_confirm_backlog
Definition: wallet2.h:768
crypto::public_key m_spend_public_key
Definition: cryptonote_basic.h:423
time_t time
Definition: blockchain.cpp:89
bool m_key_image_known
Definition: wallet2.h:152
Definition: wallet2.h:214
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:3837
std::vector< crypto::hash > m_blockchain
Definition: wallet2.h:730
void set_refresh_type(RefreshType refresh_type)
Definition: wallet2.h:413
Definition: wallet2.h:104
std::vector< transfer_details > transfer_container
Definition: wallet2.h:237
uint64_t m_amount_out
Definition: wallet2.h:201
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:5296
std::vector< uint64_t > amounts
Definition: core_rpc_server_commands_defs.h:312
crypto::public_key m_view_public_key
Definition: cryptonote_basic.h:424
std::vector< pending_tx > create_unmixable_sweep_transactions(bool trusted_daemon)
Definition: wallet2.cpp:5301
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:686
crypto::hash m_payment_id
Definition: wallet2.h:193
bool is_tx_spendtime_unlocked(uint64_t unlock_time, uint64_t block_height) const
Definition: wallet2.cpp:3046
std::unordered_set< crypto::hash > m_scanned_pool_txs[2]
Definition: wallet2.h:772
size_t m_internal_output_index
Definition: wallet2.h:144
uint32_t get_min_output_count() const
Definition: wallet2.h:586
uint64_t outs_count
Definition: core_rpc_server_commands_defs.h:313
uint32_t m_min_output_count
Definition: wallet2.h:765
etneg::MicroCore * get_core() const
Definition: wallet2.h:665
uint64_t m_timestamp
Definition: wallet2.h:195
bool auto_refresh() const
Definition: wallet2.h:577
Definition: wallet_errors.h:152
Various Tools.
Definition: base58.cpp:43
boost::optional< epee::net_utils::http::login > m_daemon_login
Definition: wallet2.h:725
confirmed_transfer_details(const unconfirmed_transfer_details &utd, uint64_t height)
Definition: wallet2.h:210
uint64_t m_global_output_index
Definition: wallet2.h:145
wallet2::transfer_container transfers
Definition: wallet2.h:277
void set_tx_note(const crypto::hash &txid, const std::string &note)
Definition: wallet2.cpp:5416
Definition: cryptonote_tx_utils.h:43
Definition: account.h:57
uint64_t m_unlock_time
Definition: wallet2.h:207
uint64_t get_refresh_from_block_height() const
Definition: wallet2.h:375
uint64_t get_min_output_value() const
Definition: wallet2.h:588
Definition: wallet2.h:107
bool load_keys(const std::string &keys_file_name, const std::string &password)
Load wallet information from wallet file.
Definition: wallet2.cpp:2202
Definition: rctTypes.h:82
#define ts
Definition: skein.c:522
Definition: core_rpc_server_commands_defs.h:80
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:1416
std::vector< cryptonote::tx_destination_entry > splitted_dsts
Definition: wallet2.h:218
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&#39;t generate key, assumes it&#39;s already there) ...
Definition: wallet2.cpp:2554
std::string encrypt(const std::string &plaintext, const crypto::secret_key &skey, bool authenticated=true) const
Definition: wallet2.cpp:5768
Definition: cryptonote_basic.h:130
crypto::hash8 get_short_payment_id(const pending_tx &ptx) const
Definition: wallet2.cpp:3332
#define BEGIN_SERIALIZE_OBJECT()
begins the environment of the DSL for described the serialization of an object
Definition: serialization.h:188
bool get_seed(std::string &electrum_words) const
Definition: wallet2.cpp:568
void generate_genesis(cryptonote::block &b)
Definition: wallet2.cpp:6125
uint64_t get_upper_transaction_size_limit()
Definition: wallet2.cpp:5076
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:246
bool store_tx_info() const
Definition: wallet2.h:573
std::string status
Definition: core_rpc_server_commands_defs.h:342
cryptonote::transaction_prefix m_tx
Definition: wallet2.h:142
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:4471
uint64_t amount
Definition: cryptonote_tx_utils.h:75
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:89
void get_short_chain_history(std::list< crypto::hash > &ids) const
Definition: wallet2.cpp:1205
static std::unique_ptr< wallet2 > make_dummy(const boost::program_options::variables_map &vm, etneg::MicroCore *core=nullptr, cryptonote::Blockchain *blockchain_storage=nullptr)
Just parses variables.
Definition: wallet2.cpp:528
std::list< size_t > selected_transfers
Definition: wallet2.h:249
type
Definition: json.h:74
#define false
Definition: stdbool.h:38
std::string m_wallet_file
Definition: wallet2.h:727
std::string seed_language
Definition: wallet2.h:753
std::string decrypt_with_view_secret_key(const std::string &ciphertext, bool authenticated=true) const
Definition: wallet2.cpp:5819
std::string get_wallet_file() const
Definition: wallet2.cpp:5340
uint64_t m_block_height
Definition: wallet2.h:141
static void init_options(boost::program_options::options_description &desc_params)
Definition: wallet2.cpp:468
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:645
std::vector< tools::wallet2::transfer_details > export_outputs() const
Definition: wallet2.cpp:5722
void display_progress_indicator(bool always)
Definition: wallet2.h:594
std::vector< uint8_t > extra
Definition: wallet2.h:220
Definition: account.h:41
std::tuple< uint64_t, crypto::public_key, rct::key > get_outs_entry
Definition: wallet2.h:316
void store()
Definition: wallet2.cpp:2794
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:625
crypto::hash get_payment_id(const pending_tx &ptx) const
Definition: wallet2.cpp:3307
Definition: core_rpc_server_commands_defs.h:182
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:5644
tx_construction_data construction_data
Definition: wallet2.h:255
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:3202
POD_CLASS public_key
Definition: crypto.h:65
uint64_t get_num_rct_outputs()
Definition: wallet2.cpp:5158
bool deinit()
Definition: wallet2.cpp:2058
static bool wallet_valid_path_format(const std::string &file_path)
Definition: wallet2.cpp:2575
cryptonote::account_base m_account
Definition: wallet2.h:724
bool m_display_progress_indicator
Definition: wallet2.h:769
bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key) const
Definition: wallet2.cpp:5331
bool m_store_tx_info
Definition: wallet2.h:758
bool ask_password() const
Definition: wallet2.h:581
crypto::chacha8_iv iv
Definition: wallet2.h:288
std::vector< uint64_t > get_unspent_amounts_vector()
Definition: wallet2.cpp:5100
static bool parse_short_payment_id(const std::string &payment_id_str, crypto::hash8 &payment_id)
Definition: wallet2.cpp:2593
static std::pair< std::unique_ptr< wallet2 >, password_container > make_new(const boost::program_options::variables_map &vm, etneg::MicroCore *core=nullptr, cryptonote::Blockchain *blockchain_storage=nullptr)
Uses stdin and stdout. Returns a wallet2 and password for wallet with no file if no errors...
Definition: wallet2.cpp:517
void set_refresh_from_block_height(uint64_t height)
Definition: wallet2.h:374
uint8_t version
Definition: blockchain.cpp:86
Definition: wallet2.h:274
payment_container m_payments
Definition: wallet2.h:738
void set_min_output_value(uint64_t value)
Definition: wallet2.h:587
std::string m_keys_file
Definition: wallet2.h:728
bool m_watch_only
Definition: wallet2.h:755
std::string m_description
Definition: wallet2.h:313
account_public_address addr
Definition: cryptonote_tx_utils.h:76
cryptonote::transaction_prefix m_tx
Definition: wallet2.h:187
std::string blobdata
Definition: blobdatatype.h:36
const transfer_details & get_transfer_details(size_t idx) const
Definition: wallet2.cpp:5180
virtual void on_new_block(uint64_t height, const cryptonote::block &block)
Definition: wallet2.h:75
#define blocks
Definition: sha512-hash.c:11
bool confirm_backlog() const
Definition: wallet2.h:591
bool is_deterministic() const
Checks if deterministic wallet.
Definition: wallet2.cpp:559
account_public_address m_account_address
Definition: account.h:43
uint64_t get_daemon_blockchain_height(std::string &err)
Definition: wallet2.cpp:5355
bool use_fork_rules(uint8_t version, int64_t early_blocks=0)
Definition: wallet2.cpp:5060
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:1045
POD_CLASS signature
Definition: crypto.h:99
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:693
Definition: wallet_errors.h:610
Definition: wallet2.h:297
Definition: cryptonote_basic.h:421
cryptonote::account_public_address m_account_public_address
Definition: wallet2.h:741
Definition: wallet_errors.h:652
key identity()
Definition: rctOps.h:75
void set_default_decimal_point(unsigned int decimal_point)
Definition: wallet2.cpp:2620
POD_CLASS hash8
Definition: hash.h:49
bool restricted() const
Definition: wallet2.h:417
uint64_t m_block_height
Definition: wallet2.h:203
Definition: core_rpc_server_commands_defs.h:172
Definition: wallet_errors.h:360
crypto::public_key key
Definition: cryptonote_basic.h:87
void set_blockchain_storage(etneg::MicroCore *core=nullptr, cryptonote::Blockchain *blockchain_storage=nullptr)
Definition: wallet2.cpp:534
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:1094
bool prepare_file_names(const std::string &file_path)
Definition: wallet2.cpp:2630
bool m_rct
Definition: wallet2.h:151
void save_transfers_to_csv(bool in, bool out, uint64_t min_height, uint64_t max_height)
Definition: wallet2.cpp:5186
void check_genesis(const crypto::hash &genesis_hash) const
Definition: wallet2.cpp:2783
POD_CLASS key_image
Definition: crypto.h:93
virtual void on_unconfirmed_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction &tx, uint64_t amount)
Definition: wallet2.h:77
etneg::MicroCore * m_core
Definition: wallet2.h:775
bool confirm_missing_payment_id() const
Definition: wallet2.h:579
uint64_t get_blockchain_height_by_date(uint16_t year, uint8_t month, uint8_t day)
Definition: wallet2.cpp:5966
static const char * tr(const char *str)
Definition: wallet2.cpp:461
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:1135
bool merge_destinations() const
Definition: wallet2.h:590
POD_CLASS secret_key
Definition: crypto.h:69
#define THROW_WALLET_EXCEPTION_IF(cond, err_type,...)
Definition: wallet_errors.h:742
static std::pair< std::unique_ptr< wallet2 >, password_container > make_from_file(const boost::program_options::variables_map &vm, const std::string &wallet_file, etneg::MicroCore *core=nullptr, cryptonote::Blockchain *blockchain_storage=nullptr)
Uses stdin and stdout. Returns a wallet2 and password for wallet_file if no errors.
Definition: wallet2.cpp:500
uint64_t m_change
Definition: wallet2.h:190
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:5824
i_wallet2_callback * callback() const
Definition: wallet2.h:388
txout_target_v target
Definition: cryptonote_basic.h:152
std::vector< cryptonote::tx_destination_entry > dests
Definition: wallet2.h:223
std::unordered_map< crypto::hash, std::string > m_tx_notes
Definition: wallet2.h:742
crypto::hash m_payment_id
Definition: wallet2.h:312
size_t real_output_in_tx_index
Definition: cryptonote_tx_utils.h:51
string a
Definition: MakeCryptoOps.py:15
static bool has_testnet_option(const boost::program_options::variables_map &vm)
Definition: wallet2.cpp:463
crypto::hash get_transaction_hash(const transaction &t)
Definition: cryptonote_format_utils.cpp:575
std::vector< outs_for_amount > outs
Definition: core_rpc_server_commands_defs.h:341
void always_confirm_transfers(bool always)
Definition: wallet2.h:570
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:157
confirmed_transfer_details()
Definition: wallet2.h:209
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:2089
void set_spent(size_t idx, uint64_t height)
Definition: wallet2.cpp:609
bool verify(const std::string &data, const cryptonote::account_public_address &address, const std::string &signature) const
Definition: wallet2.cpp:5439
wallet2(bool testnet=false, bool restricted=false)
Definition: wallet2.h:137
uint64_t m_refresh_from_block_height
Definition: wallet2.h:762
crypto::key_image m_key_image
Definition: wallet2.h:148
cryptonote::Blockchain * m_blockchain_storage
Definition: wallet2.h:776
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:601
std::vector< size_t > select_available_unmixable_outputs(bool trusted_daemon)
Definition: wallet2.cpp:5289
RefreshType get_refresh_type() const
Definition: wallet2.h:414
Definition: cryptonote_tx_utils.h:73
void get_unconfirmed_payments_out(std::list< std::pair< crypto::hash, wallet2::unconfirmed_transfer_details >> &unconfirmed_payments) const
Definition: wallet2.cpp:2952
uint64_t dust_threshold
Definition: wallet2.h:85
static boost::optional< password_container > password_prompt(const bool new_password)
Definition: wallet2.cpp:482
std::vector< size_t > select_available_outputs(const std::function< bool(const transfer_details &td)> &f)
Definition: wallet2.cpp:5084
uint64_t get_fee_multiplier(uint32_t priority, int fee_algorithm=-1)
Definition: wallet2.cpp:3655
Definition: wallet2.h:243
std::unordered_map< crypto::hash, unconfirmed_transfer_details > m_unconfirmed_txs
Definition: wallet2.h:732
bool m_print_ring_members
Definition: wallet2.h:757
bool delete_address_book_row(std::size_t row_id)
Definition: wallet2.cpp:1875
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:371
POD_CLASS hash
Definition: hash.h:46
uint64_t m_amount
Definition: wallet2.h:179
cryptonote::tx_destination_entry change_dts
Definition: wallet2.h:248
uint64_t get_blockchain_current_height() const
Definition: wallet2.h:462
bool get_blocks_from_db(const cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::request &req, cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::response &res)
Definition: wallet2.cpp:1296
crypto::secret_key tx_key
Definition: wallet2.h:251
Definition: wallet2.h:286
std::string to_string(t_connection_type type)
Definition: connection_basic.cpp:96
void print_ring_members(bool value)
Definition: wallet2.h:572
uint32_t m_default_priority
Definition: wallet2.h:759
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:4504
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:554
std::string decrypt(const std::string &ciphertext, const crypto::secret_key &skey, bool authenticated=true) const
Definition: wallet2.cpp:5794
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:800
transfer_container m_transfers
Definition: wallet2.h:737
bool is_rct() const
Definition: wallet2.h:155
#define FIELD(f)
tags the field with the variable name and then serializes it
Definition: serialization.h:236
uint32_t get_default_priority() const
Definition: wallet2.h:575
virtual void on_money_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction &tx, uint64_t amount)
Definition: wallet2.h:76
uint64_t m_amount_in
Definition: wallet2.h:188
bool load_unsigned_tx(const std::string &unsigned_filename, unsigned_tx_set &exported_txs)
Definition: wallet2.cpp:3459
RefreshType m_refresh_type
Definition: wallet2.h:760
std::unordered_map< crypto::key_image, size_t > m_key_images
Definition: wallet2.h:739
bool m_confirm_missing_payment_id
Definition: wallet2.h:763
Definition: wallet2.h:106
std::list< out_entry > outs
Definition: core_rpc_server_commands_defs.h:331
uint64_t m_upper_transaction_size_limit
Definition: wallet2.h:744
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:6061
crypto::hash m_payment_id
Definition: wallet2.h:205
const crypto::public_key & get_public_key() const
Definition: wallet2.h:157
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:4903
time_t m_sent_time
Definition: wallet2.h:191
bool m_is_initialized
Definition: wallet2.h:770
Definition: cryptonote_basic.h:198
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:4215
void set_default_priority(uint32_t p)
Definition: wallet2.h:576
std::string encrypt_with_view_secret_key(const std::string &plaintext, bool authenticated=true) const
Definition: wallet2.cpp:5789
#define true
Definition: stdbool.h:37
void set_min_output_count(uint32_t count)
Definition: wallet2.h:585
Definition: wallet_errors.h:545
virtual ~i_wallet2_callback()
Definition: wallet2.h:80
boost::mutex m_daemon_rpc_mutex
Definition: wallet2.h:748
void update_pool_state(bool refreshed=false)
Definition: wallet2.cpp:1562
static bool parse_payment_id(const std::string &payment_id_str, crypto::hash &payment_id)
Definition: wallet2.cpp:2606
bool use_rct
Definition: wallet2.h:222
uint64_t m_amount
Definition: wallet2.h:150
bool m_spent
Definition: wallet2.h:146
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:4540
uint64_t m_spent_height
Definition: wallet2.h:147
uint64_t fee
Definition: wallet2.h:246
void refresh()
Definition: wallet2.cpp:1524
Definition: wallet2.h:309
uint64_t get_daemon_blockchain_target_height(std::string &err)
Definition: wallet2.cpp:5370
wallet2(const wallet2 &)
Definition: wallet2.h:111
bool m_auto_refresh
Definition: wallet2.h:761
int get_fee_algorithm()
Definition: wallet2.cpp:3717
Definition: blockchain.h:80
Definition: wallet2.h:139
void serialize(t_archive &a, const unsigned int ver)
Definition: wallet2.h:467
void ask_password(bool always)
Definition: wallet2.h:582
void get_transfers(wallet2::transfer_container &incoming_transfers) const
Definition: wallet2.cpp:2915
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:4874