mirror of
https://github.com/monero-project/monero.git
synced 2025-08-06 00:14:14 -04:00
[#4027] add change_wallet_password wallet rpc command
This commit is contained in:
parent
b780cf4db1
commit
3d5abbe86b
3 changed files with 54 additions and 1 deletions
|
@ -2728,6 +2728,38 @@ namespace tools
|
|||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool wallet_rpc_server::on_change_wallet_password(const wallet_rpc::COMMAND_RPC_CHANGE_WALLET_PASSWORD::request& req, wallet_rpc::COMMAND_RPC_CHANGE_WALLET_PASSWORD::response& res, epee::json_rpc::error& er)
|
||||
{
|
||||
if (!m_wallet) return not_open(er);
|
||||
if (m_restricted)
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_DENIED;
|
||||
er.message = "Command unavailable in restricted mode.";
|
||||
return false;
|
||||
}
|
||||
if (m_wallet->verify_password(req.old_password))
|
||||
{
|
||||
try
|
||||
{
|
||||
m_wallet->rewrite(m_wallet->get_wallet_file(), req.new_password);
|
||||
m_wallet->store();
|
||||
LOG_PRINT_L0("Wallet password changed.");
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
er.code = WALLET_RPC_ERROR_CODE_INVALID_PASSWORD;
|
||||
er.message = "Invalid original password.";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
void wallet_rpc_server::handle_rpc_exception(const std::exception_ptr& e, epee::json_rpc::error& er, int default_error_code) {
|
||||
try
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue