diff options
Diffstat (limited to 'src/simplewallet/simplewallet.cpp')
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 8d7fc1510..c4d0fcc56 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -33,7 +33,6 @@ * * \brief Source file that defines simple_wallet class. */ - #include <thread> #include <iostream> #include <sstream> @@ -347,7 +346,8 @@ bool simple_wallet::seed_set_language(const std::vector<std::string> &args/* = s fail_msg_writer() << tr("wallet is non-deterministic and has no seed"); return true; } - tools::password_container pwd_container; + + tools::password_container pwd_container(m_wallet_file.empty()); success = pwd_container.read_password(); if (!success) { @@ -379,7 +379,7 @@ bool simple_wallet::set_always_confirm_transfers(const std::vector<std::string> fail_msg_writer() << tr("wallet is watch-only and cannot transfer"); return true; } - tools::password_container pwd_container; + tools::password_container pwd_container(m_wallet_file.empty()); success = pwd_container.read_password(); if (!success) { @@ -408,7 +408,8 @@ bool simple_wallet::set_store_tx_info(const std::vector<std::string> &args/* = s fail_msg_writer() << tr("wallet is watch-only and cannot transfer"); return true; } - tools::password_container pwd_container; + + tools::password_container pwd_container(m_wallet_file.empty()); success = pwd_container.read_password(); if (!success) { @@ -452,8 +453,9 @@ bool simple_wallet::set_default_mixin(const std::vector<std::string> &args/* = s } if (mixin == 0) mixin = DEFAULT_MIX; + + tools::password_container pwd_container(m_wallet_file.empty()); - tools::password_container pwd_container; success = pwd_container.read_password(); if (!success) { @@ -514,8 +516,8 @@ bool simple_wallet::set_default_fee_multiplier(const std::vector<std::string> &a return true; } } - - tools::password_container pwd_container; + + tools::password_container pwd_container(m_wallet_file.empty()); success = pwd_container.read_password(); if (!success) { @@ -549,9 +551,10 @@ bool simple_wallet::set_default_fee_multiplier(const std::vector<std::string> &a bool simple_wallet::set_auto_refresh(const std::vector<std::string> &args/* = std::vector<std::string>()*/) { - bool success = false; - tools::password_container pwd_container; - success = pwd_container.read_password(); + + tools::password_container pwd_container(m_wallet_file.empty()); + + bool success = pwd_container.read_password(); if (!success) { fail_msg_writer() << tr("failed to read wallet password"); @@ -586,8 +589,8 @@ bool simple_wallet::set_refresh_type(const std::vector<std::string> &args/* = st { return true; } - - tools::password_container pwd_container; + + tools::password_container pwd_container(m_wallet_file.empty()); success = pwd_container.read_password(); if (!success) { @@ -854,7 +857,7 @@ bool simple_wallet::ask_wallet_create_if_needed() bool r; if(keys_file_exists) { - m_wallet_file = wallet_path; + m_wallet_file=wallet_path; r = true; }else { @@ -889,7 +892,7 @@ void simple_wallet::print_seed(std::string seed) } //---------------------------------------------------------------------------------------------------- -static bool get_password(const boost::program_options::variables_map& vm, bool allow_entry, tools::password_container &pwd_container) +bool simple_wallet::get_password(const boost::program_options::variables_map& vm, bool allow_entry, tools::password_container &pwd_container) { // has_arg returns true even when the parameter is not passed ?? const std::string gfj = command_line::get_arg(vm, arg_generate_from_json); @@ -930,6 +933,8 @@ static bool get_password(const boost::program_options::variables_map& vm, bool a if (allow_entry) { + //vm is already part of the password container class. just need to check vm for an already existing wallet + //here need to pass in variable map. This will indicate if the wallet already exists to the read password function bool r = pwd_container.read_password(); if (!r) { @@ -1077,7 +1082,7 @@ bool simple_wallet::generate_from_json(const boost::program_options::variables_m } } - m_wallet_file = field_filename; + m_wallet_file=field_filename; 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)); @@ -1215,9 +1220,8 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) } } catch (const std::exception &e) { } - - tools::password_container pwd_container; - if (!get_password(vm, true, pwd_container)) + tools::password_container pwd_container(m_wallet_file.empty()); //m_wallet_file will be empty at this point for new wallets + if (!cryptonote::simple_wallet::get_password(vm, true, pwd_container)) return false; if (!m_generate_new.empty() || m_restore_deterministic_wallet || !m_generate_from_view_key.empty() || !m_generate_from_keys.empty() || !m_generate_from_json.empty()) @@ -1303,7 +1307,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) } crypto::secret_key viewkey = *reinterpret_cast<const crypto::secret_key*>(viewkey_data.data()); - m_wallet_file = m_generate_from_view_key; + m_wallet_file=m_generate_from_view_key; // check the view key matches the given address crypto::public_key pkey; @@ -1370,7 +1374,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) } crypto::secret_key viewkey = *reinterpret_cast<const crypto::secret_key*>(viewkey_data.data()); - m_wallet_file = m_generate_from_keys; + m_wallet_file=m_generate_from_keys; // check the spend and view keys match the given address crypto::public_key pkey; @@ -1532,7 +1536,8 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string return false; } - m_wallet_file = wallet_file; + + m_wallet_file=wallet_file; m_wallet.reset(new tools::wallet2(testnet)); m_wallet->callback(this); @@ -1591,7 +1596,7 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string& password, const cryptonote::account_public_address& address, const crypto::secret_key& viewkey, bool testnet) { - m_wallet_file = wallet_file; + m_wallet_file=wallet_file; m_wallet.reset(new tools::wallet2(testnet)); m_wallet->callback(this); @@ -1619,7 +1624,7 @@ bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string bool simple_wallet::new_wallet(const std::string &wallet_file, const std::string& password, const cryptonote::account_public_address& address, const crypto::secret_key& spendkey, const crypto::secret_key& viewkey, bool testnet) { - m_wallet_file = wallet_file; + m_wallet_file=wallet_file; m_wallet.reset(new tools::wallet2(testnet)); m_wallet->callback(this); @@ -1651,7 +1656,7 @@ bool simple_wallet::open_wallet(const string &wallet_file, const std::string& pa return false; } - m_wallet_file = wallet_file; + m_wallet_file=wallet_file; m_wallet.reset(new tools::wallet2(testnet)); m_wallet->callback(this); @@ -1757,7 +1762,7 @@ bool simple_wallet::save(const std::vector<std::string> &args) bool simple_wallet::save_watch_only(const std::vector<std::string> &args/* = std::vector<std::string>()*/) { bool success = false; - tools::password_container pwd_container; + tools::password_container pwd_container(m_wallet_file.empty()); success = pwd_container.read_password(tr("Password for the new watch-only wallet")); if (!success) @@ -3746,8 +3751,9 @@ int main(int argc, char* argv[]) bool testnet = command_line::get_arg(vm, arg_testnet); bool restricted = command_line::get_arg(vm, arg_restricted); std::string wallet_file = command_line::get_arg(vm, arg_wallet_file); - tools::password_container pwd_container; - if (!get_password(vm, false, pwd_container)) + + tools::password_container pwd_container(wallet_file.empty()); + if (!cryptonote::simple_wallet::get_password(vm, false, pwd_container)) return 1; std::string daemon_address = command_line::get_arg(vm, arg_daemon_address); std::string daemon_host = command_line::get_arg(vm, arg_daemon_host); |