aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mnemonics/electrum-words.cpp14
-rw-r--r--src/simplewallet/simplewallet.cpp38
2 files changed, 40 insertions, 12 deletions
diff --git a/src/mnemonics/electrum-words.cpp b/src/mnemonics/electrum-words.cpp
index 251503d9b..3ef7c5efc 100644
--- a/src/mnemonics/electrum-words.cpp
+++ b/src/mnemonics/electrum-words.cpp
@@ -63,6 +63,7 @@ namespace
{
words_array.clear();
words_map.clear();
+ num_words = 0;
std::ifstream input_stream;
input_stream.open(word_file.c_str(), std::ifstream::in);
@@ -109,8 +110,8 @@ namespace crypto
}
if (num_words == 0)
{
- throw std::runtime_error(std::string("Word list file is corrupt: ") +
- old_word_list ? OLD_WORD_FILE : (LANGUAGES_DIRECTORY + '/' + language));
+ throw std::runtime_error(std::string("Word list file is empty: ") +
+ (old_word_list ? OLD_WORD_FILE : (LANGUAGES_DIRECTORY + '/' + language)));
}
}
@@ -128,13 +129,16 @@ namespace crypto
boost::split(wlist, words, boost::is_any_of(" "));
std::vector<std::string> languages;
+ get_language_list(languages);
std::vector<std::string>::iterator it;
- get_language_list(languages);
- for (it = languages.begin(); it != languages.end() &&
- !word_list_file_match(wlist); it++)
+ for (it = languages.begin(); it != languages.end(); it++)
{
init(*it);
+ if (word_list_file_match(wlist))
+ {
+ break;
+ }
}
if (it == languages.end())
{
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index b368da01a..a222e7827 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -46,7 +46,7 @@
#include "version.h"
#include "crypto/crypto.h" // for crypto::secret_key definition
#include "mnemonics/electrum-words.h"
-
+#include <stdexcept>
#if defined(WIN32)
#include <crtdbg.h>
@@ -380,10 +380,18 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
}
}
- if (!crypto::ElectrumWords::words_to_bytes(m_electrum_seed, m_recovery_key))
+ try
{
- fail_msg_writer() << "electrum-style word list failed verification";
- return false;
+ if (!crypto::ElectrumWords::words_to_bytes(m_electrum_seed, m_recovery_key))
+ {
+ fail_msg_writer() << "electrum-style word list failed verification";
+ return false;
+ }
+ }
+ catch (std::runtime_error &e)
+ {
+ fail_msg_writer() << e.what() << std::endl;
+ return false;
}
}
bool r = new_wallet(m_wallet_file, pwd_container.password(), m_recovery_key, m_restore_deterministic_wallet, m_non_deterministic, testnet);
@@ -490,13 +498,29 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas
// convert rng value to electrum-style word list
std::string electrum_words;
- if (m_restore_deterministic_wallet)
+ if (!m_restore_deterministic_wallet)
{
// Ask for language only if it not a wallet restore.
std::string mnemonic_language = get_mnemonic_language();
- crypto::ElectrumWords::init(mnemonic_language);
+ try
+ {
+ crypto::ElectrumWords::init(mnemonic_language);
+ }
+ catch (std::runtime_error &e)
+ {
+ fail_msg_writer() << e.what() << std::endl;
+ return false;
+ }
+ }
+ try
+ {
+ crypto::ElectrumWords::bytes_to_words(recovery_val, electrum_words);
+ }
+ catch (std::runtime_error &e)
+ {
+ fail_msg_writer() << e.what() << std::endl;
+ return false;
}
- crypto::ElectrumWords::bytes_to_words(recovery_val, electrum_words);
std::string print_electrum = "";