aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wallet/wallet2.cpp86
-rw-r--r--tests/unit_tests/multisig.cpp12
2 files changed, 58 insertions, 40 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index af48e711e..a497f3242 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -2594,9 +2594,12 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const epee::wip
clear();
prepare_file_names(wallet_);
- boost::system::error_code ignored_ec;
- THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, m_wallet_file);
- THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_keys_file, ignored_ec), error::file_exists, m_keys_file);
+ if (!wallet_.empty())
+ {
+ boost::system::error_code ignored_ec;
+ THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, m_wallet_file);
+ THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_keys_file, ignored_ec), error::file_exists, m_keys_file);
+ }
crypto::secret_key retval = m_account.generate(recovery_param, recover, two_random);
@@ -2618,18 +2621,23 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const epee::wip
m_refresh_from_block_height = height >= blocks_per_month ? height - blocks_per_month : 0;
}
- bool r = store_keys(m_keys_file, password, false);
- THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
+ if (!wallet_.empty())
+ {
+ bool r = store_keys(m_keys_file, password, false);
+ THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
- r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
- if(!r) MERROR("String with address text not saved");
+ r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
+ if(!r) MERROR("String with address text not saved");
+ }
cryptonote::block b;
generate_genesis(b);
m_blockchain.push_back(get_block_hash(b));
add_subaddress_account(tr("Primary account"));
- store();
+ if (!wallet_.empty())
+ store();
+
return retval;
}
@@ -2678,9 +2686,12 @@ void wallet2::generate(const std::string& wallet_, const epee::wipeable_string&
clear();
prepare_file_names(wallet_);
- boost::system::error_code ignored_ec;
- THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, m_wallet_file);
- THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_keys_file, ignored_ec), error::file_exists, m_keys_file);
+ if (!wallet_.empty())
+ {
+ boost::system::error_code ignored_ec;
+ THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, m_wallet_file);
+ THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_keys_file, ignored_ec), error::file_exists, m_keys_file);
+ }
m_account.create_from_viewkey(account_public_address, viewkey);
m_account_public_address = account_public_address;
@@ -2689,18 +2700,22 @@ void wallet2::generate(const std::string& wallet_, const epee::wipeable_string&
m_multisig_threshold = 0;
m_multisig_total = 0;
- bool r = store_keys(m_keys_file, password, true);
- THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
+ if (!wallet_.empty())
+ {
+ bool r = store_keys(m_keys_file, password, true);
+ THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
- r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
- if(!r) MERROR("String with address text not saved");
+ r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
+ if(!r) MERROR("String with address text not saved");
+ }
cryptonote::block b;
generate_genesis(b);
m_blockchain.push_back(get_block_hash(b));
add_subaddress_account(tr("Primary account"));
- store();
+ if (!wallet_.empty())
+ store();
}
/*!
@@ -2717,9 +2732,12 @@ void wallet2::generate(const std::string& wallet_, const epee::wipeable_string&
clear();
prepare_file_names(wallet_);
- boost::system::error_code ignored_ec;
- THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, m_wallet_file);
- THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_keys_file, ignored_ec), error::file_exists, m_keys_file);
+ if (!wallet_.empty())
+ {
+ boost::system::error_code ignored_ec;
+ THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_wallet_file, ignored_ec), error::file_exists, m_wallet_file);
+ THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(m_keys_file, ignored_ec), error::file_exists, m_keys_file);
+ }
m_account.create_from_keys(account_public_address, spendkey, viewkey);
m_account_public_address = account_public_address;
@@ -2728,17 +2746,21 @@ void wallet2::generate(const std::string& wallet_, const epee::wipeable_string&
m_multisig_threshold = 0;
m_multisig_total = 0;
- bool r = store_keys(m_keys_file, password, false);
- THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
+ if (!wallet_.empty())
+ {
+ bool r = store_keys(m_keys_file, password, false);
+ THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
- r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
- if(!r) MERROR("String with address text not saved");
+ r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
+ if(!r) MERROR("String with address text not saved");
+ }
cryptonote::block b;
generate_genesis(b);
m_blockchain.push_back(get_block_hash(b));
- store();
+ if (!wallet_.empty())
+ store();
}
void wallet2::make_multisig(const epee::wipeable_string &password,
@@ -2789,18 +2811,22 @@ void wallet2::make_multisig(const epee::wipeable_string &password,
m_multisig_threshold = threshold;
m_multisig_total = spend_keys.size() + 1;
- bool r = store_keys(m_keys_file, password, false);
- THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
+ if (!m_wallet_file.empty())
+ {
+ bool r = store_keys(m_keys_file, password, false);
+ THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
- r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
- if(!r) MERROR("String with address text not saved");
+ r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_testnet));
+ if(!r) MERROR("String with address text not saved");
+ }
cryptonote::block b;
generate_genesis(b);
m_blockchain.push_back(get_block_hash(b));
add_subaddress_account(tr("Primary account"));
- store();
+ if (!m_wallet_file.empty())
+ store();
}
std::string wallet2::get_multisig_info() const
@@ -2889,6 +2915,8 @@ bool wallet2::has_multisig_partial_key_images() const
*/
void wallet2::rewrite(const std::string& wallet_name, const epee::wipeable_string& password)
{
+ if (wallet_name.empty())
+ return;
prepare_file_names(wallet_name);
boost::system::error_code ignored_ec;
THROW_WALLET_EXCEPTION_IF(!boost::filesystem::exists(m_keys_file, ignored_ec), error::file_not_found, m_keys_file);
diff --git a/tests/unit_tests/multisig.cpp b/tests/unit_tests/multisig.cpp
index 2fb201d82..8a94012e5 100644
--- a/tests/unit_tests/multisig.cpp
+++ b/tests/unit_tests/multisig.cpp
@@ -59,20 +59,10 @@ static void make_wallet(unsigned int idx, tools::wallet2 &wallet)
crypto::secret_key spendkey;
epee::string_tools::hex_to_pod(test_addresses[idx].spendkey, spendkey);
- std::string basename = "/tmp/multisig-unit-test-" + std::to_string(idx);
try
{
- boost::filesystem::remove(basename + ".keys");
- boost::filesystem::remove(basename + ".address.txt");
- boost::filesystem::remove(basename);
-
wallet.init("");
- wallet.generate(basename, "", spendkey, true, false);
-
- boost::filesystem::remove(basename + ".keys");
- boost::filesystem::remove(basename + ".address.txt");
- boost::filesystem::remove(basename);
-
+ wallet.generate("", "", spendkey, true, false);
ASSERT_TRUE(test_addresses[idx].address == wallet.get_account().get_public_address_str(true));
}
catch (const std::exception &e)