diff --git a/src/gui/qt-daemon/application/daemon_backend.cpp b/src/gui/qt-daemon/application/daemon_backend.cpp index 2c9a09e8..bca50a91 100644 --- a/src/gui/qt-daemon/application/daemon_backend.cpp +++ b/src/gui/qt-daemon/application/daemon_backend.cpp @@ -11,11 +11,11 @@ #include "currency_core/core_tools.h" //#include -#define GET_WALLET_OPT_BY_ID(wallet_id, name) \ +#define GET_WALLET_OPT_BY_ID(wallet_id, name) \ CRITICAL_REGION_LOCAL(m_wallets_lock); \ auto it = m_wallets.find(wallet_id); \ -if (it == m_wallets.end()) \ - return API_RETURN_CODE_WALLET_WRONG_ID; \ + if (it == m_wallets.end()) \ + return API_RETURN_CODE_WALLET_WRONG_ID; \ auto& name = it->second; #define GET_WALLET_BY_ID(wallet_id, name) \ @@ -551,8 +551,12 @@ void daemon_backend::init_wallet_entry(wallet_vs_options& wo, uint64_t id) wo.core_conf = currency::get_default_core_runtime_config(); else wo.core_conf = m_ccore.get_blockchain_storage().get_core_runtime_config(); -} + // update wallet log prefix for further usage + if (m_wallet_log_prefixes.size() <= id) + m_wallet_log_prefixes.resize(id + 1); + m_wallet_log_prefixes[id] = std::string("[") + epee::string_tools::num_to_string_fast(id) + ":" + wo.w->get()->get_account().get_public_address_str().substr(0, 6) + "] "; +} std::string daemon_backend::get_tx_pool_info(currency::COMMAND_RPC_GET_POOL_INFO::response& res) @@ -679,7 +683,7 @@ std::string daemon_backend::open_wallet(const std::wstring& path, const std::str **wo.w = w; get_wallet_info(wo, owr.wi); init_wallet_entry(wo, owr.wallet_id); - //update_wallets_info(); + return return_code; } @@ -833,6 +837,7 @@ std::string daemon_backend::close_wallet(size_t wallet_id) it->second.w->get()->store(); m_wallets.erase(it); + m_wallet_log_prefixes[wallet_id] = std::string("[") + epee::string_tools::num_to_string_fast(wallet_id) + ":CLOSED] "; } catch (const std::exception& e) @@ -1600,11 +1605,7 @@ daemon_backend::wallet_vs_options::~wallet_vs_options() std::string daemon_backend::get_wallet_log_prefix(size_t wallet_id) const { - CRITICAL_REGION_LOCAL(m_wallets_lock); - auto it = m_wallets.find(wallet_id); - if (it == m_wallets.end()) - return std::string("[") + epee::string_tools::num_to_string_fast(wallet_id) + ":???]"; - - return std::string("[") + epee::string_tools::num_to_string_fast(wallet_id) + ":" + it->second.w->get()->get_account().get_public_address_str().substr(0, 6) + "]"; + CHECK_AND_ASSERT_MES(wallet_id < m_wallet_log_prefixes.size(), std::string("[") + epee::string_tools::num_to_string_fast(wallet_id) + ":???] ", "wallet prefix is not found for id " << wallet_id); + return m_wallet_log_prefixes[wallet_id]; } diff --git a/src/gui/qt-daemon/application/daemon_backend.h b/src/gui/qt-daemon/application/daemon_backend.h index 33a33272..4996168b 100644 --- a/src/gui/qt-daemon/application/daemon_backend.h +++ b/src/gui/qt-daemon/application/daemon_backend.h @@ -188,6 +188,7 @@ private: std::map m_wallets; + std::vector m_wallet_log_prefixes; };