Browse Source

common changes

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
ee7c423868
  1. 19
      libjsqrc/ethereum.js
  2. 12
      libweb3jsonrpc/WebThreeStubServer.cpp
  3. 3
      libweb3jsonrpc/WebThreeStubServer.h
  4. 19
      libweb3jsonrpc/abstractwebthreestubserver.h
  5. 3
      libweb3jsonrpc/spec.json
  6. 35
      test/webthreestubclient.h

19
libjsqrc/ethereum.js

@ -217,7 +217,7 @@ module.exports = {
You should have received a copy of the GNU Lesser General Public License
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file websocket.js
/** @file autoprovider.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
@ -231,7 +231,7 @@ module.exports = {
*/
if ("build" !== 'build') {/*
var WebSocket = require('ws'); // jshint ignore:line
var web3 = require('./web3'); // jshint ignore:line
var web3 = require('./main.js'); // jshint ignore:line
*/}
var AutoProvider = function (userOptions) {
@ -247,13 +247,13 @@ var AutoProvider = function (userOptions) {
this.provider = new web3.providers.QtProvider();
return;
}
userOptions = userOptions || {};
var options = {
httprpc: userOptions.httprpc || 'http://localhost:8080',
websockets: userOptions.websockets || 'ws://localhost:40404/eth'
};
var self = this;
var closeWithSuccess = function (success) {
ws.close();
@ -274,7 +274,7 @@ var AutoProvider = function (userOptions) {
var ws = new WebSocket(options.websockets);
ws.onopen = function() {
closeWithSuccess(true);
closeWithSuccess(true);
};
ws.onerror = function() {
@ -553,7 +553,8 @@ var ethMethods = function () {
{ name: 'compilers', call: 'eth_compilers' },
{ name: 'lll', call: 'eth_lll' },
{ name: 'solidity', call: 'eth_solidity' },
{ name: 'serpent', call: 'eth_serpent' }
{ name: 'serpent', call: 'eth_serpent' },
{ name: 'logs', call: 'eth_logs' }
];
return methods;
};
@ -599,7 +600,7 @@ var ethWatchMethods = function () {
return [
{ name: 'newFilter', call: newFilter },
{ name: 'uninstallFilter', call: 'eth_uninstallFilter' },
{ name: 'logs', call: 'eth_getMessages' }
{ name: 'getMessages', call: 'eth_filterLogs' }
];
};
@ -904,8 +905,6 @@ Filter.prototype.messages = function() {
});
};
Filter.prototype.logs = Filter.prototype.messages;
function messageHandler(data) {
if(data._event !== undefined) {
web3.trigger(data._event, data._id, data.data);
@ -1062,4 +1061,4 @@ module.exports = web3;
},{"./lib/autoprovider":2,"./lib/contract":3,"./lib/httprpc":4,"./lib/main":5,"./lib/qt":6,"./lib/websocket":7}]},{},[])
//# sourceMappingURL=ethereum.js.map
//# sourceMappingURL=ethereum.js.map

12
libweb3jsonrpc/WebThreeStubServer.cpp

