aboutsummaryrefslogtreecommitdiff
path: root/src/simplewallet
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2014-12-01 20:14:58 +0200
committerRiccardo Spagni <ric@spagni.net>2014-12-01 20:15:06 +0200
commit4cd15cdde58c00bfcde5af1c9f57779e62a76f2f (patch)
tree89b46555ee93ac9eb2af22afae639a51d904d090 /src/simplewallet
parentMerge pull request #191 (diff)
parentPrints seed after wallet upgrade. Removed iostream include. (diff)
downloadmonero-4cd15cdde58c00bfcde5af1c9f57779e62a76f2f.tar.xz
Merge pull request #1
f1eaf88 Prints seed after wallet upgrade. Removed iostream include. (Oran Juice) 70971be Doxygen comments (Oran Juice) 031ca23 Rewrites to old wallet file correctly (Oran Juice) 1f833dc Doxygen comments in (Oran Juice) 0bd88ff Writes seed language while generating wallet. Wallet open fix. (Oran Juice) 09a659e Stores seed language in wallet file. added rapidjson. Yet to test backward compatibility (Oran Juice)
Diffstat (limited to 'src/simplewallet')
-rw-r--r--src/simplewallet/simplewallet.cpp70
-rw-r--r--src/simplewallet/simplewallet.h5
2 files changed, 54 insertions, 21 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 5bc8090a8..84e134fed 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -317,6 +317,21 @@ bool simple_wallet::ask_wallet_create_if_needed()
return r;
}
+
+/*!
+ * \brief Prints the seed with a nice message
+ * \param seed seed to print
+ */
+void simple_wallet::print_seed(std::string seed)
+{
+ success_msg_writer(true) << "\nPLEASE NOTE: the following 25 words can be used to recover access to your wallet. " <<
+ "Please write them down and store them somewhere safe and secure. Please do not store them in " <<
+ "your email or on file storage services outside of your immediate control.\n";
+ boost::replace_nth(seed, " ", 15, "\n");
+ boost::replace_nth(seed, " ", 7, "\n");
+ std::cout << seed << std::endl;
+}
+
//----------------------------------------------------------------------------------------------------
bool simple_wallet::init(const boost::program_options::variables_map& vm)
{
@@ -485,10 +500,28 @@ std::string simple_wallet::get_mnemonic_language()
bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string& password, const crypto::secret_key& recovery_key,
bool recover, bool two_random, bool testnet, const std::string &old_language)
{
+ bool was_deprecated_wallet = m_restore_deterministic_wallet && ((old_language == crypto::ElectrumWords::old_language_name) ||
+ crypto::ElectrumWords::get_is_old_style_seed(m_electrum_seed));
+
+ std::string mnemonic_language = old_language;
+ // Ask for seed language if it is not a wallet restore or if it was a deprecated wallet
+ // that was earlier used before this restore.
+ if (!m_restore_deterministic_wallet || was_deprecated_wallet)
+ {
+ if (was_deprecated_wallet)
+ {
+ // The user had used an older version of the wallet with old style mnemonics.
+ message_writer(epee::log_space::console_color_green, false) << "\nYou had been using " <<
+ "a deprecated version of the wallet. Please use the new seed that we provide.\n";
+ }
+ mnemonic_language = get_mnemonic_language();
+ }
+
m_wallet_file = wallet_file;
m_wallet.reset(new tools::wallet2(testnet));
m_wallet->callback(this);
+ m_wallet->set_seed_language(mnemonic_language);
crypto::secret_key recovery_val;
try
@@ -509,24 +542,7 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string
// convert rng value to electrum-style word list
std::string electrum_words;
- bool was_deprecated_wallet = (old_language == crypto::ElectrumWords::old_language_name) ||
- crypto::ElectrumWords::get_is_old_style_seed(m_electrum_seed);
-
- std::string mnemonic_language = old_language;
- // Ask for seed language if it is not a wallet restore or if it was a deprecated wallet
- // that was earlier used before this restore.
- if (!m_restore_deterministic_wallet || was_deprecated_wallet)
- {
- if (was_deprecated_wallet)
- {
- // The user had used an older version of the wallet with old style mnemonics.
- message_writer(epee::log_space::console_color_green, false) << "\nYou had been using " <<
- "a deprecated version of the wallet. Please use the new seed that we provide.\n";
- }
- mnemonic_language = get_mnemonic_language();
- }
crypto::ElectrumWords::bytes_to_words(recovery_val, electrum_words, mnemonic_language);
- m_wallet->set_seed_language(mnemonic_language);
std::string print_electrum = "";
@@ -543,10 +559,7 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string
if (!two_random)
{
- success_msg_writer(true) << "\nPLEASE NOTE: the following 25 words can be used to recover access to your wallet. Please write them down and store them somewhere safe and secure. Please do not store them in your email or on file storage services outside of your immediate control.\n";
- boost::replace_nth(electrum_words, " ", 15, "\n");
- boost::replace_nth(electrum_words, " ", 7, "\n");
- std::cout << electrum_words << std::endl;
+ print_seed(electrum_words);
}
success_msg_writer() << "**********************************************************************";
@@ -564,6 +577,21 @@ bool simple_wallet::open_wallet(const string &wallet_file, const std::string& pa
m_wallet->load(m_wallet_file, password);
message_writer(epee::log_space::console_color_white, true) << "Opened wallet: "
<< m_wallet->get_account().get_public_address_str(m_wallet->testnet());
+ // If the wallet file is deprecated, we should ask for mnemonic language again and store
+ // everything in the new format.
+ if (!m_non_deterministic && m_wallet->is_deprecated())
+ {
+ message_writer(epee::log_space::console_color_green, false) << "\nYou had been using " <<
+ "a deprecated version of the wallet. Please proceed to upgrade your wallet.\n";
+ std::string mnemonic_language = get_mnemonic_language();
+ m_wallet->set_seed_language(mnemonic_language);
+ m_wallet->rewrite(m_wallet_file, password);
+
+ // Display the seed
+ std::string seed;
+ m_wallet->get_seed(seed);
+ print_seed(seed);
+ }
}
catch (const std::exception& e)
{
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index af6d4172a..ebc85ed17 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -101,6 +101,11 @@ namespace cryptonote
uint64_t get_daemon_blockchain_height(std::string& err);
bool try_connect_to_daemon();
bool ask_wallet_create_if_needed();
+ /*!
+ * \brief Prints the seed with a nice message
+ * \param seed seed to print
+ */
+ void print_seed(std::string seed);
/*!
* \brief Gets the word seed language from the user.