Browse Source

qwebthree sync

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
8c2c08e869
  1. 3
      alethzero/MainWin.cpp
  2. 5
      alethzero/MainWin.h
  3. 4
      libjsqrc/natspec.js
  4. 17
      libjsqrc/setup.js
  5. 14
      libqwebthree/QWebThree.cpp
  6. 4
      libqwebthree/QWebThree.h
  7. 7
      libweb3jsonrpc/CorsHttpServer.cpp
  8. 2
      libweb3jsonrpc/CorsHttpServer.h

3
alethzero/MainWin.cpp

@ -48,6 +48,7 @@
#include <libethereum/EthereumHost.h>
#include <libethereum/DownloadMan.h>
#include <libweb3jsonrpc/WebThreeStubServer.h>
#include <libweb3jsonrpc/CorsHttpServer.h>
#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)));
});

5
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<QWebThreeConnector> m_qwebConnector;
// std::unique_ptr<jsonrpc::CorsHttpServer> m_httpConnector;
std::unique_ptr<OurWebThreeStubServer> m_server;
QWebThree* m_qweb = nullptr;

4
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);
};

17
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());

14
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()

4
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<unsigned> m_watches;
std::vector<unsigned> m_shhWatches;
QString m_response;
};
class QWebThreeConnector: public QObject, public jsonrpc::AbstractServerConnector

7
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"

2
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);
};
}

Loading…
Cancel
Save