2015-10-12 17:02:59 +00:00
|
|
|
/*
|
2015-10-12 17:48:40 +00:00
|
|
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
|
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* The MIT License
|
2015-10-12 17:48:40 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2015-10-12 17:48:40 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
2015-10-12 17:02:59 +00:00
|
|
|
*
|
2016-01-06 09:51:18 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
* THE SOFTWARE.
|
2015-10-12 17:02:59 +00:00
|
|
|
*/
|
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-09-18 18:22:20 +00:00
|
|
|
#include <QSettings>
|
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-19 15:16:22 +00:00
|
|
|
grapheneApp(new graphene::app::application),
|
|
|
|
|
webUsername(QStringLiteral("webui")),
|
|
|
|
|
webPassword(QString::fromStdString(fc::sha256::hash(fc::ecc::private_key::generate())))
|
2015-08-19 15:31:57 +00:00
|
|
|
{}
|
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 {
|
2015-09-18 18:22:20 +00:00
|
|
|
QSettings settings;
|
2015-10-08 17:40:58 +00:00
|
|
|
rpcEndpoint = settings.value( "rpc-endpoint", "127.0.0.1:8090" ).value<QString>();
|
|
|
|
|
auto seed_node = settings.value( "seed-node", "104.236.51.238:2005" ).value<QString>().toStdString();
|
2015-08-14 19:09:21 +00:00
|
|
|
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(".");
|
2015-10-08 17:40:58 +00:00
|
|
|
idump((dataDir.toStdString()));
|
2015-08-14 19:09:21 +00:00
|
|
|
boost::program_options::variables_map map;
|
2015-09-18 18:22:20 +00:00
|
|
|
map.insert({"rpc-endpoint",boost::program_options::variable_value(rpcEndpoint.toStdString(), false)});
|
|
|
|
|
map.insert({"seed-node",boost::program_options::variable_value(std::vector<std::string>{(seed_node)}, false)});
|
2015-08-14 19:09:21 +00:00
|
|
|
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();
|
2015-08-19 15:16:22 +00:00
|
|
|
|
|
|
|
|
graphene::app::api_access_info webPermissions;
|
|
|
|
|
auto passHash = fc::sha256::hash(webPassword.toStdString());
|
|
|
|
|
webPermissions.password_hash_b64 = fc::base64_encode(passHash.data(), passHash.data_size());
|
|
|
|
|
webPermissions.password_salt_b64 = fc::base64_encode("");
|
|
|
|
|
webPermissions.allowed_apis = {"database_api", "network_broadcast_api", "network_node_api", "history_api"};
|
2015-09-18 18:22:20 +00:00
|
|
|
grapheneApp->set_api_access_info(webUsername.toStdString(), std::move(webPermissions) );
|
2015-08-14 19:09:21 +00:00
|
|
|
} 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
|
|
|
}
|