diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index f2418dbb0..a6d0355e1 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include "MainWin.h" #include "DownloadView.h" #include "MiningView.h" @@ -158,6 +159,7 @@ Main::Main(QWidget *parent) : m_webThree.reset(new WebThreeDirect(string("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir() + "/AlethZero", false, {"eth", "shh"})); m_qwebConnector.reset(new QWebThreeConnector()); +// m_httpConnector.reset(new jsonrpc::CorsHttpServer(8080)); m_server.reset(new OurWebThreeStubServer(*m_qwebConnector, *web3(), keysAsVector(m_myKeys), this)); connect(&*m_server, SIGNAL(onNewId(QString)), SLOT(addNewId(QString))); m_server->setIdentities(keysAsVector(owned())); @@ -173,6 +175,7 @@ Main::Main(QWidget *parent) : QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); QWebFrame* f = ui->webView->page()->mainFrame(); f->disconnect(SIGNAL(javaScriptWindowObjectCleared())); + connect(f, &QWebFrame::javaScriptWindowObjectCleared, QETH_INSTALL_JS_NAMESPACE(f, this, qweb)); connect(m_qweb, SIGNAL(onNewId(QString)), this, SLOT(addNewId(QString))); }); diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index 37ec8f7c1..03f6dc2fa 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -49,6 +49,10 @@ class Client; class State; }} +namespace jsonrpc { +class CorsHttpServer; +} + class QQuickView; class OurWebThreeStubServer; @@ -280,6 +284,7 @@ private: bool m_logChanged = true; std::unique_ptr m_qwebConnector; +// std::unique_ptr m_httpConnector; std::unique_ptr m_server; QWebThree* m_qweb = nullptr; diff --git a/libjsqrc/natspec.js b/libjsqrc/natspec.js index 457a487a0..db5ce9a87 100644 --- a/libjsqrc/natspec.js +++ b/libjsqrc/natspec.js @@ -39,10 +39,10 @@ var getContractMethods = function (address, abi) { var impl = function () { var params = Array.prototype.slice.call(arguments); var parsed = inputParser[displayName][typeName].apply(null, params); - var methodSignature = _natspec.sha3(web3.fromAscii(method.name)).slice(0, 10); + var signature = web3.abi.methodSignature(web3.method.name); var output = _natspec.call(JSON.stringify({ to: address, - data: methodSignature + parsed + data: signature + parsed })); return outputParser[displayName][typeName](output); }; diff --git a/libjsqrc/setup.js b/libjsqrc/setup.js index b83745c33..cd496967a 100644 --- a/libjsqrc/setup.js +++ b/libjsqrc/setup.js @@ -22,25 +22,10 @@ navigator.qt = _web3; -(function () { - navigator.qt.handlers = []; - Object.defineProperty(navigator.qt, 'onmessage', { - set: function (handler) { - navigator.qt.handlers.push(handler); - } - }); -})(); - -navigator.qt.response.connect(function (res) { - navigator.qt.handlers.forEach(function (handler) { - handler({data: res}); - }); -}); - if (window.Promise === undefined) { window.Promise = ES6Promise.Promise; } var web3 = require('web3'); -web3.setProvider(new web3.providers.QtProvider()); +web3.setProvider(new web3.providers.QtSyncProvider()); diff --git a/libqwebthree/QWebThree.cpp b/libqwebthree/QWebThree.cpp index 3f4b5c67d..e565c10a2 100644 --- a/libqwebthree/QWebThree.cpp +++ b/libqwebthree/QWebThree.cpp @@ -101,7 +101,7 @@ static QString formatInput(QJsonObject const& _object) return QString::fromUtf8(QJsonDocument(res).toJson()); } -void QWebThree::postMessage(QString _json) +QString QWebThree::callMethod(QString _json) { QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object(); @@ -117,7 +117,8 @@ void QWebThree::postMessage(QString _json) m_watches.erase(std::remove(m_watches.begin(), m_watches.end(), idToRemove), m_watches.end()); } - emit processData(formatInput(f), method); + emit processData(formatInput(f), method); // it's synchronous + return m_response; } static QString formatOutput(QJsonObject const& _object) @@ -151,7 +152,7 @@ void QWebThree::onDataProcessed(QString _json, QString _addInfo) res["_id"] = (int)m_watches[i]; res["data"] = elem["result"].toArray(); - response(QString::fromUtf8(QJsonDocument(res).toJson())); + syncResponse(QString::fromUtf8(QJsonDocument(res).toJson())); } } } @@ -165,7 +166,12 @@ void QWebThree::onDataProcessed(QString _json, QString _addInfo) else if (!_addInfo.compare("shh_newIdentity") && f.contains("result")) emit onNewId(f["result"].toString()); - response(formatOutput(f)); + syncResponse(formatOutput(f)); +} + +void QWebThree::syncResponse(QString _json) +{ + m_response = _json; } QWebThreeConnector::QWebThreeConnector() diff --git a/libqwebthree/QWebThree.h b/libqwebthree/QWebThree.h index 48cae6135..d6b8655db 100644 --- a/libqwebthree/QWebThree.h +++ b/libqwebthree/QWebThree.h @@ -39,7 +39,8 @@ public: void clearWatches(); void clientDieing(); - Q_INVOKABLE void postMessage(QString _json); + Q_INVOKABLE QString callMethod(QString _json); + void syncResponse(QString _json); public slots: void onDataProcessed(QString _json, QString _addInfo); @@ -52,6 +53,7 @@ signals: private: std::vector m_watches; std::vector m_shhWatches; + QString m_response; }; class QWebThreeConnector: public QObject, public jsonrpc::AbstractServerConnector diff --git a/libweb3jsonrpc/CorsHttpServer.cpp b/libweb3jsonrpc/CorsHttpServer.cpp index ef4f2be37..0ba5083ef 100644 --- a/libweb3jsonrpc/CorsHttpServer.cpp +++ b/libweb3jsonrpc/CorsHttpServer.cpp @@ -24,7 +24,12 @@ namespace jsonrpc { -bool CorsHttpServer::SendResponse(std::string const& _response, void* _addInfo) +int HttpServer::callback(struct mg_connection *conn) +{ + +} + +bool CorsHttpServer::SendResponse(const std::string& _response, void* _addInfo) { struct mg_connection* conn = (struct mg_connection*) _addInfo; if (mg_printf(conn, "HTTP/1.1 200 OK\r\n" diff --git a/libweb3jsonrpc/CorsHttpServer.h b/libweb3jsonrpc/CorsHttpServer.h index e697ecaa1..706a7b374 100644 --- a/libweb3jsonrpc/CorsHttpServer.h +++ b/libweb3jsonrpc/CorsHttpServer.h @@ -28,7 +28,7 @@ class CorsHttpServer : public HttpServer { public: using HttpServer::HttpServer; - bool virtual SendResponse(std::string const& _response, void* _addInfo = NULL); + bool virtual SendResponse(const std::string& _response, void* _addInfo = NULL); }; }