Merge pull request #4269

3d5abbe [#4027] add change_wallet_password wallet rpc command (artyomsol)
This commit is contained in:
luigi1111 2018-09-04 13:17:40 -05:00
commit 59e6fb06f9
No known key found for this signature in database
GPG key ID: F4ACA0183641E010
3 changed files with 54 additions and 1 deletions

View file

@ -2742,6 +2742,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
{