[FWN] Create BlockChain class
This commit is contained in:
parent
8fc1ac736b
commit
de8ccf0ea4
6 changed files with 93 additions and 9 deletions
20
programs/full_web_node/BlockChain.cpp
Normal file
20
programs/full_web_node/BlockChain.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include "BlockChain.hpp"
|
||||
|
||||
#include <graphene/app/application.hpp>
|
||||
|
||||
#include <fc/thread/thread.hpp>
|
||||
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
|
||||
BlockChain::BlockChain()
|
||||
: chainThread(fc::thread::current()),
|
||||
fcTaskScheduler(new QTimer(this)),
|
||||
grapheneApp(new graphene::app::application)
|
||||
{
|
||||
fcTaskScheduler->setInterval(100);
|
||||
fcTaskScheduler->setSingleShot(false);
|
||||
connect(fcTaskScheduler, &QTimer::timeout, [] {fc::yield();});
|
||||
fcTaskScheduler->start();
|
||||
}
|
||||
19
programs/full_web_node/BlockChain.hpp
Normal file
19
programs/full_web_node/BlockChain.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QTimer;
|
||||
class QThread;
|
||||
namespace fc { class thread; }
|
||||
namespace graphene { namespace app { class application; } }
|
||||
class BlockChain : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
fc::thread& chainThread;
|
||||
QTimer* fcTaskScheduler;
|
||||
graphene::app::application* grapheneApp;
|
||||
|
||||
public:
|
||||
BlockChain();
|
||||
virtual ~BlockChain(){}
|
||||
};
|
||||
|
|
@ -5,7 +5,7 @@ project(full_web_node)
|
|||
# Find includes in corresponding build directories
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
# Instruct CMake to run moc automatically when needed.
|
||||
#set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
find_package(Qt5Core)
|
||||
find_package(Qt5Quick)
|
||||
|
|
@ -14,9 +14,10 @@ find_package(Qt5WebEngine)
|
|||
file(GLOB QML qml/*)
|
||||
qt5_add_resources(QML_QRC qml/qml.qrc)
|
||||
|
||||
add_executable(full_web_node main.cpp ${QML_QRC} ${QML})
|
||||
add_executable(full_web_node BlockChain.cpp main.cpp ${QML_QRC} ${QML})
|
||||
|
||||
target_link_libraries(full_web_node PRIVATE Qt5::Core Qt5::Quick Qt5::WebEngine graphene_chain graphene_egenesis_brief graphene_utilities fc graphene_app )
|
||||
target_link_libraries(full_web_node PRIVATE Qt5::Core Qt5::Quick Qt5::WebEngine
|
||||
graphene_chain graphene_egenesis_brief graphene_utilities fc graphene_account_history graphene_market_history graphene_app )
|
||||
|
||||
install( TARGETS
|
||||
full_web_node
|
||||
|
|
|
|||
|
|
@ -1,7 +1,13 @@
|
|||
#include "BlockChain.hpp"
|
||||
|
||||
#include <fc/thread/thread.hpp>
|
||||
#include <fc/thread/future.hpp>
|
||||
#include <fc/network/http/server.hpp>
|
||||
#include <fc/network/ip.hpp>
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QtWebEngine>
|
||||
#include <QtQml>
|
||||
|
||||
|
|
@ -14,11 +20,45 @@ int main(int argc, char *argv[])
|
|||
app.setOrganizationDomain("cryptonomex.org");
|
||||
app.setOrganizationName("Cryptonomex, Inc.");
|
||||
|
||||
QThread chainThread;
|
||||
fc::promise<BlockChain*>::ptr chain = new fc::promise<BlockChain*>;
|
||||
QObject::connect(&chainThread, &QThread::started, [&app, &chain] {
|
||||
chain->set_value(new BlockChain);
|
||||
});
|
||||
chainThread.start();
|
||||
|
||||
QtWebEngine::initialize();
|
||||
fc::http::server webGuiServer;
|
||||
fc::thread serverThread("HTTP server thread");
|
||||
serverThread.async([&webGuiServer] {
|
||||
webGuiServer.listen(fc::ip::endpoint::from_string("127.0.0.1:8080"));
|
||||
webGuiServer.on_request([](const fc::http::request& request, const fc::http::server::response& response) {
|
||||
QString path = QStringLiteral("/Users/nathan/graphene-ui/web/bundle") + QString::fromStdString(request.path);
|
||||
if (path.endsWith('/'))
|
||||
path.append(QStringLiteral("index.html"));
|
||||
QFile file(path);
|
||||
|
||||
if (file.exists()) {
|
||||
file.open(QIODevice::ReadOnly);
|
||||
auto buffer = file.readAll();
|
||||
response.set_status(fc::http::reply::OK);
|
||||
response.set_length(buffer.size());
|
||||
response.write(buffer.data(), buffer.size());
|
||||
} else {
|
||||
response.set_status(fc::http::reply::NotFound);
|
||||
response.set_length(18);
|
||||
response.write("I can't find that.", 18);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
auto chainPtr = chain->wait();
|
||||
engine.rootContext()->setContextProperty(QStringLiteral("blockChain"), chainPtr);
|
||||
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
||||
|
||||
return app.exec();
|
||||
auto ret = app.exec();
|
||||
chainPtr->deleteLater();
|
||||
chainThread.exit(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include "main.moc"
|
||||
|
|
|
|||
1
programs/full_web_node/qml/.gitignore
vendored
Normal file
1
programs/full_web_node/qml/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
qml.qrc.depends
|
||||
|
|
@ -3,11 +3,14 @@ import QtQuick.Window 2.2
|
|||
import QtWebEngine 1.0
|
||||
|
||||
Window {
|
||||
width: 800
|
||||
height: 600
|
||||
visible: true
|
||||
id: window
|
||||
width: Screen.width / 2
|
||||
height: Screen.height / 2
|
||||
|
||||
Rectangle { anchors.fill: parent; color: "#1F1F1F" }
|
||||
WebEngineView {
|
||||
anchors.fill: parent
|
||||
url: "http://localhost:8080"
|
||||
onLoadProgressChanged: if (loadProgress === 100) window.visible = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue