diff --git a/libjsqrc/main.js b/libjsqrc/main.js index cc85b9850..1f609220b 100644 --- a/libjsqrc/main.js +++ b/libjsqrc/main.js @@ -48,7 +48,7 @@ }; var transactionCall = function (args) { - return typeof args[0] === "string" ? 'transactionByHash' : 'transactonByNumber'; + return typeof args[0] === "string" ? 'transactionByHash' : 'transactionByNumber'; }; var uncleCall = function (args) { @@ -76,6 +76,7 @@ { name: 'listening', getter: 'listening', setter: 'setListening' }, { name: 'mining', getter: 'mining', setter: 'setMining' }, { name: 'gasPrice', getter: 'gasPrice' }, + { name: 'account', getter: 'account' }, { name: 'accounts', getter: 'accounts' }, { name: 'peerCount', getter: 'peerCount' }, { name: 'defaultBlock', getter: 'defaultBlock', setter: 'setDefaultBlock' }, diff --git a/libjsqrc/qt.js b/libjsqrc/qt.js index 1b146c30d..644c37737 100644 --- a/libjsqrc/qt.js +++ b/libjsqrc/qt.js @@ -5,13 +5,13 @@ var self = this; navigator.qt.onmessage = function (message) { self.handlers.forEach(function (handler) { - handler.call(self, JSON.parse(message)); + handler.call(self, JSON.parse(message.data)); }); } }; QtProvider.prototype.send = function(payload) { - navigator.qt.postData(JSON.stringify(payload)); + navigator.qt.postMessage(JSON.stringify(payload)); }; Object.defineProperty(QtProvider.prototype, "onmessage", { diff --git a/libjsqrc/setup.js b/libjsqrc/setup.js index 918100785..434e88eab 100644 --- a/libjsqrc/setup.js +++ b/libjsqrc/setup.js @@ -11,7 +11,7 @@ navigator.qt = _web3; navigator.qt.response.connect(function (res) { navigator.qt.handlers.forEach(function (handler) { - handler(res); + handler({data: res}); }); }); diff --git a/libqethereum/QEthereum.cpp b/libqethereum/QEthereum.cpp index a342a3b1a..34198b4d8 100644 --- a/libqethereum/QEthereum.cpp +++ b/libqethereum/QEthereum.cpp @@ -100,7 +100,7 @@ static QString formatInput(QJsonObject const& _object) return QString::fromUtf8(QJsonDocument(res).toJson()); } -void QWebThree::postData(QString _json) +void QWebThree::postMessage(QString _json) { QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object(); diff --git a/libqethereum/QEthereum.h b/libqethereum/QEthereum.h index 25160cf1e..4f276b7e1 100644 --- a/libqethereum/QEthereum.h +++ b/libqethereum/QEthereum.h @@ -39,7 +39,7 @@ public: void clearWatches(); void clientDieing(); - Q_INVOKABLE void postData(QString _json); + Q_INVOKABLE void postMessage(QString _json); public slots: void onDataProcessed(QString _json, QString _addInfo); diff --git a/libweb3jsonrpc/WebThreeStubServer.cpp b/libweb3jsonrpc/WebThreeStubServer.cpp index 0db178dfe..7c0425469 100644 --- a/libweb3jsonrpc/WebThreeStubServer.cpp +++ b/libweb3jsonrpc/WebThreeStubServer.cpp @@ -261,9 +261,16 @@ std::shared_ptr WebThreeStubServer::face() const return m_web3.whisper(); } +std::string WebThreeStubServer::account() +{ + if (!m_accounts.empty()) + return toJS(m_accounts.begin()->first); + return ""; +} + Json::Value WebThreeStubServer::accounts() { - Json::Value ret; + Json::Value ret(Json::arrayValue); for (auto i: m_accounts) ret.append(toJS(i.first)); return ret; diff --git a/libweb3jsonrpc/WebThreeStubServer.h b/libweb3jsonrpc/WebThreeStubServer.h index 93d428fa0..1a1bd7967 100644 --- a/libweb3jsonrpc/WebThreeStubServer.h +++ b/libweb3jsonrpc/WebThreeStubServer.h @@ -57,6 +57,7 @@ class WebThreeStubServer: public AbstractWebThreeStubServer public: WebThreeStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3, std::vector const& _accounts); + virtual std::string account(); virtual Json::Value accounts(); virtual std::string addToGroup(std::string const& _group, std::string const& _who); virtual std::string balanceAt(std::string const& _address); diff --git a/libweb3jsonrpc/abstractwebthreestubserver.h b/libweb3jsonrpc/abstractwebthreestubserver.h index 66b9ff77d..ac6893933 100644 --- a/libweb3jsonrpc/abstractwebthreestubserver.h +++ b/libweb3jsonrpc/abstractwebthreestubserver.h @@ -13,6 +13,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer(conn) { + this->bindAndAddMethod(new jsonrpc::Procedure("account", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::accountI); this->bindAndAddMethod(new jsonrpc::Procedure("accounts", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::accountsI); this->bindAndAddMethod(new jsonrpc::Procedure("addToGroup", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::addToGroupI); this->bindAndAddMethod(new jsonrpc::Procedure("balanceAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::balanceAtI); @@ -58,6 +59,11 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServeraccount(); + } + inline virtual void accountsI(const Json::Value& request, Json::Value& response) { response = this->accounts(); @@ -269,6 +275,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerclient; } + std::string account() throw (jsonrpc::JsonRpcException) + { + Json::Value p; + p = Json::nullValue; + Json::Value result = this->client->CallMethod("account",p); + if (result.isString()) + return result.asString(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + + } + Json::Value accounts() throw (jsonrpc::JsonRpcException) { Json::Value p;