Browse Source

removed dependency on qwebthree

cl-refactor
arkpar 10 years ago
parent
commit
1eec363a0c
  1. 13
      libqwebthree/QWebThree.cpp
  2. 5
      mix/CMakeLists.txt
  3. 37
      mix/ClientModel.cpp
  4. 7
      mix/ClientModel.h
  5. 2
      mix/qml/MainContent.qml

13
libqwebthree/QWebThree.cpp

@ -41,9 +41,20 @@ void QWebThree::clientDieing()
this->disconnect();
}
static QString formatInput(QJsonObject const& _object)
{
QJsonObject res;
res["jsonrpc"] = QString::fromStdString("2.0");
res["method"] = _object["call"];
res["params"] = _object["args"];
res["id"] = _object["_id"];
return QString::fromUtf8(QJsonDocument(res).toJson());
}
QString QWebThree::callMethod(QString _json)
{
emit processData(_json, ""); // it's synchronous
QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object();
emit processData(formatInput(f), ""); // it's synchronous
return m_response;
}

5
mix/CMakeLists.txt

@ -34,8 +34,11 @@ eth_add_executable(${EXECUTABLE}
target_link_libraries(${EXECUTABLE} Qt5::Core)
target_link_libraries(${EXECUTABLE} Qt5::Gui)
target_link_libraries(${EXECUTABLE} Qt5::Widgets)
target_link_libraries(${EXECUTABLE} Qt5::Network)
target_link_libraries(${EXECUTABLE} Qt5::Quick)
target_link_libraries(${EXECUTABLE} Qt5::Qml)
target_link_libraries(${EXECUTABLE} webthree)
target_link_libraries(${EXECUTABLE} qwebthree)
target_link_libraries(${EXECUTABLE} ethereum)
target_link_libraries(${EXECUTABLE} evm)
target_link_libraries(${EXECUTABLE} ethcore)

37
mix/ClientModel.cpp

@ -22,6 +22,7 @@
#include <QDebug>
#include <QQmlContext>
#include <QQmlApplicationEngine>
#include <jsonrpccpp/server.h>
#include <libdevcore/CommonJS.h>
#include <libethereum/Transaction.h>
#include <libqwebthree/QWebThree.h>
@ -38,10 +39,30 @@
using namespace dev;
using namespace dev::eth;
using namespace dev::mix;
namespace dev
{
namespace mix
{
class RpcConnector: public jsonrpc::AbstractServerConnector
{
public:
virtual bool StartListening() override { return true; }
virtual bool StopListening() override { return true; }
virtual bool SendResponse(std::string const& _response, void*) override
{
m_response = QString::fromStdString(_response);
return true;
}
QString response() const { return m_response; }
private:
QString m_response;
};
ClientModel::ClientModel(AppContext* _context):
m_context(_context), m_running(false), m_qWebThree(nullptr)
m_context(_context), m_running(false), m_rpcConnector(new RpcConnector())
{
qRegisterMetaType<QBigInt*>("QBigInt*");
qRegisterMetaType<QEther*>("QEther*");
@ -55,11 +76,7 @@ ClientModel::ClientModel(AppContext* _context):
connect(this, &ClientModel::dataAvailable, this, &ClientModel::showDebugger, Qt::QueuedConnection);
m_client.reset(new MixClient());
m_qWebThree = new QWebThree(this);
m_qWebThreeConnector.reset(new QWebThreeConnector());
m_qWebThreeConnector->setQWeb(m_qWebThree);
m_web3Server.reset(new Web3Server(*m_qWebThreeConnector.get(), std::vector<dev::KeyPair> { m_client->userAccount() }, m_client.get()));
connect(m_qWebThree, &QWebThree::response, this, &ClientModel::apiResponse);
m_web3Server.reset(new Web3Server(*m_rpcConnector.get(), std::vector<dev::KeyPair> { m_client->userAccount() }, m_client.get()));
_context->appEngine()->rootContext()->setContextProperty("clientModel", this);
}
@ -70,7 +87,8 @@ ClientModel::~ClientModel()
QString ClientModel::apiCall(QString const& _message)
{
return m_qWebThree->callMethod(_message);
m_rpcConnector->OnRequest(_message.toStdString(), nullptr);
return m_rpcConnector->response();
}
QString ClientModel::contractAddress() const
@ -237,3 +255,6 @@ ExecutionResult ClientModel::callContract(Address const& _contract, bytes const&
return r;
}
}
}

7
mix/ClientModel.h

@ -32,9 +32,6 @@ using AssemblyDebuggerData = std::tuple<QList<QObject*>, dev::mix::QQMLMap*>;
Q_DECLARE_METATYPE(AssemblyDebuggerData)
Q_DECLARE_METATYPE(dev::mix::ExecutionResult)
class QWebThree;
class QWebThreeConnector;
namespace dev
{
namespace mix
@ -42,6 +39,7 @@ namespace mix
class AppContext;
class Web3Server;
class RpcConnector;
/// Backend transaction config class
struct TransactionSettings
@ -124,8 +122,7 @@ private:
AppContext* m_context;
std::atomic<bool> m_running;
std::unique_ptr<MixClient> m_client;
QWebThree* m_qWebThree;
std::unique_ptr<QWebThreeConnector> m_qWebThreeConnector;
std::unique_ptr<RpcConnector> m_rpcConnector;
std::unique_ptr<Web3Server> m_web3Server;
};

2
mix/qml/MainContent.qml

@ -20,7 +20,7 @@ Rectangle {
property alias rightViewVisible : rightView.visible
property alias webViewVisible : webPreview.visible
property bool webViewHorizontal : codeWebSplitter.orientation === Qt.Vertical
property bool webViewHorizontal : codeWebSplitter.orientation === Qt.Vertical //vertical splitter positions elements vertically, splits screen horizontally
onWidthChanged:
{

Loading…
Cancel
Save