mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-26 09:24:47 +00:00
wallet2: allow empty wallet filename to avoid saving data
Useful to speed tests up and avoid unnecessary leftover files
This commit is contained in:
parent
b84b3565f3
commit
95a21a793d
2 changed files with 58 additions and 40 deletions
|
@ -2594,9 +2594,12 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const epee::wip
|
|||
clear();
|
||||
prepare_file_names(wallet_);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
cryptonote::block b;
|
||||
generate_genesis(b);
|
||||
m_blockchain.push_back(get_block_hash(b));
|
||||
add_subaddress_account(tr("Primary account"));
|
||||
|
||||
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_);
|
||||
|
||||
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,17 +2700,21 @@ void wallet2::generate(const std::string& wallet_, const epee::wipeable_string&
|
|||
m_multisig_threshold = 0;
|
||||
m_multisig_total = 0;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
cryptonote::block b;
|
||||
generate_genesis(b);
|
||||
m_blockchain.push_back(get_block_hash(b));
|
||||
add_subaddress_account(tr("Primary account"));
|
||||
|
||||
if (!wallet_.empty())
|
||||
store();
|
||||
}
|
||||
|
||||
|
@ -2717,9 +2732,12 @@ void wallet2::generate(const std::string& wallet_, const epee::wipeable_string&
|
|||
clear();
|
||||
prepare_file_names(wallet_);
|
||||
|
||||
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,16 +2746,20 @@ void wallet2::generate(const std::string& wallet_, const epee::wipeable_string&
|
|||
m_multisig_threshold = 0;
|
||||
m_multisig_total = 0;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
cryptonote::block b;
|
||||
generate_genesis(b);
|
||||
m_blockchain.push_back(get_block_hash(b));
|
||||
|
||||
if (!wallet_.empty())
|
||||
store();
|
||||
}
|
||||
|
||||
|
@ -2789,17 +2811,21 @@ void wallet2::make_multisig(const epee::wipeable_string &password,
|
|||
m_multisig_threshold = threshold;
|
||||
m_multisig_total = spend_keys.size() + 1;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
cryptonote::block b;
|
||||
generate_genesis(b);
|
||||
m_blockchain.push_back(get_block_hash(b));
|
||||
add_subaddress_account(tr("Primary account"));
|
||||
|
||||
if (!m_wallet_file.empty())
|
||||
store();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue