mirror of
https://github.com/monero-project/monero.git
synced 2024-10-01 11:49:47 -04:00
simplewallet: make --password-file work in RPC mode
This commit is contained in:
parent
d7fb03fc97
commit
b525457061
@ -760,6 +760,54 @@ void simple_wallet::print_seed(std::string seed)
|
|||||||
std::cout << seed << std::endl;
|
std::cout << seed << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
static bool get_password(const boost::program_options::variables_map& vm, bool allow_entry, tools::password_container &pwd_container)
|
||||||
|
{
|
||||||
|
if (has_arg(vm, arg_password) && has_arg(vm, arg_password_file))
|
||||||
|
{
|
||||||
|
fail_msg_writer() << tr("can't specify more than one of --password and --password-file");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command_line::has_arg(vm, arg_password))
|
||||||
|
{
|
||||||
|
pwd_container.password(command_line::get_arg(vm, arg_password));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command_line::has_arg(vm, arg_password_file))
|
||||||
|
{
|
||||||
|
std::string password;
|
||||||
|
bool r = epee::file_io_utils::load_file_to_string(command_line::get_arg(vm, arg_password_file),
|
||||||
|
password);
|
||||||
|
if (!r)
|
||||||
|
{
|
||||||
|
fail_msg_writer() << tr("the password file specified could not be read");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove line breaks the user might have inserted
|
||||||
|
password.erase(std::remove(password.begin() - 1, password.end(), '\n'), password.end());
|
||||||
|
password.erase(std::remove(password.end() - 1, password.end(), '\r'), password.end());
|
||||||
|
pwd_container.password(password.c_str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allow_entry)
|
||||||
|
{
|
||||||
|
bool r = pwd_container.read_password();
|
||||||
|
if (!r)
|
||||||
|
{
|
||||||
|
fail_msg_writer() << tr("failed to read wallet password");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fail_msg_writer() << tr("Wallet password not set.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
||||||
{
|
{
|
||||||
@ -795,42 +843,9 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
|
|||||||
if (m_daemon_address.empty())
|
if (m_daemon_address.empty())
|
||||||
m_daemon_address = std::string("http://") + m_daemon_host + ":" + std::to_string(m_daemon_port);
|
m_daemon_address = std::string("http://") + m_daemon_host + ":" + std::to_string(m_daemon_port);
|
||||||
|
|
||||||
if (has_arg(vm, arg_password) && has_arg(vm, arg_password_file))
|
|
||||||
{
|
|
||||||
fail_msg_writer() << tr("can't specify more than one of --password and --password-file");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
tools::password_container pwd_container;
|
tools::password_container pwd_container;
|
||||||
if (command_line::has_arg(vm, arg_password))
|
if (!get_password(vm, true, pwd_container))
|
||||||
{
|
return false;
|
||||||
pwd_container.password(command_line::get_arg(vm, arg_password));
|
|
||||||
}
|
|
||||||
else if (command_line::has_arg(vm, arg_password_file))
|
|
||||||
{
|
|
||||||
std::string password;
|
|
||||||
bool r = epee::file_io_utils::load_file_to_string(command_line::get_arg(vm, arg_password_file),
|
|
||||||
password);
|
|
||||||
if (!r)
|
|
||||||
{
|
|
||||||
fail_msg_writer() << tr("the password file specified could not be read");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove line breaks the user might have inserted
|
|
||||||
password.erase(std::remove(password.begin() - 1, password.end(), '\n'), password.end());
|
|
||||||
password.erase(std::remove(password.end() - 1, password.end(), '\r'), password.end());
|
|
||||||
pwd_container.password(password.c_str());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool r = pwd_container.read_password();
|
|
||||||
if (!r)
|
|
||||||
{
|
|
||||||
fail_msg_writer() << tr("failed to read wallet password");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_generate_new.empty() || m_restore_deterministic_wallet || !m_generate_from_view_key.empty() || !m_generate_from_keys.empty())
|
if (!m_generate_new.empty() || m_restore_deterministic_wallet || !m_generate_from_view_key.empty() || !m_generate_from_keys.empty())
|
||||||
{
|
{
|
||||||
@ -2675,16 +2690,13 @@ int main(int argc, char* argv[])
|
|||||||
LOG_ERROR(sw::tr("Daemon address not set."));
|
LOG_ERROR(sw::tr("Daemon address not set."));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(!command_line::has_arg(vm, arg_password) )
|
|
||||||
{
|
|
||||||
LOG_ERROR(sw::tr("Wallet password not set."));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool testnet = command_line::get_arg(vm, arg_testnet);
|
bool testnet = command_line::get_arg(vm, arg_testnet);
|
||||||
bool restricted = command_line::get_arg(vm, arg_restricted);
|
bool restricted = command_line::get_arg(vm, arg_restricted);
|
||||||
std::string wallet_file = command_line::get_arg(vm, arg_wallet_file);
|
std::string wallet_file = command_line::get_arg(vm, arg_wallet_file);
|
||||||
std::string wallet_password = command_line::get_arg(vm, arg_password);
|
tools::password_container pwd_container;
|
||||||
|
if (!get_password(vm, false, pwd_container))
|
||||||
|
return 1;
|
||||||
std::string daemon_address = command_line::get_arg(vm, arg_daemon_address);
|
std::string daemon_address = command_line::get_arg(vm, arg_daemon_address);
|
||||||
std::string daemon_host = command_line::get_arg(vm, arg_daemon_host);
|
std::string daemon_host = command_line::get_arg(vm, arg_daemon_host);
|
||||||
int daemon_port = command_line::get_arg(vm, arg_daemon_port);
|
int daemon_port = command_line::get_arg(vm, arg_daemon_port);
|
||||||
@ -2699,7 +2711,7 @@ int main(int argc, char* argv[])
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
LOG_PRINT_L0(sw::tr("Loading wallet..."));
|
LOG_PRINT_L0(sw::tr("Loading wallet..."));
|
||||||
wal.load(wallet_file, wallet_password);
|
wal.load(wallet_file, pwd_container.password());
|
||||||
wal.init(daemon_address);
|
wal.init(daemon_address);
|
||||||
wal.refresh();
|
wal.refresh();
|
||||||
LOG_PRINT_GREEN(sw::tr("Loaded ok"), LOG_LEVEL_0);
|
LOG_PRINT_GREEN(sw::tr("Loaded ok"), LOG_LEVEL_0);
|
||||||
|
Loading…
Reference in New Issue
Block a user