Browse Source

applied changes from ethereum.js 5538ff7252

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
a014e77af8
  1. 3
      libjsqrc/main.js
  2. 4
      libjsqrc/qt.js
  3. 2
      libjsqrc/setup.js
  4. 2
      libqethereum/QEthereum.cpp
  5. 2
      libqethereum/QEthereum.h
  6. 9
      libweb3jsonrpc/WebThreeStubServer.cpp
  7. 1
      libweb3jsonrpc/WebThreeStubServer.h
  8. 7
      libweb3jsonrpc/abstractwebthreestubserver.h
  9. 1
      libweb3jsonrpc/spec.json
  10. 12
      test/webthreestubclient.h

3
libjsqrc/main.js

@ -48,7 +48,7 @@
}; };
var transactionCall = function (args) { var transactionCall = function (args) {
return typeof args[0] === "string" ? 'transactionByHash' : 'transactonByNumber'; return typeof args[0] === "string" ? 'transactionByHash' : 'transactionByNumber';
}; };
var uncleCall = function (args) { var uncleCall = function (args) {
@ -76,6 +76,7 @@
{ name: 'listening', getter: 'listening', setter: 'setListening' }, { name: 'listening', getter: 'listening', setter: 'setListening' },
{ name: 'mining', getter: 'mining', setter: 'setMining' }, { name: 'mining', getter: 'mining', setter: 'setMining' },
{ name: 'gasPrice', getter: 'gasPrice' }, { name: 'gasPrice', getter: 'gasPrice' },
{ name: 'account', getter: 'account' },
{ name: 'accounts', getter: 'accounts' }, { name: 'accounts', getter: 'accounts' },
{ name: 'peerCount', getter: 'peerCount' }, { name: 'peerCount', getter: 'peerCount' },
{ name: 'defaultBlock', getter: 'defaultBlock', setter: 'setDefaultBlock' }, { name: 'defaultBlock', getter: 'defaultBlock', setter: 'setDefaultBlock' },

4
libjsqrc/qt.js

@ -5,13 +5,13 @@
var self = this; var self = this;
navigator.qt.onmessage = function (message) { navigator.qt.onmessage = function (message) {
self.handlers.forEach(function (handler) { self.handlers.forEach(function (handler) {
handler.call(self, JSON.parse(message)); handler.call(self, JSON.parse(message.data));
}); });
} }
}; };
QtProvider.prototype.send = function(payload) { QtProvider.prototype.send = function(payload) {
navigator.qt.postData(JSON.stringify(payload)); navigator.qt.postMessage(JSON.stringify(payload));
}; };
Object.defineProperty(QtProvider.prototype, "onmessage", { Object.defineProperty(QtProvider.prototype, "onmessage", {

2
libjsqrc/setup.js

@ -11,7 +11,7 @@ navigator.qt = _web3;
navigator.qt.response.connect(function (res) { navigator.qt.response.connect(function (res) {
navigator.qt.handlers.forEach(function (handler) { navigator.qt.handlers.forEach(function (handler) {
handler(res); handler({data: res});
}); });
}); });

2
libqethereum/QEthereum.cpp

@ -100,7 +100,7 @@ static QString formatInput(QJsonObject const& _object)
return QString::fromUtf8(QJsonDocument(res).toJson()); return QString::fromUtf8(QJsonDocument(res).toJson());
} }
void QWebThree::postData(QString _json) void QWebThree::postMessage(QString _json)
{ {
QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object(); QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object();

2
libqethereum/QEthereum.h

@ -39,7 +39,7 @@ public:
void clearWatches(); void clearWatches();
void clientDieing(); void clientDieing();
Q_INVOKABLE void postData(QString _json); Q_INVOKABLE void postMessage(QString _json);
public slots: public slots:
void onDataProcessed(QString _json, QString _addInfo); void onDataProcessed(QString _json, QString _addInfo);

9
libweb3jsonrpc/WebThreeStubServer.cpp

@ -261,9 +261,16 @@ std::shared_ptr<dev::shh::Interface> WebThreeStubServer::face() const
return m_web3.whisper(); 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 WebThreeStubServer::accounts()
{ {
Json::Value ret; Json::Value ret(Json::arrayValue);
for (auto i: m_accounts) for (auto i: m_accounts)
ret.append(toJS(i.first)); ret.append(toJS(i.first));
return ret; return ret;

1
libweb3jsonrpc/WebThreeStubServer.h

@ -57,6 +57,7 @@ class WebThreeStubServer: public AbstractWebThreeStubServer
public: public:
WebThreeStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3, std::vector<dev::KeyPair> const& _accounts); WebThreeStubServer(jsonrpc::AbstractServerConnector* _conn, dev::WebThreeDirect& _web3, std::vector<dev::KeyPair> const& _accounts);
virtual std::string account();
virtual Json::Value accounts(); virtual Json::Value accounts();
virtual std::string addToGroup(std::string const& _group, std::string const& _who); virtual std::string addToGroup(std::string const& _group, std::string const& _who);
virtual std::string balanceAt(std::string const& _address); virtual std::string balanceAt(std::string const& _address);

7
libweb3jsonrpc/abstractwebthreestubserver.h

@ -13,6 +13,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
AbstractWebThreeStubServer(jsonrpc::AbstractServerConnector* conn) : AbstractWebThreeStubServer(jsonrpc::AbstractServerConnector* conn) :
jsonrpc::AbstractServer<AbstractWebThreeStubServer>(conn) jsonrpc::AbstractServer<AbstractWebThreeStubServer>(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("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("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); 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::AbstractServer<AbstractWebThr
} }
inline virtual void accountI(const Json::Value& request, Json::Value& response)
{
response = this->account();
}
inline virtual void accountsI(const Json::Value& request, Json::Value& response) inline virtual void accountsI(const Json::Value& request, Json::Value& response)
{ {
response = this->accounts(); response = this->accounts();
@ -269,6 +275,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
} }
virtual std::string account() = 0;
virtual Json::Value accounts() = 0; virtual Json::Value accounts() = 0;
virtual std::string addToGroup(const std::string& param1, const std::string& param2) = 0; virtual std::string addToGroup(const std::string& param1, const std::string& param2) = 0;
virtual std::string balanceAt(const std::string& param1) = 0; virtual std::string balanceAt(const std::string& param1) = 0;

1
libweb3jsonrpc/spec.json

@ -6,6 +6,7 @@
{ "method": "mining", "params": [], "order": [], "returns" : false }, { "method": "mining", "params": [], "order": [], "returns" : false },
{ "method": "setMining", "params": [false], "order" : [], "returns" : true }, { "method": "setMining", "params": [false], "order" : [], "returns" : true },
{ "method": "gasPrice", "params": [], "order": [], "returns" : "" }, { "method": "gasPrice", "params": [], "order": [], "returns" : "" },
{ "method": "account", "params": [], "order": [], "returns" : "" },
{ "method": "accounts", "params": [], "order": [], "returns" : [] }, { "method": "accounts", "params": [], "order": [], "returns" : [] },
{ "method": "peerCount", "params": [], "order": [], "returns" : 0 }, { "method": "peerCount", "params": [], "order": [], "returns" : 0 },
{ "method": "defaultBlock", "params": [], "order": [], "returns" : 0}, { "method": "defaultBlock", "params": [], "order": [], "returns" : 0},

12
test/webthreestubclient.h

@ -19,6 +19,18 @@ class WebThreeStubClient
delete this->client; delete this->client;
} }
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 accounts() throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;

Loading…
Cancel
Save