mirror of
https://github.com/monero-project/monero.git
synced 2025-08-06 00:04:14 -04:00
wallet rpc: Add close_wallet RPC
And close the current wallet automatically if necessary when opening another wallet.
This commit is contained in:
parent
fad88e18a9
commit
54b859bea5
3 changed files with 59 additions and 0 deletions
|
@ -2678,8 +2678,20 @@ namespace tools
|
|||
er.message = "Failed to generate wallet";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_wallet)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_wallet->store();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
|
||||
return false;
|
||||
}
|
||||
delete m_wallet;
|
||||
}
|
||||
m_wallet = wal.release();
|
||||
return true;
|
||||
}
|
||||
|
@ -2736,12 +2748,42 @@ namespace tools
|
|||
er.message = "Failed to open wallet";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_wallet)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_wallet->store();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
|
||||
return false;
|
||||
}
|
||||
delete m_wallet;
|
||||
}
|
||||
m_wallet = wal.release();
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool wallet_rpc_server::on_close_wallet(const wallet_rpc::COMMAND_RPC_CLOSE_WALLET::request& req, wallet_rpc::COMMAND_RPC_CLOSE_WALLET::response& res, epee::json_rpc::error& er)
|
||||
{
|
||||
if (!m_wallet) return not_open(er);
|
||||
|
||||
try
|
||||
{
|
||||
m_wallet->store();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
|
||||
return false;
|
||||
}
|
||||
delete m_wallet;
|
||||
m_wallet = NULL;
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue