aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-10-22 22:07:38 +0200
committerRiccardo Spagni <ric@spagni.net>2016-10-22 22:07:38 +0200
commitb53c9e55496d6a9b0f1636cfb88db9260bc0a8a7 (patch)
tree84f7951acd55609f978e70d2ccd78a530a6ebed3 /src
parentMerge pull request #1237 (diff)
parentRewrote add_wallet_create_if_needed for clearer flow and behaviour (diff)
downloadmonero-b53c9e55496d6a9b0f1636cfb88db9260bc0a8a7.tar.xz
Merge pull request #1200
a3748f4 Rewrote add_wallet_create_if_needed for clearer flow and behaviour (NanoAkron)
Diffstat (limited to 'src')
-rw-r--r--src/simplewallet/simplewallet.cpp120
-rw-r--r--src/wallet/wallet2.h1
2 files changed, 67 insertions, 54 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index b27113473..639fcb4b6 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -873,65 +873,79 @@ bool simple_wallet::set_log(const std::vector<std::string> &args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::ask_wallet_create_if_needed()
{
+ LOG_PRINT_L3("simple_wallet::ask_wallet_create_if_needed() started");
std::string wallet_path;
-
- bool valid_path = false;
- do {
- wallet_path = command_line::input_line(
- tr("Specify wallet file name (e.g., MyWallet). If the wallet doesn't exist, it will be created.\n"
- "Wallet file name: ")
- );
- if (std::cin.eof())
- {
- return false;
- }
- valid_path = tools::wallet2::wallet_valid_path_format(wallet_path);
- if (!valid_path)
- {
- fail_msg_writer() << tr("wallet file path not valid: ") << wallet_path;
- }
- }
- while (!valid_path);
-
+ std::string confirm_creation;
+ bool wallet_name_valid = false;
bool keys_file_exists;
bool wallet_file_exists;
- tools::wallet2::wallet_exists(wallet_path, keys_file_exists, wallet_file_exists);
- LOG_PRINT_L3("wallet_path: " << wallet_path << "");
- LOG_PRINT_L3("keys_file_exists: " << std::boolalpha << keys_file_exists << std::noboolalpha
- << " wallet_file_exists: " << std::boolalpha << wallet_file_exists << std::noboolalpha);
- LOG_PRINT_L1("Loading wallet...");
-
- // 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_restoring)
- {
- fail_msg_writer() << tr("attempting to generate or restore wallet, but specified file(s) exist. Exiting to not risk overwriting.");
- return false;
- }
- }
+ do{
+ LOG_PRINT_L3("User asked to specify wallet file name.");
+ wallet_path = command_line::input_line(
+ tr("Specify wallet file name (e.g., MyWallet). If the wallet doesn't exist, it will be created.\n"
+ "Wallet file name (or Ctrl-C to quit): ")
+ );
+ if(std::cin.eof())
+ {
+ LOG_ERROR("Unexpected std::cin.eof() - Exited simple_wallet::ask_wallet_create_if_needed()");
+ return false;
+ }
+ if(!tools::wallet2::wallet_valid_path_format(wallet_path))
+ {
+ fail_msg_writer() << tr("Wallet name not valid. Please try again or use Ctrl-C to quit.");
+ wallet_name_valid = false;
+ }
+ else
+ {
+ tools::wallet2::wallet_exists(wallet_path, keys_file_exists, wallet_file_exists);
+ LOG_PRINT_L3("wallet_path: " << wallet_path << "");
+ LOG_PRINT_L3("keys_file_exists: " << std::boolalpha << keys_file_exists << std::noboolalpha
+ << " wallet_file_exists: " << std::boolalpha << wallet_file_exists << std::noboolalpha);
- bool r;
- if(keys_file_exists)
- {
- m_wallet_file=wallet_path;
- r = true;
- }else
- {
- if(!wallet_file_exists)
- {
- std::cout << tr("The wallet doesn't exist, generating new one") << std::endl;
- m_generate_new = wallet_path;
- r = true;
- }else
- {
- fail_msg_writer() << tr("keys file not found: failed to open wallet: ") << "\"" << wallet_path << "\".";
- r = false;
- }
- }
+ if((keys_file_exists || wallet_file_exists) && (!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;
+ }
+ if(wallet_file_exists && keys_file_exists) //Yes wallet, yes keys
+ {
+ success_msg_writer() << tr("Wallet and key files found, loading...");
+ m_wallet_file = wallet_path;
+ return true;
+ }
+ else if(!wallet_file_exists && keys_file_exists) //No wallet, yes keys
+ {
+ success_msg_writer() << tr("Key file found but not wallet file. Regenerating...");
+ m_wallet_file = wallet_path;
+ return true;
+ }
+ else if(wallet_file_exists && !keys_file_exists) //Yes wallet, no keys
+ {
+ fail_msg_writer() << tr("Key file not found. Failed to open wallet: ") << "\"" << wallet_path << "\". Exiting.";
+ return false;
+ }
+ else if(!wallet_file_exists && !keys_file_exists) //No wallet, no keys
+ {
+ message_writer() << tr("No wallet/key file found with that name. Confirm creation of new wallet named: ") << wallet_path;
+ confirm_creation = command_line::input_line(tr("(y)es/(n)o: "));
+ if(std::cin.eof())
+ {
+ LOG_ERROR("Unexpected std::cin.eof() - Exited simple_wallet::ask_wallet_create_if_needed()");
+ return false;
+ }
+ if(is_it_true(confirm_creation))
+ {
+ success_msg_writer() << tr("Generating new wallet...");
+ m_generate_new = wallet_path;
+ return true;
+ }
+ }
+ }
+ } while(!wallet_name_valid);
- return r;
+ LOG_ERROR("Failed out of do-while loop in ask_wallet_create_if_needed()");
+ return false;
}
/*!
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index a039c92d6..4777102af 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -422,7 +422,6 @@ namespace tools
* \return Whether path is valid format
*/
static bool wallet_valid_path_format(const std::string& file_path);
-
static bool parse_long_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);
static bool parse_short_payment_id(const std::string& payment_id_str, crypto::hash8& payment_id);
static bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);