From ca0ec026e1dda70aa0212e8287e36d3510f40ab5 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 12 Nov 2019 11:35:09 +0300 Subject: [PATCH] wallet rpc: correct exception handling (#130) --- src/wallet/wallet_rpc_server.cpp | 45 +++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 5bd2fe09..508ff005 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -61,24 +61,39 @@ namespace tools { m_net_server.add_idle_handler([this]() -> bool { - size_t blocks_fetched = 0; - bool received_money = false, ok = false; - std::atomic stop(false); - LOG_PRINT_L2("wallet RPC idle: refreshing..."); - m_wallet.refresh(blocks_fetched, received_money, ok, stop); - if (stop) + try { - LOG_PRINT_L1("wallet RPC idle: refresh failed"); - return true; - } + size_t blocks_fetched = 0; + bool received_money = false, ok = false; + std::atomic stop(false); + LOG_PRINT_L2("wallet RPC idle: refreshing..."); + m_wallet.refresh(blocks_fetched, received_money, ok, stop); + if (stop) + { + LOG_PRINT_L1("wallet RPC idle: refresh failed"); + return true; + } - if (m_do_mint) + if (m_do_mint) + { + bool has_related_alias_in_unconfirmed = false; + LOG_PRINT_L2("wallet RPC idle: scanning tx pool..."); + m_wallet.scan_tx_pool(has_related_alias_in_unconfirmed); + LOG_PRINT_L2("wallet RPC idle: trying to do PoS iteration..."); + m_wallet.try_mint_pos(); + } + } + catch (error::no_connection_to_daemon&) { - bool has_related_alias_in_unconfirmed = false; - LOG_PRINT_L2("wallet RPC idle: scanning tx pool..."); - m_wallet.scan_tx_pool(has_related_alias_in_unconfirmed); - LOG_PRINT_L2("wallet RPC idle: tring to do PoS iteration..."); - m_wallet.try_mint_pos(); + LOG_PRINT_RED("no connection to the daemon", LOG_LEVEL_0); + } + catch(std::exception& e) + { + LOG_ERROR("exeption caught in wallet_rpc_server::idle_handler: " << e.what()); + } + catch(...) + { + LOG_ERROR("unknown exeption caught in wallet_rpc_server::idle_handler"); } return true;