diff options
Diffstat (limited to 'src/simplewallet')
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 55 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.h | 3 |
2 files changed, 50 insertions, 8 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index a307f9d3d..bbf794c05 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -42,6 +42,7 @@ #include <boost/program_options.hpp> #include <boost/algorithm/string.hpp> #include <boost/format.hpp> +#include <boost/regex.hpp> #include "include_base_utils.h" #include "common/i18n.h" #include "common/command_line.h" @@ -432,7 +433,7 @@ bool simple_wallet::print_seed(bool encrypted) m_wallet->set_seed_language(mnemonic_language); } - std::string seed_pass; + epee::wipeable_string seed_pass; if (encrypted) { auto pwd_container = tools::password_container::prompt(true, tr("Enter optional seed encryption passphrase, empty to see raw seed")); @@ -933,6 +934,10 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("stop_mining", boost::bind(&simple_wallet::stop_mining, this, _1), tr("Stop mining in the daemon.")); + m_cmd_binder.set_handler("set_daemon", + boost::bind(&simple_wallet::set_daemon, this, _1), + tr("set_daemon <host>[:<port>]"), + tr("Set another daemon to connect to.")); m_cmd_binder.set_handler("save_bc", boost::bind(&simple_wallet::save_bc, this, _1), tr("Save the current blockchain data.")); @@ -1344,8 +1349,8 @@ bool simple_wallet::ask_wallet_create_if_needed() */ void simple_wallet::print_seed(std::string seed) { - success_msg_writer(true) << "\n" << tr("PLEASE 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 " + success_msg_writer(true) << "\n" << tr("NOTE: the following 25 words can be used to recover access to your wallet. " + "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"); @@ -1421,7 +1426,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) auto pwd_container = tools::password_container::prompt(false, tr("Enter seed encryption passphrase, empty if none")); if (std::cin.eof() || !pwd_container) return false; - std::string seed_pass = pwd_container->password(); + epee::wipeable_string seed_pass = pwd_container->password(); if (!seed_pass.empty()) m_recovery_key = cryptonote::decrypt_key(m_recovery_key, seed_pass); } @@ -1890,7 +1895,7 @@ bool simple_wallet::try_connect_to_daemon(bool silent, uint32_t* version) if (!silent) fail_msg_writer() << tr("wallet failed to connect to daemon: ") << m_wallet->get_daemon_address() << ". " << tr("Daemon either is not started or wrong port was passed. " - "Please make sure daemon is running or restart the wallet with the correct daemon address."); + "Please make sure daemon is running or change the daemon address using the 'set_daemon' command."); return false; } if (!m_allow_mismatched_daemon_version && ((*version >> 16) != CORE_RPC_VERSION_MAJOR)) @@ -2082,12 +2087,12 @@ bool simple_wallet::open_wallet(const boost::program_options::variables_map& vm) fail_msg_writer() << tr("wallet file path not valid: ") << m_wallet_file; return false; } - std::string password; + epee::wipeable_string password; try { auto rc = tools::wallet2::make_from_file(vm, m_wallet_file, password_prompter); m_wallet = std::move(rc.first); - password = std::move(rc.second).password(); + password = std::move(std::move(rc.second).password()); if (!m_wallet) { return false; @@ -2295,6 +2300,42 @@ bool simple_wallet::stop_mining(const std::vector<std::string>& args) return true; } //---------------------------------------------------------------------------------------------------- +bool simple_wallet::set_daemon(const std::vector<std::string>& args) +{ + std::string daemon_url; + + if (args.size() < 1) + { + fail_msg_writer() << tr("missing daemon URL argument"); + return true; + } + + boost::regex rgx("^(.*://)?([A-Za-z0-9\\-\\.]+)(:[0-9]+)?"); + boost::cmatch match; + // If user input matches URL regex + if (boost::regex_match(args[0].c_str(), match, rgx)) + { + if (match.length() < 4) + { + fail_msg_writer() << tr("Unexpected array length - Exited simple_wallet::set_daemon()"); + return true; + } + // If no port has been provided, use the default from config + if (!match[3].length()) + { + int daemon_port = m_wallet->testnet() ? config::testnet::RPC_DEFAULT_PORT : config::RPC_DEFAULT_PORT; + daemon_url = match[1] + match[2] + std::string(":") + std::to_string(daemon_port); + } else { + daemon_url = args[0]; + } + LOCK_IDLE_SCOPE(); + m_wallet->init(daemon_url); + } else { + fail_msg_writer() << tr("This does not seem to be a valid daemon URL."); + } + return true; +} +//---------------------------------------------------------------------------------------------------- bool simple_wallet::save_bc(const std::vector<std::string>& args) { if (!try_connect_to_daemon()) diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index f6405426b..ad174a636 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -128,7 +128,8 @@ namespace cryptonote bool help(const std::vector<std::string> &args = std::vector<std::string>()); bool start_mining(const std::vector<std::string> &args); bool stop_mining(const std::vector<std::string> &args); - bool save_bc(const std::vector<std::string>& args); + bool set_daemon(const std::vector<std::string> &args); + bool save_bc(const std::vector<std::string> &args); bool refresh(const std::vector<std::string> &args); bool show_balance_unlocked(bool detailed = false); bool show_balance(const std::vector<std::string> &args = std::vector<std::string>()); |