mirror of
https://github.com/monero-project/monero.git
synced 2025-08-06 08:04:19 -04:00
wallet: rejig to avoid prompting in wallet2
wallet2 is a library, and should not prompt for stdin. Instead, pass a function so simplewallet can prompt on stdin, and a GUI might display a window, etc.
This commit is contained in:
parent
ec5135e5b7
commit
e89994e98f
8 changed files with 97 additions and 78 deletions
|
@ -60,6 +60,16 @@ namespace
|
|||
const command_line::arg_descriptor<std::string> arg_wallet_dir = {"wallet-dir", "Directory for newly created wallets"};
|
||||
|
||||
constexpr const char default_rpc_username[] = "monero";
|
||||
|
||||
boost::optional<tools::password_container> password_prompter(const char *prompt, bool verify)
|
||||
{
|
||||
auto pwd_container = tools::password_container::prompt(verify, prompt);
|
||||
if (!pwd_container)
|
||||
{
|
||||
MERROR("failed to read wallet password");
|
||||
}
|
||||
return pwd_container;
|
||||
}
|
||||
}
|
||||
|
||||
namespace tools
|
||||
|
@ -131,7 +141,7 @@ namespace tools
|
|||
walvars = m_wallet;
|
||||
else
|
||||
{
|
||||
tmpwal = tools::wallet2::make_dummy(*m_vm);
|
||||
tmpwal = tools::wallet2::make_dummy(*m_vm, password_prompter);
|
||||
walvars = tmpwal.get();
|
||||
}
|
||||
boost::optional<epee::net_utils::http::login> http_login{};
|
||||
|
@ -1798,7 +1808,7 @@ namespace tools
|
|||
command_line::add_arg(desc, arg_password);
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm2);
|
||||
}
|
||||
std::unique_ptr<tools::wallet2> wal = tools::wallet2::make_new(vm2).first;
|
||||
std::unique_ptr<tools::wallet2> wal = tools::wallet2::make_new(vm2, password_prompter).first;
|
||||
if (!wal)
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
|
||||
|
@ -1872,7 +1882,7 @@ namespace tools
|
|||
}
|
||||
std::unique_ptr<tools::wallet2> wal = nullptr;
|
||||
try {
|
||||
wal = tools::wallet2::make_from_file(vm2, wallet_file).first;
|
||||
wal = tools::wallet2::make_from_file(vm2, wallet_file, password_prompter).first;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
|
@ -2007,11 +2017,11 @@ int main(int argc, char** argv) {
|
|||
LOG_PRINT_L0(tools::wallet_rpc_server::tr("Loading wallet..."));
|
||||
if(!wallet_file.empty())
|
||||
{
|
||||
wal = tools::wallet2::make_from_file(*vm, wallet_file).first;
|
||||
wal = tools::wallet2::make_from_file(*vm, wallet_file, password_prompter).first;
|
||||
}
|
||||
else
|
||||
{
|
||||
wal = tools::wallet2::make_from_json(*vm, from_json);
|
||||
wal = tools::wallet2::make_from_json(*vm, from_json, password_prompter);
|
||||
}
|
||||
if (!wal)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue