From 88a657cbb784414eb5a700b0923ce74ba0dc31f9 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Feb 2020 03:46:47 +0100 Subject: [PATCH] fixed bugs and code clean up --- src/wallet/plain_wallet_api.cpp | 48 +++++++-------------------------- src/wallet/plain_wallet_api.h | 11 +++----- src/wallet/view_iface.h | 13 +++++++++ src/wallet/wallets_manager.cpp | 10 +++++-- src/wallet/wallets_manager.h | 1 + 5 files changed, 35 insertions(+), 48 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 72c5e8a8..94a6b470 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -54,9 +54,16 @@ namespace plain_wallet return path; } - std::string print_money(int64_t amount) + void initialize_logs() { - return currency::print_money(amount); + std::string log_dir = get_bundle_root_dir(); + log_dir += "/" HOME_FOLDER; + epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2); + epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL); + epee::log_space::log_singletone::add_logger(LOGGER_FILE, "plain_wallet.log", log_dir.c_str()); + LOG_PRINT_L0("Plain wallet initialized: " << CURRENCY_NAME << " v" << PROJECT_VERSION_LONG << ", log location: " << log_dir + "/plain_wallet.log"); + + //glogs_initialized = true; } std::string init(const std::string& ip, const std::string& port) @@ -84,17 +91,7 @@ namespace plain_wallet return API_RETURN_CODE_OK; } - void initialize_logs() - { - std::string log_dir = get_bundle_root_dir(); - log_dir += "/" HOME_FOLDER; - epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2); - epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL); - epee::log_space::log_singletone::add_logger(LOGGER_FILE, "plain_wallet.log", log_dir.c_str()); - LOG_PRINT_L0("Plain wallet initialized: " << CURRENCY_NAME << " v" << PROJECT_VERSION_LONG << ", log location: " << log_dir + "/plain_wallet.log"); - //glogs_initialized = true; - } std::string get_version() { @@ -119,31 +116,6 @@ namespace plain_wallet return epee::serialization::store_t_to_json(sl); } - hwallet create_instance(const std::string& ip, const std::string& port) - { - -// plain_wallet_api_impl* ptr = new plain_wallet_api_impl(ip, port); -// hwallet new_h = gcounter++; -// CRITICAL_REGION_BEGIN(ginstances_lock); -// ginstances[new_h] = ptr; -// CRITICAL_REGION_END(); -// return new_h; - } - - void destroy_instance(hwallet h) - { -// plain_wallet_api_impl* instance_ptr = nullptr; -// CRITICAL_REGION_BEGIN(ginstances_lock); -// auto it = ginstances.find(h); -// if (it == ginstances.end()) -// { -// LOG_ERROR("Internal error: attempt to delete wallet with wrong instance id: " << h); -// } -// instance_ptr = it->second; -// ginstances.erase(it); -// CRITICAL_REGION_END(); -// delete instance_ptr; - } std::string open(const std::string& path, const std::string& password) { epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); @@ -218,7 +190,7 @@ namespace plain_wallet // } std::string get_wallet_status(hwallet h) { - + return gwm.get_wallet_status(h); } std::string invoke(hwallet h, const std::string& params) { diff --git a/src/wallet/plain_wallet_api.h b/src/wallet/plain_wallet_api.h index cfab17fd..4b42c948 100644 --- a/src/wallet/plain_wallet_api.h +++ b/src/wallet/plain_wallet_api.h @@ -15,16 +15,11 @@ 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 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 open(const std::string& path, const std::string& password); + std::string restore(const std::string& seed, const std::string& path, const std::string& password); + std::string generate(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 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 c25cabd9..ccdfe1e6 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -520,6 +520,19 @@ public: END_KV_SERIALIZE_MAP() }; + struct wallet_sync_status_info + { + uint64_t wallet_state; + bool is_in_long_refresh; + uint64_t progress; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(wallet_state) + KV_SERIALIZE(is_in_long_refresh) + KV_SERIALIZE(progress) + END_KV_SERIALIZE_MAP() + }; + struct get_restore_info_response { std::string restore_key; diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index bad50e13..1b9a3f6f 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1133,13 +1133,19 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par std::string wallets_manager::get_wallet_status(uint64_t wallet_id) { - + GET_WALLET_OPT_BY_ID(wallet_id, wo); + view::wallet_sync_status_info wsi = AUTO_VAL_INIT(wsi); + wsi.is_in_long_refresh = wo.long_refresh_in_progress; + wsi.progress = wo.w.unlocked_get().get()->get_sync_progress(); + wsi.wallet_state = wo.wallet_state; + return epee::serialization::store_t_to_json(wsi); } + 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); + CRITICAL_REGION_LOCAL1(wo.long_refresh_in_progress_lock); if (wo.long_refresh_in_progress) { epee::json_rpc::response error_response = AUTO_VAL_INIT(error_response); diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index 9bb661d2..0e3e8e27 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -94,6 +94,7 @@ public: std::string generate_wallet(const std::wstring& path, const std::string& password, view::open_wallet_response& owr); std::string restore_wallet(const std::wstring& path, const std::string& password, const std::string& restore_key, view::open_wallet_response& owr); std::string invoke(uint64_t wallet_id, std::string params); + std::string get_wallet_status(uint64_t wallet_id); std::string run_wallet(uint64_t wallet_id); std::string get_recent_transfers(size_t wallet_id, uint64_t offset, uint64_t count, view::transfers_array& tr_hist); std::string get_wallet_info(size_t wallet_id, view::wallet_info& wi);