wallet rpc: Add close_wallet RPC

And close the current wallet automatically if necessary when opening another
wallet.
This commit is contained in:
Guillaume LE VAILLANT 2018-09-05 16:38:26 +02:00
parent fad88e18a9
commit 54b859bea5
3 changed files with 59 additions and 0 deletions

View file

@ -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);