diff --git a/libjsqrc/ethereum.js b/libjsqrc/ethereum.js index 0a27f3905..f319cd74a 100644 --- a/libjsqrc/ethereum.js +++ b/libjsqrc/ethereum.js @@ -526,6 +526,12 @@ function flattenPromise (obj) { return Promise.resolve(obj); } +var web3Methods = function () { + return [ + { name: 'sha3', call: 'web3_sha3' } + ]; +}; + var ethMethods = function () { var blockCall = function (args) { return typeof args[0] === "string" ? "eth_blockByHash" : "eth_blockByNumber"; @@ -778,6 +784,7 @@ var web3 = { } }; +setupMethods(web3, web3Methods()); setupMethods(web3.eth, ethMethods()); setupProperties(web3.eth, ethProperties()); setupMethods(web3.db, dbMethods()); diff --git a/libweb3jsonrpc/WebThreeStubServer.cpp b/libweb3jsonrpc/WebThreeStubServer.cpp index fc1bd28d1..d88aa0a5f 100644 --- a/libweb3jsonrpc/WebThreeStubServer.cpp +++ b/libweb3jsonrpc/WebThreeStubServer.cpp @@ -244,6 +244,11 @@ std::shared_ptr WebThreeStubServer::face() const return m_web3.whisper(); } +std::string WebThreeStubServer::web3_sha3(std::string const& _param1) +{ + return toJS(sha3(jsToBytes(_param1))); +} + Json::Value WebThreeStubServer::eth_accounts() { Json::Value ret(Json::arrayValue); diff --git a/libweb3jsonrpc/WebThreeStubServer.h b/libweb3jsonrpc/WebThreeStubServer.h index 474fda9af..6d54c59ef 100644 --- a/libweb3jsonrpc/WebThreeStubServer.h +++ b/libweb3jsonrpc/WebThreeStubServer.h @@ -64,6 +64,7 @@ class WebThreeStubServer: public AbstractWebThreeStubServer public: WebThreeStubServer(jsonrpc::AbstractServerConnector& _conn, dev::WebThreeDirect& _web3, std::vector const& _accounts); + virtual std::string web3_sha3(std::string const& _param1); virtual Json::Value eth_accounts(); virtual std::string eth_balanceAt(std::string const& _address); virtual Json::Value eth_blockByHash(std::string const& _hash); diff --git a/libweb3jsonrpc/abstractwebthreestubserver.h b/libweb3jsonrpc/abstractwebthreestubserver.h index a4be6aa45..779d8bec3 100644 --- a/libweb3jsonrpc/abstractwebthreestubserver.h +++ b/libweb3jsonrpc/abstractwebthreestubserver.h @@ -12,6 +12,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer(conn) { + this->bindAndAddMethod(new jsonrpc::Procedure("web3_sha3", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::web3_sha3I); this->bindAndAddMethod(new jsonrpc::Procedure("eth_coinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_coinbaseI); this->bindAndAddMethod(new jsonrpc::Procedure("eth_setCoinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_setCoinbaseI); this->bindAndAddMethod(new jsonrpc::Procedure("eth_listening", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_listeningI); @@ -61,9 +62,12 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerbindAndAddMethod(new jsonrpc::Procedure("shh_changed", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::shh_changedI); } + inline virtual void web3_sha3I(const Json::Value &request, Json::Value &response) + { + response = this->web3_sha3(request[0u].asString()); + } inline virtual void eth_coinbaseI(const Json::Value &request, Json::Value &response) { - (void)request; response = this->eth_coinbase(); } inline virtual void eth_setCoinbaseI(const Json::Value &request, Json::Value &response) @@ -72,7 +76,6 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServereth_listening(); } inline virtual void eth_setListeningI(const Json::Value &request, Json::Value &response) @@ -81,7 +84,6 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServereth_mining(); } inline virtual void eth_setMiningI(const Json::Value &request, Json::Value &response) @@ -90,22 +92,18 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServereth_gasPrice(); } inline virtual void eth_accountsI(const Json::Value &request, Json::Value &response) { - (void)request; response = this->eth_accounts(); } inline virtual void eth_peerCountI(const Json::Value &request, Json::Value &response) { - (void)request; response = this->eth_peerCount(); } inline virtual void eth_defaultBlockI(const Json::Value &request, Json::Value &response) { - (void)request; response = this->eth_defaultBlock(); } inline virtual void eth_setDefaultBlockI(const Json::Value &request, Json::Value &response) @@ -114,7 +112,6 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServereth_number(); } inline virtual void eth_balanceAtI(const Json::Value &request, Json::Value &response) @@ -171,7 +168,6 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServereth_compilers(); } inline virtual void eth_lllI(const Json::Value &request, Json::Value &response) @@ -232,7 +228,6 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServershh_newIdentity(); } inline virtual void shh_haveIdentityI(const Json::Value &request, Json::Value &response) @@ -259,6 +254,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServershh_changed(request[0u].asInt()); } + virtual std::string web3_sha3(const std::string& param1) = 0; virtual std::string eth_coinbase() = 0; virtual bool eth_setCoinbase(const std::string& param1) = 0; virtual bool eth_listening() = 0; diff --git a/libweb3jsonrpc/spec.json b/libweb3jsonrpc/spec.json index 43d8d3f5a..09d88c4d2 100644 --- a/libweb3jsonrpc/spec.json +++ b/libweb3jsonrpc/spec.json @@ -1,4 +1,6 @@ [ + { "name": "web3_sha3", "params": [""], "order": [], "returns" : "" }, + { "name": "eth_coinbase", "params": [], "order": [], "returns" : "" }, { "name": "eth_setCoinbase", "params": [""], "order": [], "returns" : true }, { "name": "eth_listening", "params": [], "order": [], "returns" : false }, diff --git a/test/jsonrpc.cpp b/test/jsonrpc.cpp index 37377407c..454ae2257 100644 --- a/test/jsonrpc.cpp +++ b/test/jsonrpc.cpp @@ -19,7 +19,7 @@ * @date 2014 */ -#if ETH_JSONRPC && 0 +#if ETH_JSONRPC #include #include