mirror of
https://github.com/monero-project/monero.git
synced 2024-12-15 21:06:32 +02:00
wallet2: factor the creation of a new wallet keys file
This commit is contained in:
parent
be6acfd5be
commit
20171746de
@ -3678,7 +3678,8 @@ boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::pr
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_wallet->restore(m_wallet_file, std::move(rc.second).password(), device_name);
|
bool create_address_file = command_line::get_arg(vm, arg_create_address_file);
|
||||||
|
m_wallet->restore(m_wallet_file, std::move(rc.second).password(), device_name, create_address_file);
|
||||||
message_writer(console_color_white, true) << tr("Generated new wallet on hw device: ")
|
message_writer(console_color_white, true) << tr("Generated new wallet on hw device: ")
|
||||||
<< m_wallet->get_account().get_public_address_str(m_wallet->nettype());
|
<< m_wallet->get_account().get_public_address_str(m_wallet->nettype());
|
||||||
}
|
}
|
||||||
|
@ -3333,6 +3333,22 @@ void wallet2::setup_new_blockchain()
|
|||||||
add_subaddress_account(tr("Primary account"));
|
add_subaddress_account(tr("Primary account"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wallet2::create_keys_file(const std::string &wallet_, bool watch_only, const epee::wipeable_string &password, bool create_address_file)
|
||||||
|
{
|
||||||
|
if (!wallet_.empty())
|
||||||
|
{
|
||||||
|
bool r = store_keys(m_keys_file, password, watch_only);
|
||||||
|
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
|
||||||
|
|
||||||
|
if (create_address_file)
|
||||||
|
{
|
||||||
|
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_nettype));
|
||||||
|
if(!r) MERROR("String with address text not saved");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Generates a wallet or restores one.
|
* \brief Generates a wallet or restores one.
|
||||||
* \param wallet_ Name of wallet file
|
* \param wallet_ Name of wallet file
|
||||||
@ -3409,18 +3425,7 @@ void wallet2::generate(const std::string& wallet_, const epee::wipeable_string&
|
|||||||
m_key_on_device = false;
|
m_key_on_device = false;
|
||||||
setup_keys(password);
|
setup_keys(password);
|
||||||
|
|
||||||
if (!wallet_.empty())
|
create_keys_file(wallet_, false, password, m_nettype != MAINNET || create_address_file);
|
||||||
{
|
|
||||||
bool r = store_keys(m_keys_file, password, false);
|
|
||||||
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
|
|
||||||
|
|
||||||
if (m_nettype != MAINNET || create_address_file)
|
|
||||||
{
|
|
||||||
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_nettype));
|
|
||||||
if(!r) MERROR("String with address text not saved");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_new_blockchain();
|
setup_new_blockchain();
|
||||||
|
|
||||||
if (!wallet_.empty())
|
if (!wallet_.empty())
|
||||||
@ -3465,17 +3470,7 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const epee::wip
|
|||||||
m_refresh_from_block_height = estimate_blockchain_height();
|
m_refresh_from_block_height = estimate_blockchain_height();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wallet_.empty())
|
create_keys_file(wallet_, false, password, m_nettype != MAINNET || create_address_file);
|
||||||
{
|
|
||||||
bool r = store_keys(m_keys_file, password, false);
|
|
||||||
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
|
|
||||||
|
|
||||||
if (m_nettype != MAINNET || create_address_file)
|
|
||||||
{
|
|
||||||
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_nettype));
|
|
||||||
if(!r) MERROR("String with address text not saved");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_new_blockchain();
|
setup_new_blockchain();
|
||||||
|
|
||||||
@ -3558,17 +3553,7 @@ void wallet2::generate(const std::string& wallet_, const epee::wipeable_string&
|
|||||||
m_key_on_device = false;
|
m_key_on_device = false;
|
||||||
setup_keys(password);
|
setup_keys(password);
|
||||||
|
|
||||||
if (!wallet_.empty())
|
create_keys_file(wallet_, true, password, m_nettype != MAINNET || create_address_file);
|
||||||
{
|
|
||||||
bool r = store_keys(m_keys_file, password, true);
|
|
||||||
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
|
|
||||||
|
|
||||||
if (m_nettype != MAINNET || create_address_file)
|
|
||||||
{
|
|
||||||
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_nettype));
|
|
||||||
if(!r) MERROR("String with address text not saved");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_new_blockchain();
|
setup_new_blockchain();
|
||||||
|
|
||||||
@ -3608,17 +3593,7 @@ void wallet2::generate(const std::string& wallet_, const epee::wipeable_string&
|
|||||||
m_key_on_device = false;
|
m_key_on_device = false;
|
||||||
setup_keys(password);
|
setup_keys(password);
|
||||||
|
|
||||||
if (!wallet_.empty())
|
create_keys_file(wallet_, false, password, create_address_file);
|
||||||
{
|
|
||||||
bool r = store_keys(m_keys_file, password, false);
|
|
||||||
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
|
|
||||||
|
|
||||||
if (m_nettype != MAINNET || create_address_file)
|
|
||||||
{
|
|
||||||
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_nettype));
|
|
||||||
if(!r) MERROR("String with address text not saved");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_new_blockchain();
|
setup_new_blockchain();
|
||||||
|
|
||||||
@ -3632,7 +3607,7 @@ void wallet2::generate(const std::string& wallet_, const epee::wipeable_string&
|
|||||||
* \param password Password of wallet file
|
* \param password Password of wallet file
|
||||||
* \param device_name device string address
|
* \param device_name device string address
|
||||||
*/
|
*/
|
||||||
void wallet2::restore(const std::string& wallet_, const epee::wipeable_string& password, const std::string &device_name)
|
void wallet2::restore(const std::string& wallet_, const epee::wipeable_string& password, const std::string &device_name, bool create_address_file)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
prepare_file_names(wallet_);
|
prepare_file_names(wallet_);
|
||||||
@ -3651,13 +3626,7 @@ void wallet2::restore(const std::string& wallet_, const epee::wipeable_string& p
|
|||||||
m_multisig_signers.clear();
|
m_multisig_signers.clear();
|
||||||
setup_keys(password);
|
setup_keys(password);
|
||||||
|
|
||||||
if (!wallet_.empty()) {
|
create_keys_file(wallet_, false, password, m_nettype != MAINNET || create_address_file);
|
||||||
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_nettype));
|
|
||||||
if(!r) MERROR("String with address text not saved");
|
|
||||||
}
|
|
||||||
if (m_subaddress_lookahead_major == SUBADDRESS_LOOKAHEAD_MAJOR && m_subaddress_lookahead_minor == SUBADDRESS_LOOKAHEAD_MINOR)
|
if (m_subaddress_lookahead_major == SUBADDRESS_LOOKAHEAD_MAJOR && m_subaddress_lookahead_minor == SUBADDRESS_LOOKAHEAD_MINOR)
|
||||||
{
|
{
|
||||||
// the default lookahead setting (50:200) is clearly too much for hardware wallet
|
// the default lookahead setting (50:200) is clearly too much for hardware wallet
|
||||||
@ -3759,17 +3728,7 @@ std::string wallet2::make_multisig(const epee::wipeable_string &password,
|
|||||||
// re-encrypt keys
|
// re-encrypt keys
|
||||||
keys_reencryptor = epee::misc_utils::auto_scope_leave_caller();
|
keys_reencryptor = epee::misc_utils::auto_scope_leave_caller();
|
||||||
|
|
||||||
if (!m_wallet_file.empty())
|
create_keys_file(m_wallet_file, false, password, boost::filesystem::exists(m_wallet_file + ".address.txt"));
|
||||||
{
|
|
||||||
bool r = store_keys(m_keys_file, password, false);
|
|
||||||
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
|
|
||||||
|
|
||||||
if (boost::filesystem::exists(m_wallet_file + ".address.txt"))
|
|
||||||
{
|
|
||||||
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_nettype));
|
|
||||||
if(!r) MERROR("String with address text not saved");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_new_blockchain();
|
setup_new_blockchain();
|
||||||
|
|
||||||
@ -3873,17 +3832,7 @@ bool wallet2::finalize_multisig(const epee::wipeable_string &password, std::unor
|
|||||||
// keys are encrypted again
|
// keys are encrypted again
|
||||||
keys_reencryptor = epee::misc_utils::auto_scope_leave_caller();
|
keys_reencryptor = epee::misc_utils::auto_scope_leave_caller();
|
||||||
|
|
||||||
if (!m_wallet_file.empty())
|
create_keys_file(m_wallet_file, false, password, boost::filesystem::exists(m_wallet_file + ".address.txt"));
|
||||||
{
|
|
||||||
bool r = store_keys(m_keys_file, password, false);
|
|
||||||
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
|
|
||||||
|
|
||||||
if (boost::filesystem::exists(m_wallet_file + ".address.txt"))
|
|
||||||
{
|
|
||||||
r = file_io_utils::save_string_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_nettype));
|
|
||||||
if(!r) MERROR("String with address text not saved");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_subaddresses.clear();
|
m_subaddresses.clear();
|
||||||
m_subaddress_labels.clear();
|
m_subaddress_labels.clear();
|
||||||
|
@ -544,8 +544,9 @@ namespace tools
|
|||||||
* \param wallet_ Name of wallet file
|
* \param wallet_ Name of wallet file
|
||||||
* \param password Password of wallet file
|
* \param password Password of wallet file
|
||||||
* \param device_name name of HW to use
|
* \param device_name name of HW to use
|
||||||
|
* \param create_address_file Whether to create an address file
|
||||||
*/
|
*/
|
||||||
void restore(const std::string& wallet_, const epee::wipeable_string& password, const std::string &device_name);
|
void restore(const std::string& wallet_, const epee::wipeable_string& password, const std::string &device_name, bool create_address_file);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Creates a multisig wallet
|
* \brief Creates a multisig wallet
|
||||||
@ -1242,6 +1243,7 @@ namespace tools
|
|||||||
void cache_tx_data(const cryptonote::transaction& tx, const crypto::hash &txid, tx_cache_data &tx_cache_data) const;
|
void cache_tx_data(const cryptonote::transaction& tx, const crypto::hash &txid, tx_cache_data &tx_cache_data) const;
|
||||||
|
|
||||||
void setup_new_blockchain();
|
void setup_new_blockchain();
|
||||||
|
void create_keys_file(const std::string &wallet_, bool watch_only, const epee::wipeable_string &password, bool create_address_file);
|
||||||
|
|
||||||
cryptonote::account_base m_account;
|
cryptonote::account_base m_account;
|
||||||
boost::optional<epee::net_utils::http::login> m_daemon_login;
|
boost::optional<epee::net_utils::http::login> m_daemon_login;
|
||||||
|
Loading…
Reference in New Issue
Block a user