Browse Source

new Ex methods

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
a52cd26609
  1. 43
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  2. 3
      libweb3jsonrpc/WebThreeStubServerBase.h
  3. 18
      libweb3jsonrpc/abstractwebthreestubserver.h
  4. 3
      libweb3jsonrpc/spec.json
  5. 30
      test/libweb3jsonrpc/webthreestubclient.h

43
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -781,6 +781,18 @@ string WebThreeStubServerBase::eth_newFilter(Json::Value const& _json)
} }
} }
string WebThreeStubServerBase::eth_newFilterEx(Json::Value const& _json)
{
try
{
return toJS(client()->installWatch(toLogFilter(_json)));
}
catch (...)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
}
}
string WebThreeStubServerBase::eth_newBlockFilter(string const& _filter) string WebThreeStubServerBase::eth_newBlockFilter(string const& _filter)
{ {
h256 filter; h256 filter;
@ -825,6 +837,22 @@ Json::Value WebThreeStubServerBase::eth_getFilterChanges(string const& _filterId
} }
} }
Json::Value WebThreeStubServerBase::eth_getFilterChangesEx(string const& _filterId)
{
try
{
int id = jsToInt(_filterId);
auto entries = client()->checkWatch(id);
if (entries.size())
cnote << "FIRING WATCH" << id << entries.size();
return toJson(entries);
}
catch (...)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
}
}
Json::Value WebThreeStubServerBase::eth_getFilterLogs(string const& _filterId) Json::Value WebThreeStubServerBase::eth_getFilterLogs(string const& _filterId)
{ {
try try
@ -837,6 +865,18 @@ Json::Value WebThreeStubServerBase::eth_getFilterLogs(string const& _filterId)
} }
} }
Json::Value WebThreeStubServerBase::eth_getFilterLogsEx(string const& _filterId)
{
try
{
return toJson(client()->logs(jsToInt(_filterId)));
}
catch (...)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
}
}
Json::Value WebThreeStubServerBase::eth_getLogs(Json::Value const& _json) Json::Value WebThreeStubServerBase::eth_getLogs(Json::Value const& _json)
{ {
try try
@ -982,7 +1022,6 @@ string WebThreeStubServerBase::shh_addToGroup(string const& _group, string const
string WebThreeStubServerBase::shh_newFilter(Json::Value const& _json) string WebThreeStubServerBase::shh_newFilter(Json::Value const& _json)
{ {
try try
{ {
pair<shh::Topics, Public> w = toWatch(_json); pair<shh::Topics, Public> w = toWatch(_json);
@ -1073,3 +1112,5 @@ Json::Value WebThreeStubServerBase::shh_getMessages(string const& _filterId)
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS)); BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
} }
} }

3
libweb3jsonrpc/WebThreeStubServerBase.h

@ -107,10 +107,13 @@ public:
virtual std::string eth_compileSerpent(std::string const& _s); virtual std::string eth_compileSerpent(std::string const& _s);
virtual std::string eth_compileSolidity(std::string const& _code); virtual std::string eth_compileSolidity(std::string const& _code);
virtual std::string eth_newFilter(Json::Value const& _json); virtual std::string eth_newFilter(Json::Value const& _json);
virtual std::string eth_newFilterEx(Json::Value const& _json);
virtual std::string eth_newBlockFilter(std::string const& _filter); virtual std::string eth_newBlockFilter(std::string const& _filter);
virtual bool eth_uninstallFilter(std::string const& _filterId); virtual bool eth_uninstallFilter(std::string const& _filterId);
virtual Json::Value eth_getFilterChanges(std::string const& _filterId); virtual Json::Value eth_getFilterChanges(std::string const& _filterId);
virtual Json::Value eth_getFilterChangesEx(std::string const& _filterId);
virtual Json::Value eth_getFilterLogs(std::string const& _filterId); virtual Json::Value eth_getFilterLogs(std::string const& _filterId);
virtual Json::Value eth_getFilterLogsEx(std::string const& _filterId);
virtual Json::Value eth_getLogs(Json::Value const& _json); virtual Json::Value eth_getLogs(Json::Value const& _json);
virtual Json::Value eth_getWork(); virtual Json::Value eth_getWork();
virtual bool eth_submitWork(std::string const& _nonce, std::string const&, std::string const& _mixHash); virtual bool eth_submitWork(std::string const& _nonce, std::string const&, std::string const& _mixHash);

18
libweb3jsonrpc/abstractwebthreestubserver.h

@ -47,10 +47,13 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(jsonrpc::Procedure("eth_compileSerpent", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_compileSerpentI); this->bindAndAddMethod(jsonrpc::Procedure("eth_compileSerpent", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_compileSerpentI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_compileSolidity", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_compileSolidityI); this->bindAndAddMethod(jsonrpc::Procedure("eth_compileSolidity", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_compileSolidityI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_newFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_newFilterI); this->bindAndAddMethod(jsonrpc::Procedure("eth_newFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_newFilterI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_newFilterEx", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_newFilterExI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_newBlockFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_newBlockFilterI); this->bindAndAddMethod(jsonrpc::Procedure("eth_newBlockFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_newBlockFilterI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_uninstallFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_uninstallFilterI); this->bindAndAddMethod(jsonrpc::Procedure("eth_uninstallFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_uninstallFilterI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getFilterChanges", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getFilterChangesI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getFilterChanges", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getFilterChangesI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getFilterChangesEx", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getFilterChangesExI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getFilterLogs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getFilterLogsI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getFilterLogs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getFilterLogsI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getFilterLogsEx", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getFilterLogsExI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getLogs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_getLogsI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getLogs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_getLogsI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_getWork", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_getWorkI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getWork", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_getWorkI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_submitWork", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING,"param3",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_submitWorkI); this->bindAndAddMethod(jsonrpc::Procedure("eth_submitWork", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING,"param3",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_submitWorkI);
@ -226,6 +229,10 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
{ {
response = this->eth_newFilter(request[0u]); response = this->eth_newFilter(request[0u]);
} }
inline virtual void eth_newFilterExI(const Json::Value &request, Json::Value &response)
{
response = this->eth_newFilterEx(request[0u]);
}
inline virtual void eth_newBlockFilterI(const Json::Value &request, Json::Value &response) inline virtual void eth_newBlockFilterI(const Json::Value &request, Json::Value &response)
{ {
response = this->eth_newBlockFilter(request[0u].asString()); response = this->eth_newBlockFilter(request[0u].asString());
@ -238,10 +245,18 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
{ {
response = this->eth_getFilterChanges(request[0u].asString()); response = this->eth_getFilterChanges(request[0u].asString());
} }
inline virtual void eth_getFilterChangesExI(const Json::Value &request, Json::Value &response)
{
response = this->eth_getFilterChangesEx(request[0u].asString());
}
inline virtual void eth_getFilterLogsI(const Json::Value &request, Json::Value &response) inline virtual void eth_getFilterLogsI(const Json::Value &request, Json::Value &response)
{ {
response = this->eth_getFilterLogs(request[0u].asString()); response = this->eth_getFilterLogs(request[0u].asString());
} }
inline virtual void eth_getFilterLogsExI(const Json::Value &request, Json::Value &response)
{
response = this->eth_getFilterLogsEx(request[0u].asString());
}
inline virtual void eth_getLogsI(const Json::Value &request, Json::Value &response) inline virtual void eth_getLogsI(const Json::Value &request, Json::Value &response)
{ {
response = this->eth_getLogs(request[0u]); response = this->eth_getLogs(request[0u]);
@ -359,10 +374,13 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual std::string eth_compileSerpent(const std::string& param1) = 0; virtual std::string eth_compileSerpent(const std::string& param1) = 0;
virtual std::string eth_compileSolidity(const std::string& param1) = 0; virtual std::string eth_compileSolidity(const std::string& param1) = 0;
virtual std::string eth_newFilter(const Json::Value& param1) = 0; virtual std::string eth_newFilter(const Json::Value& param1) = 0;
virtual std::string eth_newFilterEx(const Json::Value& param1) = 0;
virtual std::string eth_newBlockFilter(const std::string& param1) = 0; virtual std::string eth_newBlockFilter(const std::string& param1) = 0;
virtual bool eth_uninstallFilter(const std::string& param1) = 0; virtual bool eth_uninstallFilter(const std::string& param1) = 0;
virtual Json::Value eth_getFilterChanges(const std::string& param1) = 0; virtual Json::Value eth_getFilterChanges(const std::string& param1) = 0;
virtual Json::Value eth_getFilterChangesEx(const std::string& param1) = 0;
virtual Json::Value eth_getFilterLogs(const std::string& param1) = 0; virtual Json::Value eth_getFilterLogs(const std::string& param1) = 0;
virtual Json::Value eth_getFilterLogsEx(const std::string& param1) = 0;
virtual Json::Value eth_getLogs(const Json::Value& param1) = 0; virtual Json::Value eth_getLogs(const Json::Value& param1) = 0;
virtual Json::Value eth_getWork() = 0; virtual Json::Value eth_getWork() = 0;
virtual bool eth_submitWork(const std::string& param1, const std::string& param2, const std::string& param3) = 0; virtual bool eth_submitWork(const std::string& param1, const std::string& param2, const std::string& param3) = 0;

3
libweb3jsonrpc/spec.json

@ -36,10 +36,13 @@
{ "name": "eth_compileSerpent", "params": [""], "order": [], "returns": ""}, { "name": "eth_compileSerpent", "params": [""], "order": [], "returns": ""},
{ "name": "eth_compileSolidity", "params": [""], "order": [], "returns": ""}, { "name": "eth_compileSolidity", "params": [""], "order": [], "returns": ""},
{ "name": "eth_newFilter", "params": [{}], "order": [], "returns": ""}, { "name": "eth_newFilter", "params": [{}], "order": [], "returns": ""},
{ "name": "eth_newFilterEx", "params": [{}], "order": [], "returns": ""},
{ "name": "eth_newBlockFilter", "params": [""], "order": [], "returns": ""}, { "name": "eth_newBlockFilter", "params": [""], "order": [], "returns": ""},
{ "name": "eth_uninstallFilter", "params": [""], "order": [], "returns": true}, { "name": "eth_uninstallFilter", "params": [""], "order": [], "returns": true},
{ "name": "eth_getFilterChanges", "params": [""], "order": [], "returns": []}, { "name": "eth_getFilterChanges", "params": [""], "order": [], "returns": []},
{ "name": "eth_getFilterChangesEx", "params": [""], "order": [], "returns": []},
{ "name": "eth_getFilterLogs", "params": [""], "order": [], "returns": []}, { "name": "eth_getFilterLogs", "params": [""], "order": [], "returns": []},
{ "name": "eth_getFilterLogsEx", "params": [""], "order": [], "returns": []},
{ "name": "eth_getLogs", "params": [{}], "order": [], "returns": []}, { "name": "eth_getLogs", "params": [{}], "order": [], "returns": []},
{ "name": "eth_getWork", "params": [], "order": [], "returns": []}, { "name": "eth_getWork", "params": [], "order": [], "returns": []},
{ "name": "eth_submitWork", "params": ["", "", ""], "order": [], "returns": true}, { "name": "eth_submitWork", "params": ["", "", ""], "order": [], "returns": true},

30
test/libweb3jsonrpc/webthreestubclient.h

@ -374,6 +374,16 @@ class WebThreeStubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
std::string eth_newFilterEx(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_newFilterEx",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string eth_newBlockFilter(const std::string& param1) throw (jsonrpc::JsonRpcException) std::string eth_newBlockFilter(const std::string& param1) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
@ -404,6 +414,16 @@ class WebThreeStubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value eth_getFilterChangesEx(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_getFilterChangesEx",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value eth_getFilterLogs(const std::string& param1) throw (jsonrpc::JsonRpcException) Json::Value eth_getFilterLogs(const std::string& param1) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
@ -414,6 +434,16 @@ class WebThreeStubClient : public jsonrpc::Client
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
Json::Value eth_getFilterLogsEx(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_getFilterLogsEx",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value eth_getLogs(const Json::Value& param1) throw (jsonrpc::JsonRpcException) Json::Value eth_getLogs(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;

Loading…
Cancel
Save