From d218b767aa05a5847bc9116d9831e294a32cc7c4 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Sun, 28 May 2017 07:53:36 +0800 Subject: [PATCH] mempool thread status thread dev started for tests --- main.cpp | 16 ++++++++++ src/CMakeLists.txt | 2 +- src/MempoolStatus.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++ src/MempoolStatus.h | 49 +++++++++++++++++++++++++++++ src/page.h | 1 + 5 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/MempoolStatus.cpp create mode 100644 src/MempoolStatus.h diff --git a/main.cpp b/main.cpp index 6119525..79df005 100644 --- a/main.cpp +++ b/main.cpp @@ -204,6 +204,22 @@ main(int ac, const char* av[]) xmreg::CurrentBlockchainStatus::start_monitor_blockchain_thread(); } + + xmreg::MempoolStatus::blockchain_path + = blockchain_path; + xmreg::MempoolStatus::testnet + = testnet; + xmreg::MempoolStatus::deamon_url + = deamon_url; + xmreg::MempoolStatus::set_blockchain_variables( + &mcore, core_storage); + + // launch the status monitoring thread so that it keeps track of blockchain + // info, e.g., current height. Information from this thread is used + // by tx searching threads that are launched for each user independently, + // when they log back or create new account. + xmreg::MempoolStatus::start_mempool_status_thread(); + // create instance of page class which // contains logic for the website xmreg::page xmrblocks(&mcore, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d4f476c..868bd81 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,7 +14,7 @@ set(SOURCE_FILES CmdLineOptions.cpp page.h rpccalls.cpp rpccalls.h - version.h.in CurrentBlockchainStatus.cpp) + version.h.in CurrentBlockchainStatus.cpp MempoolStatus.cpp MempoolStatus.h) # make static library called libmyxrm # that we are going to link to diff --git a/src/MempoolStatus.cpp b/src/MempoolStatus.cpp new file mode 100644 index 0000000..88ba55b --- /dev/null +++ b/src/MempoolStatus.cpp @@ -0,0 +1,72 @@ +// +// Created by mwo on 28/05/17. +// + +#include "MempoolStatus.h" + +namespace xmreg +{ + +using namespace std; + + +void +MempoolStatus::set_blockchain_variables(MicroCore *_mcore, + Blockchain *_core_storage) { + mcore = _mcore; + core_storage = _core_storage; +} + + + +void +MempoolStatus::start_mempool_status_thread() +{ + + if (!is_running) + { + m_thread = boost::thread{[]() + { + try + { + while (true) + { + + cout << "mempool status: " << endl; + + + // when we reach top of the blockchain, update + // the emission amount every minute. + boost::this_thread::sleep_for(boost::chrono::seconds(10)); + + + } // while (true) + } + catch (boost::thread_interrupted&) + { + cout << "Mempool status thread interrupted." << endl; + return; + } + + }}; // m_thread = boost::thread{[]() + + is_running = true; + + } // if (!is_running) +} + +bool +MempoolStatus::is_thread_running() +{ + return is_running; +} + +bf::path MempoolStatus::blockchain_path {"/home/mwo/.bitmonero/lmdb"}; +string MempoolStatus::deamon_url {"http:://127.0.0.1:18081"}; +bool MempoolStatus::testnet {false}; +atomic MempoolStatus::is_running {false}; +boost::thread MempoolStatus::m_thread; +Blockchain* MempoolStatus::core_storage {nullptr}; +xmreg::MicroCore* MempoolStatus::mcore {nullptr}; + +} \ No newline at end of file diff --git a/src/MempoolStatus.h b/src/MempoolStatus.h new file mode 100644 index 0000000..6a9cf6b --- /dev/null +++ b/src/MempoolStatus.h @@ -0,0 +1,49 @@ +// +// Created by mwo on 28/05/17. +// + +#ifndef XMRBLOCKS_MEMPOOLSTATUS_H +#define XMRBLOCKS_MEMPOOLSTATUS_H + + +#include "MicroCore.h" + +#include + +#include +#include +#include +#include +#include + +namespace xmreg +{ + +struct MempoolStatus +{ + + static boost::thread m_thread; + + static atomic is_running; + + static bf::path blockchain_path; + static string deamon_url; + static bool testnet; + + // make object for accessing the blockchain here + static MicroCore* mcore; + static Blockchain* core_storage; + + static void + set_blockchain_variables(MicroCore* _mcore, + Blockchain* _core_storage); + + static void + start_mempool_status_thread(); + + static bool + is_thread_running(); +}; + +} +#endif //XMRBLOCKS_MEMPOOLSTATUS_H diff --git a/src/page.h b/src/page.h index 0ff364d..781a0a4 100644 --- a/src/page.h +++ b/src/page.h @@ -18,6 +18,7 @@ #include "rpccalls.h" #include "CurrentBlockchainStatus.h" +#include "MempoolStatus.h" #include "../ext/crow/http_request.h"