mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 11:23:26 +01:00
simplewallet: make sure wallet config is stored right after creation
This commit is contained in:
parent
702a41034d
commit
f13c7a8263
@ -2806,6 +2806,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||||||
m_recovery_key = cryptonote::decrypt_key(m_recovery_key, seed_pass);
|
m_recovery_key = cryptonote::decrypt_key(m_recovery_key, seed_pass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
epee::wipeable_string password;
|
||||||
if (!m_generate_from_view_key.empty())
|
if (!m_generate_from_view_key.empty())
|
||||||
{
|
{
|
||||||
m_wallet_file = m_generate_from_view_key;
|
m_wallet_file = m_generate_from_view_key;
|
||||||
@ -2858,8 +2859,9 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool r = new_wallet(vm, info.address, boost::none, viewkey);
|
auto r = new_wallet(vm, info.address, boost::none, viewkey);
|
||||||
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
||||||
|
password = *r;
|
||||||
}
|
}
|
||||||
else if (!m_generate_from_spend_key.empty())
|
else if (!m_generate_from_spend_key.empty())
|
||||||
{
|
{
|
||||||
@ -2877,8 +2879,9 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||||||
fail_msg_writer() << tr("failed to parse spend key secret key");
|
fail_msg_writer() << tr("failed to parse spend key secret key");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool r = new_wallet(vm, m_recovery_key, true, false, "");
|
auto r = new_wallet(vm, m_recovery_key, true, false, "");
|
||||||
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
||||||
|
password = *r;
|
||||||
}
|
}
|
||||||
else if (!m_generate_from_keys.empty())
|
else if (!m_generate_from_keys.empty())
|
||||||
{
|
{
|
||||||
@ -2955,8 +2958,9 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||||||
fail_msg_writer() << tr("view key does not match standard address");
|
fail_msg_writer() << tr("view key does not match standard address");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool r = new_wallet(vm, info.address, spendkey, viewkey);
|
auto r = new_wallet(vm, info.address, spendkey, viewkey);
|
||||||
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
||||||
|
password = *r;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asks user for all the data required to merge secret keys from multisig wallets into one master wallet, which then gets full control of the multisig wallet. The resulting wallet will be the same as any other regular wallet.
|
// Asks user for all the data required to merge secret keys from multisig wallets into one master wallet, which then gets full control of the multisig wallet. The resulting wallet will be the same as any other regular wallet.
|
||||||
@ -3089,8 +3093,9 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create wallet
|
// create wallet
|
||||||
bool r = new_wallet(vm, info.address, spendkey, viewkey);
|
auto r = new_wallet(vm, info.address, spendkey, viewkey);
|
||||||
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
||||||
|
password = *r;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!m_generate_from_json.empty())
|
else if (!m_generate_from_json.empty())
|
||||||
@ -3112,8 +3117,9 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||||||
{
|
{
|
||||||
m_wallet_file = m_generate_from_device;
|
m_wallet_file = m_generate_from_device;
|
||||||
// create wallet
|
// create wallet
|
||||||
bool r = new_wallet(vm, "Ledger");
|
auto r = new_wallet(vm, "Ledger");
|
||||||
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
||||||
|
password = *r;
|
||||||
// if no block_height is specified, assume its a new account and start it "now"
|
// if no block_height is specified, assume its a new account and start it "now"
|
||||||
if(m_wallet->get_refresh_from_block_height() == 0) {
|
if(m_wallet->get_refresh_from_block_height() == 0) {
|
||||||
{
|
{
|
||||||
@ -3138,12 +3144,13 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_wallet_file = m_generate_new;
|
m_wallet_file = m_generate_new;
|
||||||
bool r;
|
boost::optional<epee::wipeable_string> r;
|
||||||
if (m_restore_multisig_wallet)
|
if (m_restore_multisig_wallet)
|
||||||
r = new_wallet(vm, multisig_keys, old_language);
|
r = new_wallet(vm, multisig_keys, old_language);
|
||||||
else
|
else
|
||||||
r = new_wallet(vm, m_recovery_key, m_restore_deterministic_wallet, m_non_deterministic, old_language);
|
r = new_wallet(vm, m_recovery_key, m_restore_deterministic_wallet, m_non_deterministic, old_language);
|
||||||
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
CHECK_AND_ASSERT_MES(r, false, tr("account creation failed"));
|
||||||
|
password = *r;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_restoring && m_generate_from_json.empty() && m_generate_from_device.empty())
|
if (m_restoring && m_generate_from_json.empty() && m_generate_from_device.empty())
|
||||||
@ -3225,6 +3232,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||||||
}
|
}
|
||||||
m_wallet->set_refresh_from_block_height(m_restore_height);
|
m_wallet->set_refresh_from_block_height(m_restore_height);
|
||||||
}
|
}
|
||||||
|
m_wallet->rewrite(m_wallet_file, password);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3392,15 +3400,16 @@ boost::optional<tools::password_container> simple_wallet::get_and_verify_passwor
|
|||||||
return pwd_container;
|
return pwd_container;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
||||||
const crypto::secret_key& recovery_key, bool recover, bool two_random, const std::string &old_language)
|
const crypto::secret_key& recovery_key, bool recover, bool two_random, const std::string &old_language)
|
||||||
{
|
{
|
||||||
auto rc = tools::wallet2::make_new(vm, password_prompter);
|
auto rc = tools::wallet2::make_new(vm, password_prompter);
|
||||||
m_wallet = std::move(rc.first);
|
m_wallet = std::move(rc.first);
|
||||||
if (!m_wallet)
|
if (!m_wallet)
|
||||||
{
|
{
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
epee::wipeable_string password = rc.second.password();
|
||||||
|
|
||||||
if (!m_subaddress_lookahead.empty())
|
if (!m_subaddress_lookahead.empty())
|
||||||
{
|
{
|
||||||
@ -3436,7 +3445,7 @@ bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
|||||||
}
|
}
|
||||||
mnemonic_language = get_mnemonic_language();
|
mnemonic_language = get_mnemonic_language();
|
||||||
if (mnemonic_language.empty())
|
if (mnemonic_language.empty())
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
m_wallet->set_seed_language(mnemonic_language);
|
m_wallet->set_seed_language(mnemonic_language);
|
||||||
@ -3454,7 +3463,7 @@ bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
|||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
fail_msg_writer() << tr("failed to generate new wallet: ") << e.what();
|
fail_msg_writer() << tr("failed to generate new wallet: ") << e.what();
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert rng value to electrum-style word list
|
// convert rng value to electrum-style word list
|
||||||
@ -3479,10 +3488,10 @@ bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
|||||||
}
|
}
|
||||||
success_msg_writer() << "**********************************************************************";
|
success_msg_writer() << "**********************************************************************";
|
||||||
|
|
||||||
return true;
|
return std::move(password);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
||||||
const cryptonote::account_public_address& address, const boost::optional<crypto::secret_key>& spendkey,
|
const cryptonote::account_public_address& address, const boost::optional<crypto::secret_key>& spendkey,
|
||||||
const crypto::secret_key& viewkey)
|
const crypto::secret_key& viewkey)
|
||||||
{
|
{
|
||||||
@ -3490,8 +3499,9 @@ bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
|||||||
m_wallet = std::move(rc.first);
|
m_wallet = std::move(rc.first);
|
||||||
if (!m_wallet)
|
if (!m_wallet)
|
||||||
{
|
{
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
epee::wipeable_string password = rc.second.password();
|
||||||
|
|
||||||
if (!m_subaddress_lookahead.empty())
|
if (!m_subaddress_lookahead.empty())
|
||||||
{
|
{
|
||||||
@ -3521,22 +3531,23 @@ bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
|||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
fail_msg_writer() << tr("failed to generate new wallet: ") << e.what();
|
fail_msg_writer() << tr("failed to generate new wallet: ") << e.what();
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return std::move(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
||||||
const std::string &device_name) {
|
const std::string &device_name) {
|
||||||
auto rc = tools::wallet2::make_new(vm, password_prompter);
|
auto rc = tools::wallet2::make_new(vm, password_prompter);
|
||||||
m_wallet = std::move(rc.first);
|
m_wallet = std::move(rc.first);
|
||||||
if (!m_wallet)
|
if (!m_wallet)
|
||||||
{
|
{
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
epee::wipeable_string password = rc.second.password();
|
||||||
|
|
||||||
if (!m_subaddress_lookahead.empty())
|
if (!m_subaddress_lookahead.empty())
|
||||||
{
|
{
|
||||||
@ -3557,21 +3568,22 @@ bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
|||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
fail_msg_writer() << tr("failed to generate new wallet: ") << e.what();
|
fail_msg_writer() << tr("failed to generate new wallet: ") << e.what();
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return std::move(password);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
||||||
const std::string &multisig_keys, const std::string &old_language)
|
const std::string &multisig_keys, const std::string &old_language)
|
||||||
{
|
{
|
||||||
auto rc = tools::wallet2::make_new(vm, password_prompter);
|
auto rc = tools::wallet2::make_new(vm, password_prompter);
|
||||||
m_wallet = std::move(rc.first);
|
m_wallet = std::move(rc.first);
|
||||||
if (!m_wallet)
|
if (!m_wallet)
|
||||||
{
|
{
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
epee::wipeable_string password = rc.second.password();
|
||||||
|
|
||||||
if (!m_subaddress_lookahead.empty())
|
if (!m_subaddress_lookahead.empty())
|
||||||
{
|
{
|
||||||
@ -3601,7 +3613,7 @@ bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
|||||||
if (!m_wallet->multisig(&ready, &threshold, &total) || !ready)
|
if (!m_wallet->multisig(&ready, &threshold, &total) || !ready)
|
||||||
{
|
{
|
||||||
fail_msg_writer() << tr("failed to generate new mutlisig wallet");
|
fail_msg_writer() << tr("failed to generate new mutlisig wallet");
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
message_writer(console_color_white, true) << boost::format(tr("Generated new %u/%u multisig wallet: ")) % threshold % total
|
message_writer(console_color_white, true) << boost::format(tr("Generated new %u/%u multisig wallet: ")) % threshold % total
|
||||||
<< m_wallet->get_account().get_public_address_str(m_wallet->nettype());
|
<< m_wallet->get_account().get_public_address_str(m_wallet->nettype());
|
||||||
@ -3609,10 +3621,10 @@ bool simple_wallet::new_wallet(const boost::program_options::variables_map& vm,
|
|||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
fail_msg_writer() << tr("failed to generate new wallet: ") << e.what();
|
fail_msg_writer() << tr("failed to generate new wallet: ") << e.what();
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return std::move(password);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool simple_wallet::open_wallet(const boost::program_options::variables_map& vm)
|
bool simple_wallet::open_wallet(const boost::program_options::variables_map& vm)
|
||||||
|
@ -91,13 +91,13 @@ namespace cryptonote
|
|||||||
//! \return Prompts user for password and verifies against local file. Logs on error and returns `none`
|
//! \return Prompts user for password and verifies against local file. Logs on error and returns `none`
|
||||||
boost::optional<tools::password_container> get_and_verify_password() const;
|
boost::optional<tools::password_container> get_and_verify_password() const;
|
||||||
|
|
||||||
bool new_wallet(const boost::program_options::variables_map& vm, const crypto::secret_key& recovery_key,
|
boost::optional<epee::wipeable_string> new_wallet(const boost::program_options::variables_map& vm, const crypto::secret_key& recovery_key,
|
||||||
bool recover, bool two_random, const std::string &old_language);
|
bool recover, bool two_random, const std::string &old_language);
|
||||||
bool new_wallet(const boost::program_options::variables_map& vm, const cryptonote::account_public_address& address,
|
boost::optional<epee::wipeable_string> new_wallet(const boost::program_options::variables_map& vm, const cryptonote::account_public_address& address,
|
||||||
const boost::optional<crypto::secret_key>& spendkey, const crypto::secret_key& viewkey);
|
const boost::optional<crypto::secret_key>& spendkey, const crypto::secret_key& viewkey);
|
||||||
bool new_wallet(const boost::program_options::variables_map& vm,
|
boost::optional<epee::wipeable_string> new_wallet(const boost::program_options::variables_map& vm,
|
||||||
const std::string &multisig_keys, const std::string &old_language);
|
const std::string &multisig_keys, const std::string &old_language);
|
||||||
bool new_wallet(const boost::program_options::variables_map& vm, const std::string& device_name);
|
boost::optional<epee::wipeable_string> new_wallet(const boost::program_options::variables_map& vm, const std::string& device_name);
|
||||||
bool open_wallet(const boost::program_options::variables_map& vm);
|
bool open_wallet(const boost::program_options::variables_map& vm);
|
||||||
bool close_wallet();
|
bool close_wallet();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user