diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index f575b508..72c5e8a8 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -216,9 +216,12 @@ namespace plain_wallet // GET_INSTANCE(pimpl, h); // return pimpl->sync(); // } + std::string get_wallet_status(hwallet h) + { + + } std::string invoke(hwallet h, const std::string& params) { - GET_INSTANCE(pimpl, h); - return pimpl->invoke(params); + return gwm.invoke(h, params); } } \ No newline at end of file diff --git a/src/wallet/plain_wallet_api.h b/src/wallet/plain_wallet_api.h index 28701596..cfab17fd 100644 --- a/src/wallet/plain_wallet_api.h +++ b/src/wallet/plain_wallet_api.h @@ -15,15 +15,16 @@ namespace plain_wallet std::string init(const std::string& ip, const std::string& port); std::string get_version(); std::string get_wallet_files(); - std::string print_money(int64_t); + //std::string print_money(int64_t); std::string open(hwallet h, const std::string& path, const std::string& password); std::string restore(hwallet h, const std::string& seed, const std::string& path, const std::string& password); std::string generate(hwallet h, const std::string& path, const std::string& password); - std::string start_sync_thread(hwallet h); - std::string get_sync_status(hwallet h); - std::string cancel_sync_thread(hwallet h); - std::string sync(hwallet h); +// std::string start_sync_thread(hwallet h); +// std::string get_sync_status(hwallet h); +// std::string cancel_sync_thread(hwallet h); +// std::string sync(hwallet h); + std::string get_wallet_status(hwallet h); std::string invoke(hwallet h, const std::string& params); } \ No newline at end of file diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index a15b5713..c25cabd9 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -747,6 +747,7 @@ public: #define API_RETURN_CODE_FALSE "FALSE" #define API_RETURN_CODE_CORE_BUSY "CORE_BUSY" #define API_RETURN_CODE_OVERFLOW "OVERFLOW" +#define API_RETURN_CODE_BUSY "BUSY" #define API_MAX_ALIASES_COUNT 10000 diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 479d7758..bad50e13 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1131,9 +1131,24 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par return API_RETURN_CODE_OK; } +std::string wallets_manager::get_wallet_status(uint64_t wallet_id) +{ + +} std::string wallets_manager::invoke(uint64_t wallet_id, std::string params) { GET_WALLET_OPT_BY_ID(wallet_id, wo); + + CRITICAL_REGION_LOCAL(wo.long_refresh_in_progress_lock); + if (wo.long_refresh_in_progress) + { + epee::json_rpc::response error_response = AUTO_VAL_INIT(error_response); + error_response.error.code = -1; + error_response.error.message = API_RETURN_CODE_BUSY; + return epee::serialization::store_t_to_json(error_response); + } + + auto locker_object = wo.w.lock(); epee::net_utils::http::http_request_info query_info = AUTO_VAL_INIT(query_info); @@ -1542,6 +1557,13 @@ void wallets_manager::wallet_vs_options::worker_func() if (last_wallet_synch_height && *plast_daemon_height - last_wallet_synch_height < 3) show_progress = false; + if(last_wallet_synch_height && *plast_daemon_height - last_wallet_synch_height > 10) + { + CRITICAL_REGION_LOCAL(long_refresh_in_progress_lock); + long_refresh_in_progress = true; + } + + if (show_progress) { wallet_state = wsi.wallet_state = view::wallet_status_info::wallet_state_synchronizing; @@ -1549,6 +1571,7 @@ void wallets_manager::wallet_vs_options::worker_func() pview->update_wallet_status(wsi); } w->get()->refresh(stop_for_refresh); + long_refresh_in_progress = false; w->get()->resend_unconfirmed(); { auto w_ptr = *w; // get locked exclusive access to the wallet first (it's more likely that wallet is locked for a long time than 'offers') diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index e2dc1cef..9bb661d2 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -70,6 +70,10 @@ public: std::atomic* plast_daemon_is_disconnected; std::atomic has_related_alias_in_unconfirmed; std::atomic need_to_update_wallet_info; + + std::atomic long_refresh_in_progress; + epee::critical_section long_refresh_in_progress_lock; //secure wallet state and prevent from long wait while long refresh is in work + view::i_view* pview; uint64_t wallet_id; epee::locked_object> offers;