1
0
Fork 0
forked from lthn/blockchain

implemented synchronyzation thread

This commit is contained in:
cryptozoidberg 2020-01-17 23:44:22 +01:00
parent 068bda9052
commit cbce45285c
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
4 changed files with 18 additions and 6 deletions

View file

@ -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()
}

View file

@ -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();

View file

@ -1236,6 +1236,11 @@ void wallet2::handle_pulled_blocks(size_t& blocks_added, std::atomic<bool>& 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;

View file

@ -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<uint64_t, uint64_t>& distribution);
uint64_t get_sync_progress();
private:
void add_transfers_to_expiration_list(const std::vector<uint64_t>& 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<i_core_proxy> m_core_proxy;
std::shared_ptr<i_wallet2_callback> m_wcallback;
uint64_t m_height_of_start_sync;
uint64_t m_last_sync_percent;
std::atomic<uint64_t> m_last_sync_percent;
uint64_t m_last_pow_block_h;
currency::core_runtime_config m_core_runtime_config;
escrow_contracts_container m_contracts;