From 95eb944eade434f86908262932ea991236820a61 Mon Sep 17 00:00:00 2001 From: warptangent Date: Thu, 11 Dec 2014 02:47:24 -0800 Subject: [PATCH 1/2] Repeat prompt for wallet path if invalid simplewallet run without a wallet path argument should prompt again if an invalid path was entered. Validity here currently means the string isn't empty. --- src/simplewallet/simplewallet.cpp | 28 ++++++++++++++++++++++++---- src/wallet/wallet2.cpp | 5 +++++ src/wallet/wallet2.h | 6 ++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 4f7df2d3a..61c74449c 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -285,14 +285,28 @@ bool simple_wallet::ask_wallet_create_if_needed() { std::string wallet_path; - wallet_path = command_line::input_line( - "Specify wallet file name (e.g., wallet.bin). If the wallet doesn't exist, it will be created.\n" - "Wallet file name: " - ); + bool valid_path = false; + do { + wallet_path = command_line::input_line( + "Specify wallet file name (e.g., wallet.bin). If the wallet doesn't exist, it will be created.\n" + "Wallet file name: " + ); + valid_path = tools::wallet2::wallet_valid_path_format(wallet_path); + if (!valid_path) + { + fail_msg_writer() << "wallet file path not valid: " << wallet_path; + } + } + while (!valid_path); 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) @@ -575,6 +589,12 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string //---------------------------------------------------------------------------------------------------- bool simple_wallet::open_wallet(const string &wallet_file, const std::string& password, bool testnet) { + if (!tools::wallet2::wallet_valid_path_format(wallet_file)) + { + fail_msg_writer() << "wallet file path not valid: " << wallet_file; + return false; + } + m_wallet_file = wallet_file; m_wallet.reset(new tools::wallet2(testnet)); m_wallet->callback(this); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 163e19df4..2b84cbbf3 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -633,6 +633,11 @@ void wallet2::wallet_exists(const std::string& file_path, bool& keys_file_exists wallet_file_exists = boost::filesystem::exists(wallet_file, ignore); } //---------------------------------------------------------------------------------------------------- +bool wallet2::wallet_valid_path_format(const std::string& file_path) +{ + return !file_path.empty(); +} +//---------------------------------------------------------------------------------------------------- bool wallet2::parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id) { cryptonote::blobdata payment_id_data; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index f22c5d79d..dface0a7d 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -225,6 +225,12 @@ namespace tools } static void wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exists); + /*! + * \brief Check if wallet file path is valid format + * \param file_path Wallet file path + * \return Whether path is valid format + */ + static bool wallet_valid_path_format(const std::string& file_path); static bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id); From 583cf0ad8a59b8bded1bd075d06e3ace2fa611e5 Mon Sep 17 00:00:00 2001 From: warptangent Date: Thu, 11 Dec 2014 02:48:04 -0800 Subject: [PATCH 2/2] Document existing function --- src/wallet/wallet2.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index dface0a7d..e037bf42d 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -224,6 +224,12 @@ namespace tools a & m_payments; } + /*! + * \brief Check if wallet keys and bin files exist + * \param file_path Wallet file path + * \param keys_file_exists Whether keys file exists + * \param wallet_file_exists Whether bin file exists + */ static void wallet_exists(const std::string& file_path, bool& keys_file_exists, bool& wallet_file_exists); /*! * \brief Check if wallet file path is valid format