From d2644c15c34a9a9b95aa3051ebbfdd259dced3f3 Mon Sep 17 00:00:00 2001 From: luigi1111 Date: Tue, 9 Aug 2016 17:46:49 -0500 Subject: fix restore-deterministic height Simplewallet improperly skipped the restore from height code if restoring a deterministic wallet AND not specifying a wallet file in the command line. The other generate options require a wallet file as an argument, which prevents "ask_wallet_create_if_needed()" from being called, which in turn causes "m_generate_new" to remain unset. Specifying a wallet file at launch with --restore-deterministic emulated this behavior. --- src/simplewallet/simplewallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index a3a4685b5..2d2de89b0 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1259,7 +1259,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) return false; } } - if (!m_restore_height && m_generate_new.empty()) + if (!m_restore_height && (m_generate_new.empty() || m_restore_deterministic_wallet)) { std::string heightstr = command_line::input_line("Restore from specific blockchain height (optional, default 0): "); if (std::cin.eof()) @@ -1546,7 +1546,7 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string m_wallet->set_seed_language(mnemonic_language); // for a totally new account, we don't care about older blocks. - if (!m_generate_new.empty()) + if (!m_generate_new.empty() && !m_restore_deterministic_wallet) { std::string err; m_wallet->set_refresh_from_block_height(get_daemon_blockchain_height(err)); -- cgit v1.2.3 From 709c7247cd525952e89c4b8975171152a3969d92 Mon Sep 17 00:00:00 2001 From: hyc Date: Wed, 10 Aug 2016 00:54:20 +0100 Subject: Better fix (#4) --- src/simplewallet/simplewallet.cpp | 12 ++++++++---- src/simplewallet/simplewallet.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 2d2de89b0..e4a771017 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -851,7 +851,7 @@ bool simple_wallet::ask_wallet_create_if_needed() // add logic to error out if new wallet requested but named wallet file exists if (keys_file_exists || wallet_file_exists) { - if (!m_generate_new.empty() || m_restore_deterministic_wallet || !m_generate_from_view_key.empty() || !m_generate_from_keys.empty() || !m_generate_from_json.empty()) + if (!m_generate_new.empty() || m_restoring) { fail_msg_writer() << tr("attempting to generate or restore wallet, but specified file(s) exist. Exiting to not risk overwriting."); return false; @@ -1227,7 +1227,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) if (!get_password(vm, true, pwd_container)) return false; - if (!m_generate_new.empty() || m_restore_deterministic_wallet || !m_generate_from_view_key.empty() || !m_generate_from_keys.empty() || !m_generate_from_json.empty()) + if (!m_generate_new.empty() || m_restoring) { if (m_wallet_file.empty()) m_wallet_file = m_generate_new; // alias for simplicity later @@ -1259,7 +1259,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) return false; } } - if (!m_restore_height && (m_generate_new.empty() || m_restore_deterministic_wallet)) + if (!m_restore_height && m_restoring) { std::string heightstr = command_line::input_line("Restore from specific blockchain height (optional, default 0): "); if (std::cin.eof()) @@ -1447,6 +1447,10 @@ bool simple_wallet::handle_command_line(const boost::program_options::variables_ m_trusted_daemon = command_line::get_arg(vm, arg_trusted_daemon); m_allow_mismatched_daemon_version = command_line::get_arg(vm, arg_allow_mismatched_daemon_version); m_restore_height = command_line::get_arg(vm, arg_restore_height); + m_restoring = !m_generate_from_view_key.empty() || + !m_generate_from_keys.empty() || + !m_generate_from_json.empty() || + m_restore_deterministic_wallet; return true; } @@ -1546,7 +1550,7 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string m_wallet->set_seed_language(mnemonic_language); // for a totally new account, we don't care about older blocks. - if (!m_generate_new.empty() && !m_restore_deterministic_wallet) + if (!m_restoring) { std::string err; m_wallet->set_refresh_from_block_height(get_daemon_blockchain_height(err)); diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index b35ca0866..46357cfc0 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -243,6 +243,7 @@ namespace cryptonote bool m_non_deterministic; // old 2-random generation bool m_trusted_daemon; bool m_allow_mismatched_daemon_version; + bool m_restoring; // are we restoring, by whatever method? uint64_t m_restore_height; // optional std::string m_daemon_address; -- cgit v1.2.3