Electroneum
Loading...
Searching...
No Matches
simplewallet.h
Go to the documentation of this file.
1// Copyrights(c) 2017-2021, The Electroneum Project
2// Copyrights(c) 2014-2019, 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
37#pragma once
38
39#include <memory>
40
41#include <boost/optional/optional.hpp>
42#include <boost/program_options/variables_map.hpp>
43
46#include "wallet/wallet2.h"
47#include "console_handler.h"
48#include "wipeable_string.h"
49#include "common/i18n.h"
50#include "common/password.h"
51#include "crypto/crypto.h" // for definition of crypto::secret_key
52
53#undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
54#define ELECTRONEUM_DEFAULT_LOG_CATEGORY "wallet.simplewallet"
55// Hardcode Electroneum's donation address (see #1447)
56constexpr const char ETN_DONATION_ADDR[] = "etnjwQwwEY65dhSMfKto64GgY7j7q2RUSZP1r8rXZ615J4egUC596R4crvZ5woWWTWBUztnKMUudzQ22E37LHiV48XWeJDFkkY";
57
62namespace cryptonote
63{
68 {
69 public:
70 static const char *tr(const char *str) { return i18n_translate(str, "cryptonote::simple_wallet"); }
71
72 public:
73 typedef std::vector<std::string> command_type;
74
76 bool init(const boost::program_options::variables_map& vm);
77 bool deinit();
78 bool run();
79 void stop();
80 void interrupt();
81
82 //wallet *create_wallet();
83 bool process_command(const std::vector<std::string> &args);
84 std::string get_commands_str();
85 std::string get_command_usage(const std::vector<std::string> &args);
86 private:
87
88 enum ResetType { ResetNone, ResetSoft, ResetHard, ResetSoftKeepKI };
89
90 bool handle_command_line(const boost::program_options::variables_map& vm);
91
92 bool run_console_handler();
93
94 void wallet_idle_thread();
95
97 boost::optional<tools::password_container> get_and_verify_password() const;
98
99 boost::optional<epee::wipeable_string> new_wallet(const boost::program_options::variables_map& vm, const crypto::secret_key& recovery_key,
100 bool recover, bool two_random, const std::string &old_language);
101 boost::optional<epee::wipeable_string> new_wallet(const boost::program_options::variables_map& vm, const cryptonote::account_public_address& address,
102 const boost::optional<crypto::secret_key>& spendkey, const crypto::secret_key& viewkey);
103 boost::optional<epee::wipeable_string> new_wallet(const boost::program_options::variables_map& vm,
104 const epee::wipeable_string &multisig_keys, const std::string &old_language);
105 boost::optional<epee::wipeable_string> new_wallet(const boost::program_options::variables_map& vm);
106 boost::optional<epee::wipeable_string> open_wallet(const boost::program_options::variables_map& vm);
107 bool close_wallet();
108
109 bool viewkey(const std::vector<std::string> &args = std::vector<std::string>());
110 bool spendkey(const std::vector<std::string> &args = std::vector<std::string>());
111 bool seed(const std::vector<std::string> &args = std::vector<std::string>());
112 bool encrypted_seed(const std::vector<std::string> &args = std::vector<std::string>());
113
123 bool seed_set_language(const std::vector<std::string> &args = std::vector<std::string>());
124 bool set_always_confirm_transfers(const std::vector<std::string> &args = std::vector<std::string>());
125 bool set_print_ring_members(const std::vector<std::string> &args = std::vector<std::string>());
126 bool set_store_tx_info(const std::vector<std::string> &args = std::vector<std::string>());
127 bool set_auto_refresh(const std::vector<std::string> &args = std::vector<std::string>());
128 bool set_refresh_type(const std::vector<std::string> &args = std::vector<std::string>());
129 bool set_confirm_missing_payment_id(const std::vector<std::string> &args = std::vector<std::string>());
130 bool set_ask_password(const std::vector<std::string> &args = std::vector<std::string>());
131 bool set_unit(const std::vector<std::string> &args = std::vector<std::string>());
132 bool set_min_output_count(const std::vector<std::string> &args = std::vector<std::string>());
133 bool set_min_output_value(const std::vector<std::string> &args = std::vector<std::string>());
134 bool set_merge_destinations(const std::vector<std::string> &args = std::vector<std::string>());
135 bool set_confirm_backlog(const std::vector<std::string> &args = std::vector<std::string>());
136 bool set_confirm_backlog_threshold(const std::vector<std::string> &args = std::vector<std::string>());
137 bool set_confirm_export_overwrite(const std::vector<std::string> &args = std::vector<std::string>());
138 bool set_refresh_from_block_height(const std::vector<std::string> &args = std::vector<std::string>());
139 bool set_auto_low_priority(const std::vector<std::string> &args = std::vector<std::string>());
140 bool set_segregate_pre_fork_outputs(const std::vector<std::string> &args = std::vector<std::string>());
141 bool set_key_reuse_mitigation2(const std::vector<std::string> &args = std::vector<std::string>());
142 bool set_subaddress_lookahead(const std::vector<std::string> &args = std::vector<std::string>());
143 bool set_segregation_height(const std::vector<std::string> &args = std::vector<std::string>());
144 bool set_ignore_fractional_outputs(const std::vector<std::string> &args = std::vector<std::string>());
145 bool set_track_uses(const std::vector<std::string> &args = std::vector<std::string>());
146 bool set_setup_background_mining(const std::vector<std::string> &args = std::vector<std::string>());
147 bool set_device_name(const std::vector<std::string> &args = std::vector<std::string>());
148 bool help(const std::vector<std::string> &args = std::vector<std::string>());
149 bool start_mining(const std::vector<std::string> &args);
150 bool stop_mining(const std::vector<std::string> &args);
151 bool set_daemon(const std::vector<std::string> &args);
152 bool save_bc(const std::vector<std::string> &args);
153 bool refresh(const std::vector<std::string> &args);
154 bool show_balance_unlocked(bool detailed = false);
155 bool show_balance(const std::vector<std::string> &args = std::vector<std::string>());
156 bool show_incoming_transfers(const std::vector<std::string> &args);
157 bool show_payments(const std::vector<std::string> &args);
158 bool show_blockchain_height(const std::vector<std::string> &args);
159 bool transfer_main(int transfer_type, const std::vector<std::string> &args, bool called_by_mms);
160 bool transfer(const std::vector<std::string> &args);
161 bool locked_transfer(const std::vector<std::string> &args);
162 bool locked_sweep_all(const std::vector<std::string> &args);
163 bool sweep_main(uint64_t below, bool locked, const std::vector<std::string> &args);
164 bool sweep_all(const std::vector<std::string> &args);
165 bool sweep_below(const std::vector<std::string> &args);
166 bool sweep_single(const std::vector<std::string> &args);
167 bool sweep_unmixable(const std::vector<std::string> &args);
168 bool donate(const std::vector<std::string> &args);
169 bool sign_transfer(const std::vector<std::string> &args);
170 bool submit_transfer(const std::vector<std::string> &args);
171 std::vector<std::vector<cryptonote::tx_destination_entry>> split_amounts(
172 std::vector<cryptonote::tx_destination_entry> dsts, size_t num_splits
173 );
174 bool account(const std::vector<std::string> &args = std::vector<std::string>());
175 void print_accounts();
176 void print_accounts(const std::string& tag);
177 bool print_address(const std::vector<std::string> &args = std::vector<std::string>());
178 bool print_integrated_address(const std::vector<std::string> &args = std::vector<std::string>());
179 bool address_book(const std::vector<std::string> &args = std::vector<std::string>());
180 bool save(const std::vector<std::string> &args);
181 bool save_watch_only(const std::vector<std::string> &args);
182 bool set_variable(const std::vector<std::string> &args);
183 bool rescan_spent(const std::vector<std::string> &args);
184 bool set_log(const std::vector<std::string> &args);
185 bool get_tx_key(const std::vector<std::string> &args);
186 bool set_tx_key(const std::vector<std::string> &args);
187 bool check_tx_key(const std::vector<std::string> &args);
188 bool get_tx_proof(const std::vector<std::string> &args);
189 bool check_tx_proof(const std::vector<std::string> &args);
190 bool get_spend_proof(const std::vector<std::string> &args);
191 bool check_spend_proof(const std::vector<std::string> &args);
192 bool get_reserve_proof(const std::vector<std::string> &args);
193 bool check_reserve_proof(const std::vector<std::string> &args);
194 bool show_transfers(const std::vector<std::string> &args);
195 bool export_transfers(const std::vector<std::string> &args);
196 bool unspent_outputs(const std::vector<std::string> &args);
197 bool rescan_blockchain(const std::vector<std::string> &args);
198 bool refresh_main(uint64_t start_height, ResetType reset, bool is_init = false);
199 bool set_tx_note(const std::vector<std::string> &args);
200 bool get_tx_note(const std::vector<std::string> &args);
201 bool set_description(const std::vector<std::string> &args);
202 bool get_description(const std::vector<std::string> &args);
203 bool status(const std::vector<std::string> &args);
204 bool wallet_info(const std::vector<std::string> &args);
205 bool set_default_ring_size(const std::vector<std::string> &args);
206 bool set_default_priority(const std::vector<std::string> &args);
207 bool sign(const std::vector<std::string> &args);
208 bool verify(const std::vector<std::string> &args);
209 bool export_key_images(const std::vector<std::string> &args);
210 bool import_key_images(const std::vector<std::string> &args);
211 bool hw_key_images_sync(const std::vector<std::string> &args);
212 bool hw_reconnect(const std::vector<std::string> &args);
213 bool export_outputs(const std::vector<std::string> &args);
214 bool import_outputs(const std::vector<std::string> &args);
215 bool show_transfer(const std::vector<std::string> &args);
216 bool change_password(const std::vector<std::string>& args);
217 bool payment_id(const std::vector<std::string> &args);
218 bool print_fee_info(const std::vector<std::string> &args);
219 bool prepare_multisig(const std::vector<std::string>& args);
220 bool prepare_multisig_main(const std::vector<std::string>& args, bool called_by_mms);
221 bool make_multisig(const std::vector<std::string>& args);
222 bool make_multisig_main(const std::vector<std::string>& args, bool called_by_mms);
223 bool finalize_multisig(const std::vector<std::string> &args);
224 bool exchange_multisig_keys(const std::vector<std::string> &args);
225 bool exchange_multisig_keys_main(const std::vector<std::string> &args, bool called_by_mms);
226 bool export_multisig(const std::vector<std::string>& args);
227 bool export_multisig_main(const std::vector<std::string>& args, bool called_by_mms);
228 bool import_multisig(const std::vector<std::string>& args);
229 bool import_multisig_main(const std::vector<std::string>& args, bool called_by_mms);
230 bool accept_loaded_tx(const tools::wallet2::multisig_tx_set &txs);
231 bool sign_multisig(const std::vector<std::string>& args);
232 bool sign_multisig_main(const std::vector<std::string>& args, bool called_by_mms);
233 bool submit_multisig(const std::vector<std::string>& args);
234 bool submit_multisig_main(const std::vector<std::string>& args, bool called_by_mms);
235 bool export_raw_multisig(const std::vector<std::string>& args);
236 bool mms(const std::vector<std::string>& args);
237 bool print_ring(const std::vector<std::string>& args);
238 bool set_ring(const std::vector<std::string>& args);
239 bool unset_ring(const std::vector<std::string>& args);
240 bool save_known_rings(const std::vector<std::string>& args);
241 bool blackball(const std::vector<std::string>& args);
242 bool unblackball(const std::vector<std::string>& args);
243 bool blackballed(const std::vector<std::string>& args);
244 bool freeze(const std::vector<std::string>& args);
245 bool thaw(const std::vector<std::string>& args);
246 bool frozen(const std::vector<std::string>& args);
247 bool net_stats(const std::vector<std::string>& args);
248 bool welcome(const std::vector<std::string>& args);
249 bool version(const std::vector<std::string>& args);
250
251 bool set_account_major_offset(const std::vector<std::string> &args = std::vector<std::string>());
252
253 bool cold_sign_tx(const std::vector<tools::wallet2::pending_tx>& ptx_vector, tools::wallet2::signed_tx_set &exported_txs, std::vector<cryptonote::address_parse_info> &dsts_info, std::function<bool(const tools::wallet2::signed_tx_set &)> accept_func);
254 uint64_t get_daemon_blockchain_height(std::string& err);
255 bool try_connect_to_daemon(bool silent = false, uint32_t* version = nullptr);
256 bool ask_wallet_create_if_needed();
257 bool accept_loaded_tx(const std::function<size_t()> get_num_txes, const std::function<const tools::wallet2::tx_construction_data&(size_t)> &get_tx, const std::string &extra_message = std::string());
258 bool accept_loaded_tx(const tools::wallet2::unsigned_tx_set &txs);
259 bool accept_loaded_tx(const tools::wallet2::signed_tx_set &txs);
260 bool print_ring_members(const std::vector<tools::wallet2::pending_tx>& ptx_vector, std::ostream& ostr);
261 std::string get_prompt() const;
262 bool print_seed(bool encrypted);
263 void key_images_sync_intern();
264 void on_refresh_finished(uint64_t start_height, uint64_t fetched_blocks, bool is_init, bool received_etn);
265 std::pair<std::string, std::string> show_outputs_line(const std::vector<uint64_t> &heights, uint64_t blockchain_height, uint64_t highlight_height = std::numeric_limits<uint64_t>::max()) const;
266 bool freeze_thaw(const std::vector<std::string>& args, bool freeze);
267
268 struct transfer_view
269 {
270 std::string type;
271 boost::variant<uint64_t, std::string> block;
272 uint64_t timestamp;
273 std::string direction;
274 bool confirmed;
275 uint64_t amount;
276 crypto::hash hash;
277 std::string payment_id;
278 uint64_t fee;
279 std::vector<std::pair<std::string, uint64_t>> outputs;
280 std::set<uint32_t> index;
281 std::string note;
282 std::string unlocked;
283 };
284 bool get_transfers(std::vector<std::string>& args_, std::vector<transfer_view>& transfers);
285
290 void print_seed(const epee::wipeable_string &seed);
291
299 std::string get_mnemonic_language();
300
305 void commit_or_save(std::vector<tools::wallet2::pending_tx>& ptx_vector, bool do_not_relay);
306
310 void check_background_mining(const epee::wipeable_string &password);
311 void start_background_mining();
312 void stop_background_mining();
313
314 //----------------- i_wallet2_callback ---------------------
315 virtual void on_new_block(uint64_t height, const cryptonote::block& block);
316 virtual void on_etn_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index, uint64_t unlock_time);
317 virtual void on_unconfirmed_etn_received(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t amount, const cryptonote::subaddress_index& subaddr_index);
318 virtual void on_etn_spent(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& in_tx, uint64_t amount, const cryptonote::transaction& spend_tx, const cryptonote::subaddress_index& subaddr_index);
319 virtual void on_skip_transaction(uint64_t height, const crypto::hash &txid, const cryptonote::transaction& tx);
320 virtual boost::optional<epee::wipeable_string> on_get_password(const char *reason);
321 virtual void on_device_button_request(uint64_t code);
322 virtual boost::optional<epee::wipeable_string> on_device_pin_request();
323 virtual boost::optional<epee::wipeable_string> on_device_passphrase_request(bool on_device);
324 //----------------------------------------------------------
325
326 friend class refresh_progress_reporter_t;
327
328 class refresh_progress_reporter_t
329 {
330 public:
332 : m_simple_wallet(simple_wallet)
333 , m_blockchain_height(0)
334 , m_blockchain_height_update_time()
335 , m_print_time()
336 {
337 }
338
339 void update(uint64_t height, bool force = false)
340 {
341 auto current_time = std::chrono::system_clock::now();
342 const auto node_update_threshold = std::chrono::seconds(DIFFICULTY_TARGET / 2); // use min of V1/V2
343 if (node_update_threshold < current_time - m_blockchain_height_update_time || m_blockchain_height <= height)
344 {
345 update_blockchain_height();
346 m_blockchain_height = (std::max)(m_blockchain_height, height);
347 }
348
349 if (std::chrono::milliseconds(20) < current_time - m_print_time || force)
350 {
351 std::cout << QT_TRANSLATE_NOOP("cryptonote::simple_wallet", "Height ") << height << " / " << m_blockchain_height << '\r' << std::flush;
352 m_print_time = current_time;
353 }
354 }
355
356 private:
357 void update_blockchain_height()
358 {
359 std::string err;
360 uint64_t blockchain_height = m_simple_wallet.get_daemon_blockchain_height(err);
361 if (err.empty())
362 {
363 m_blockchain_height = blockchain_height;
364 m_blockchain_height_update_time = std::chrono::system_clock::now();
365 }
366 else
367 {
368 LOG_ERROR("Failed to get current blockchain height: " << err);
369 }
370 }
371
372 private:
373 cryptonote::simple_wallet& m_simple_wallet;
374 uint64_t m_blockchain_height;
375 std::chrono::system_clock::time_point m_blockchain_height_update_time;
376 std::chrono::system_clock::time_point m_print_time;
377 };
378
379 private:
380 std::string m_wallet_file;
381 std::string m_generate_new;
382 std::string m_generate_from_device;
383 std::string m_generate_from_view_key;
384 std::string m_generate_from_spend_key;
385 std::string m_generate_from_keys;
386 std::string m_generate_from_multisig_keys;
387 std::string m_generate_from_json;
388 std::string m_mnemonic_language;
389 std::string m_import_path;
390 std::string m_subaddress_lookahead;
391 std::string m_restore_date; // optional - converted to m_restore_height
392
393 epee::wipeable_string m_electrum_seed; // electrum-style seed parameter
394
395 crypto::secret_key m_recovery_key; // recovery key (used as random for wallet gen)
396 bool m_restore_deterministic_wallet; // recover flag
397 bool m_restore_multisig_wallet; // recover flag
398 bool m_non_deterministic; // old 2-random generation
399 bool m_allow_mismatched_daemon_version;
400 bool m_restoring; // are we restoring, by whatever method?
401 uint64_t m_restore_height; // optional
402 bool m_do_not_relay;
403 bool m_use_english_language_names;
404 uint32_t m_account_major_offset;
405
406 epee::console_handlers_binder m_cmd_binder;
407
408 std::unique_ptr<tools::wallet2> m_wallet;
409 refresh_progress_reporter_t m_refresh_progress_reporter;
410
411 std::atomic<bool> m_idle_run;
412 boost::thread m_idle_thread;
413 boost::mutex m_idle_mutex;
414 boost::condition_variable m_idle_cond;
415
416 std::atomic<bool> m_auto_refresh_enabled;
417 bool m_auto_refresh_refreshing;
418 std::atomic<bool> m_in_manual_refresh;
419 uint32_t m_current_subaddress_account;
420
421 bool m_long_payment_id_support;
422
423 // MMS
424 mms::message_store& get_message_store() const { return m_wallet->get_message_store(); };
425 mms::multisig_wallet_state get_multisig_wallet_state() const { return m_wallet->get_multisig_wallet_state(); };
426 bool mms_active() const { return get_message_store().get_active(); };
427 bool choose_mms_processing(const std::vector<mms::processing_data> &data_list, uint32_t &choice);
428 void list_mms_messages(const std::vector<mms::message> &messages);
429 void list_signers(const std::vector<mms::authorized_signer> &signers);
430 void add_signer_config_messages();
431 void show_message(const mms::message &m);
432 void ask_send_all_ready_messages();
433 void check_for_messages();
434 bool user_confirms(const std::string &question);
435 bool get_message_from_arg(const std::string &arg, mms::message &m);
436 bool get_number_from_arg(const std::string &arg, uint32_t &number, const uint32_t lower_bound, const uint32_t upper_bound);
437
438 void mms_init(const std::vector<std::string> &args);
439 void mms_info(const std::vector<std::string> &args);
440 void mms_signer(const std::vector<std::string> &args);
441 void mms_list(const std::vector<std::string> &args);
442 void mms_next(const std::vector<std::string> &args);
443 void mms_sync(const std::vector<std::string> &args);
444 void mms_transfer(const std::vector<std::string> &args);
445 void mms_delete(const std::vector<std::string> &args);
446 void mms_send(const std::vector<std::string> &args);
447 void mms_receive(const std::vector<std::string> &args);
448 void mms_export(const std::vector<std::string> &args);
449 void mms_note(const std::vector<std::string> &args);
450 void mms_show(const std::vector<std::string> &args);
451 void mms_set(const std::vector<std::string> &args);
452 void mms_help(const std::vector<std::string> &args);
453 void mms_send_signer_config(const std::vector<std::string> &args);
454 void mms_start_auto_config(const std::vector<std::string> &args);
455 void mms_stop_auto_config(const std::vector<std::string> &args);
456 void mms_auto_config(const std::vector<std::string> &args);
457 };
458}
uint64_t height
uint8_t version
Manages wallet operations. This is the most abstracted wallet class.
std::vector< std::string > command_type
std::string get_command_usage(const std::vector< std::string > &args)
friend class refresh_progress_reporter_t
bool init(const boost::program_options::variables_map &vm)
static const char * tr(const char *str)
bool process_command(const std::vector< std::string > &args)
virtual boost::optional< epee::wipeable_string > on_device_pin_request()
Definition wallet2.h:141
#define DIFFICULTY_TARGET
const char * i18n_translate(const char *s, const std::string &context)
Definition i18n.cpp:323
#define QT_TRANSLATE_NOOP(context, str)
Definition i18n.h:32
#define LOG_ERROR(x)
Definition misc_log_ex.h:98
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition crypto.h:82
POD_CLASS hash
Definition hash.h:50
Holds cryptonote related classes and helpers.
Definition ban.cpp:40
constexpr const char ETN_DONATION_ADDR[]
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
const char * address
Definition multisig.cpp:37
const char * spendkey
Definition multisig.cpp:38