From cbce45285ca5915b75ad3e2458afb6a409d27f27 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 17 Jan 2020 23:44:22 +0100 Subject: [PATCH] implemented synchronyzation thread --- src/wallet/plain_wallet_api_impl.cpp | 14 ++++++++++---- src/wallet/plain_wallet_api_impl.h | 1 + src/wallet/wallet2.cpp | 5 +++++ src/wallet/wallet2.h | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/wallet/plain_wallet_api_impl.cpp b/src/wallet/plain_wallet_api_impl.cpp index 9e2d5e39..5b4b83b9 100644 --- a/src/wallet/plain_wallet_api_impl.cpp +++ b/src/wallet/plain_wallet_api_impl.cpp @@ -99,21 +99,27 @@ namespace plain_wallet { m_sync_thread = std::thread([&]() { - + m_wallet->refresh(m_stop); }); } + + bool plain_wallet_api_impl::cancel_sync_thread() + { + m_stop = true; + } + std::string plain_wallet_api_impl::get_sync_status() { - + m_wallet->get_sync_progress(); } std::string plain_wallet_api_impl::sync() { - + m_wallet->refresh(m_stop); } std::string plain_wallet_api_impl::invoke(const std::string& params) { - + m_rpc_wrapper->handle_http_request_map() } diff --git a/src/wallet/plain_wallet_api_impl.h b/src/wallet/plain_wallet_api_impl.h index 3a27abf7..ff1f5473 100644 --- a/src/wallet/plain_wallet_api_impl.h +++ b/src/wallet/plain_wallet_api_impl.h @@ -21,6 +21,7 @@ namespace plain_wallet std::string generate(const std::string& path, const std::string password); bool start_sync_thread(); + bool cancel_sync_thread(); std::string get_sync_status(); std::string sync(); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index d66fead1..abaea6aa 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1236,6 +1236,11 @@ void wallet2::handle_pulled_blocks(size_t& blocks_added, std::atomic& stop WLT_LOG_L1("[PULL BLOCKS] " << res.start_height << " --> " << m_blockchain.size()); } //---------------------------------------------------------------------------------------------------- +uint64_t wallet2::get_sync_progress() +{ + return m_last_sync_percent; +} +//---------------------------------------------------------------------------------------------------- void wallet2::refresh() { size_t blocks_fetched = 0; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 2b65d049..7654bba7 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -744,7 +744,7 @@ namespace tools std::string get_log_prefix() const { return m_log_prefix; } static uint64_t get_max_unlock_time_from_receive_indices(const currency::transaction& tx, const money_transfer2_details& td); bool get_utxo_distribution(std::map& distribution); - + uint64_t get_sync_progress(); private: void add_transfers_to_expiration_list(const std::vector& selected_transfers, uint64_t expiration, uint64_t change_amount, const crypto::hash& related_tx_id); void remove_transfer_from_expiration_list(uint64_t transfer_index); @@ -895,7 +895,7 @@ private: std::shared_ptr m_core_proxy; std::shared_ptr m_wcallback; uint64_t m_height_of_start_sync; - uint64_t m_last_sync_percent; + std::atomic m_last_sync_percent; uint64_t m_last_pow_block_h; currency::core_runtime_config m_core_runtime_config; escrow_contracts_container m_contracts;