Merge pull request #5429

bcb86ae6 wallet_rpc_server: fix inconsistent wallet caches on reload (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2019-04-16 22:39:37 +02:00
commit 35b3d754e8
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
3 changed files with 77 additions and 45 deletions

View file

@ -3111,6 +3111,18 @@ namespace tools
er.message = "Invalid filename";
return false;
}
if (m_wallet && req.autosave_current)
{
try
{
m_wallet->store();
}
catch (const std::exception& e)
{
handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
return false;
}
}
std::string wallet_file = m_wallet_dir + "/" + req.filename;
{
po::options_description desc("dummy");
@ -3141,6 +3153,16 @@ namespace tools
}
if (m_wallet)
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, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
if (req.autosave_current)
{
try
{
@ -3151,24 +3173,6 @@ namespace tools
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, const connection_context *ctx)
{
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;
@ -3385,6 +3389,20 @@ namespace tools
return false;
}
if (m_wallet && req.autosave_current)
{
try
{
if (!wallet_file.empty())
m_wallet->store();
}
catch (const std::exception &e)
{
handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
return false;
}
}
try
{
if (!req.spendkey.empty())
@ -3433,19 +3451,7 @@ namespace tools
}
if (m_wallet)
{
try
{
if (!wallet_file.empty())
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();
res.address = m_wallet->get_account().get_public_address_str(m_wallet->nettype());
return true;
@ -3511,6 +3517,18 @@ namespace tools
return false;
}
}
if (m_wallet && req.autosave_current)
{
try
{
m_wallet->store();
}
catch (const std::exception &e)
{
handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
return false;
}
}
// process seed_offset if given
{
@ -3621,18 +3639,7 @@ namespace tools
}
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();
res.address = m_wallet->get_account().get_public_address_str(m_wallet->nettype());
res.info = "Wallet has been restored successfully.";