2015-08-12 18:56:33 +00:00
|
|
|
#include "BlockChain.hpp"
|
|
|
|
|
|
|
|
|
|
#include <graphene/app/application.hpp>
|
2015-08-12 19:47:00 +00:00
|
|
|
#include <graphene/account_history/account_history_plugin.hpp>
|
|
|
|
|
#include <graphene/market_history/market_history_plugin.hpp>
|
2015-08-12 18:56:33 +00:00
|
|
|
|
|
|
|
|
#include <fc/thread/thread.hpp>
|
|
|
|
|
|
2015-08-12 19:47:00 +00:00
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
|
|
2015-08-12 18:56:33 +00:00
|
|
|
#include <QThread>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QDebug>
|
2015-08-12 19:47:00 +00:00
|
|
|
#include <QStandardPaths>
|
|
|
|
|
#include <QDir>
|
2015-08-12 18:56:33 +00:00
|
|
|
|
|
|
|
|
BlockChain::BlockChain()
|
2015-08-14 19:09:21 +00:00
|
|
|
: chainThread(new fc::thread("chainThread")),
|
2015-08-12 18:56:33 +00:00
|
|
|
fcTaskScheduler(new QTimer(this)),
|
|
|
|
|
grapheneApp(new graphene::app::application)
|
|
|
|
|
{
|
|
|
|
|
fcTaskScheduler->setInterval(100);
|
|
|
|
|
fcTaskScheduler->setSingleShot(false);
|
|
|
|
|
connect(fcTaskScheduler, &QTimer::timeout, [] {fc::yield();});
|
|
|
|
|
fcTaskScheduler->start();
|
|
|
|
|
}
|
2015-08-12 19:47:00 +00:00
|
|
|
|
2015-08-14 19:09:21 +00:00
|
|
|
BlockChain::~BlockChain() {
|
|
|
|
|
startFuture.cancel_and_wait(__FUNCTION__);
|
|
|
|
|
chainThread->async([this] {
|
|
|
|
|
grapheneApp->shutdown_plugins();
|
|
|
|
|
delete grapheneApp;
|
|
|
|
|
}).wait();
|
|
|
|
|
delete chainThread;
|
2015-08-12 19:47:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlockChain::start()
|
|
|
|
|
{
|
2015-08-14 19:09:21 +00:00
|
|
|
startFuture = chainThread->async([this] {
|
|
|
|
|
try {
|
|
|
|
|
grapheneApp->register_plugin<graphene::account_history::account_history_plugin>();
|
|
|
|
|
grapheneApp->register_plugin<graphene::market_history::market_history_plugin>();
|
|
|
|
|
|
|
|
|
|
QString dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
|
|
|
|
QDir(dataDir).mkpath(".");
|
|
|
|
|
boost::program_options::variables_map map;
|
|
|
|
|
map.insert({"rpc-endpoint",boost::program_options::variable_value(std::string("127.0.0.1:8090"), false)});
|
|
|
|
|
map.insert({"seed-node",boost::program_options::variable_value(std::vector<std::string>{("104.200.28.117:61705")}, false)});
|
|
|
|
|
grapheneApp->initialize(dataDir.toStdString(), map);
|
2015-08-14 19:52:25 +00:00
|
|
|
grapheneApp->initialize_plugins(map);
|
2015-08-14 19:09:21 +00:00
|
|
|
grapheneApp->startup();
|
|
|
|
|
grapheneApp->startup_plugins();
|
|
|
|
|
} catch (const fc::exception& e) {
|
|
|
|
|
elog("Crap went wrong: ${e}", ("e", e.to_detail_string()));
|
|
|
|
|
}
|
|
|
|
|
QMetaObject::invokeMethod(this, "started");
|
|
|
|
|
});
|
2015-08-12 19:47:00 +00:00
|
|
|
}
|