mempool thread status thread dev started for tests

This commit is contained in:
moneroexamples 2017-05-28 07:53:36 +08:00
parent 36b9bd2a56
commit 48a999dc80
5 changed files with 139 additions and 1 deletions

View file

@ -201,6 +201,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,

View file

@ -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

72
src/MempoolStatus.cpp Normal file
View file

@ -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<bool> MempoolStatus::is_running {false};
boost::thread MempoolStatus::m_thread;
Blockchain* MempoolStatus::core_storage {nullptr};
xmreg::MicroCore* MempoolStatus::mcore {nullptr};
}

49
src/MempoolStatus.h Normal file
View file

@ -0,0 +1,49 @@
//
// Created by mwo on 28/05/17.
//
#ifndef XMRBLOCKS_MEMPOOLSTATUS_H
#define XMRBLOCKS_MEMPOOLSTATUS_H
#include "MicroCore.h"
#include <boost/algorithm/string.hpp>
#include <iostream>
#include <memory>
#include <thread>
#include <mutex>
#include <atomic>
namespace xmreg
{
struct MempoolStatus
{
static boost::thread m_thread;
static atomic<bool> 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

View file

@ -18,6 +18,7 @@
#include "rpccalls.h"
#include "CurrentBlockchainStatus.h"
#include "MempoolStatus.h"
#include "../ext/crow/http_request.h"