@ -394,14 +394,20 @@ std::string WebThreeStubServer::db_get(std::string const& _name, std::string con
return toJS(dev::asBytes(ret));
}
Json::Value WebThreeStubServer::eth_getLogs(int const& _id)
Json::Value WebThreeStubServer::eth_filterLogs(int const& _id)
{
if (!client())
return Json::Value();
// return toJson(client()->messages(_id));
return Json::Value(Json::arrayValue);
return toJson(client()->logs(_id));
}
Json::Value WebThreeStubServer::eth_logs(Json::Value const& _json)
{
if (!client())
return Json::Value(Json::arrayValue);
return toJson(client()->logs(toLogFilter(_json)));
}
std::string WebThreeStubServer::db_getString(std::string const& _name, std::string const& _key)
{
bytes k = sha3(_name).asBytes() + sha3(_key).asBytes();

3
libweb3jsonrpc/WebThreeStubServer.h

@ -76,7 +76,8 @@ public:
virtual double eth_countAt(std::string const& _address);
virtual int eth_defaultBlock();
virtual std::string eth_gasPrice();
virtual Json::Value eth_getLogs(int const& _id);
virtual Json::Value eth_filterLogs(int const& _id);
virtual Json::Value eth_logs(Json::Value const& _json);
virtual bool eth_listening();
virtual bool eth_mining();
virtual int eth_newFilter(Json::Value const& _json);

19
libweb3jsonrpc/abstractwebthreestubserver.h

@ -28,10 +28,11 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(new jsonrpc::Procedure("eth_compilers", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_compilersI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_countAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_REAL, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_countAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_defaultBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_defaultBlockI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_filterLogs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_filterLogsI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_gasPrice", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_gasPriceI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_getLogs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_getLogsI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_listening", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_listeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_lll", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_lllI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_logs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_logsI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_mining", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::eth_miningI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_newFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_newFilterI);
this->bindAndAddMethod(new jsonrpc::Procedure("eth_newFilterString", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_newFilterStringI);
@ -137,14 +138,14 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->eth_defaultBlock();
}
inline virtual void eth_gasPriceI(const Json::Value& request, Json::Value& response)
inline virtual void eth_filterLogsI(const Json::Value& request, Json::Value& response)
{
response = this->eth_gasPrice();
response = this->eth_filterLogs(request[0u].asInt());
}
inline virtual void eth_getLogsI(const Json::Value& request, Json::Value& response)
inline virtual void eth_gasPriceI(const Json::Value& request, Json::Value& response)
{
response = this->eth_getLogs(request[0u].asInt());
response = this->eth_gasPrice();
}
inline virtual void eth_listeningI(const Json::Value& request, Json::Value& response)
@ -157,6 +158,11 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->eth_lll(request[0u].asString());
}
inline virtual void eth_logsI(const Json::Value& request, Json::Value& response)
{
response = this->eth_logs(request[0u]);
}
inline virtual void eth_miningI(const Json::Value& request, Json::Value& response)
{
response = this->eth_mining();
@ -308,10 +314,11 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual Json::Value eth_compilers() = 0;
virtual double eth_countAt(const std::string& param1) = 0;
virtual int eth_defaultBlock() = 0;
virtual Json::Value eth_filterLogs(const int& param1) = 0;
virtual std::string eth_gasPrice() = 0;
virtual Json::Value eth_getLogs(const int& param1) = 0;
virtual bool eth_listening() = 0;
virtual std::string eth_lll(const std::string& param1) = 0;
virtual Json::Value eth_logs(const Json::Value& param1) = 0;
virtual bool eth_mining() = 0;
virtual int eth_newFilter(const Json::Value& param1) = 0;
virtual int eth_newFilterString(const std::string& param1) = 0;

3
libweb3jsonrpc/spec.json

@ -37,7 +37,8 @@
{ "method": "eth_newFilterString", "params": [""], "order": [], "returns": 0},
{ "method": "eth_uninstallFilter", "params": [0], "order": [], "returns": true},
{ "method": "eth_changed", "params": [0], "order": [], "returns": false},
{ "method": "eth_getLogs", "params": [0], "order": [], "returns": []},
{ "method": "eth_filterLogs", "params": [0], "order": [], "returns": []},
{ "method": "eth_logs", "params": [{}], "order": [], "returns": []},
{ "method": "db_put", "params": ["", "", ""], "order": [], "returns": true},
{ "method": "db_get", "params": ["", ""], "order": [], "returns": ""},

35
test/webthreestubclient.h

@ -216,26 +216,26 @@ p.append(param3);
}
std::string eth_gasPrice() throw (jsonrpc::JsonRpcException)
Json::Value eth_filterLogs(const int& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("eth_gasPrice",p);
if (result.isString())
return result.asString();
p.append(param1);
Json::Value result = this->client->CallMethod("eth_filterLogs",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value eth_getLogs(const int& param1) throw (jsonrpc::JsonRpcException)
std::string eth_gasPrice() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->client->CallMethod("eth_getLogs",p);
if (result.isArray())
return result;
p = Json::nullValue;
Json::Value result = this->client->CallMethod("eth_gasPrice",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
@ -266,6 +266,19 @@ p.append(param3);
}
Json::Value eth_logs(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->client->CallMethod("eth_logs",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool eth_mining() throw (jsonrpc::JsonRpcException)
{
Json::Value p;

Loading…
Cancel
Save