Browse Source

json-rpc generic api

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
4d1e8e8f67
  1. 160
      libethrpc/WebThreeStubServer.cpp
  2. 9
      libethrpc/WebThreeStubServer.h
  3. 43
      libethrpc/abstractwebthreestubserver.h
  4. 9
      libethrpc/spec.json
  5. 59
      test/webthreestubclient.h

160
libethrpc/WebThreeStubServer.cpp

@ -96,6 +96,54 @@ static Json::Value toJson(dev::eth::Transaction const& _t)
return res; return res;
} }
static dev::eth::MessageFilter toMessageFilter(Json::Value const& _json)
{
dev::eth::MessageFilter filter;
if (!_json.isObject() || _json.empty()){
return filter;
}
if (!_json["earliest"].empty())
filter.withEarliest(_json["earliest"].asInt());
if (!_json["latest"].empty())
filter.withLatest(_json["lastest"].asInt());
if (!_json["max"].empty())
filter.withMax(_json["max"].asInt());
if (!_json["skip"].empty())
filter.withSkip(_json["skip"].asInt());
if (!_json["from"].empty())
{
if (_json["from"].isArray())
for (auto i : _json["from"])
filter.from(jsToAddress(i.asString()));
else
filter.from(jsToAddress(_json["from"].asString()));
}
if (!_json["to"].empty())
{
if (_json["to"].isArray())
for (auto i : _json["to"])
filter.from(jsToAddress(i.asString()));
else
filter.from(jsToAddress(_json["to"].asString()));
}
if (!_json["altered"].empty())
{
if (_json["altered"].isArray())
for (auto i: _json["altered"])
if (i.isObject())
filter.altered(jsToAddress(i["id"].asString()), jsToU256(i["at"].asString()));
else
filter.altered((jsToAddress(i.asString())));
else if (_json["altered"].isObject())
filter.altered(jsToAddress(_json["altered"]["id"].asString()), jsToU256(_json["altered"]["at"].asString()));
else
filter.altered(jsToAddress(_json["altered"].asString()));
}
return filter;
}
WebThreeStubServer::WebThreeStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDirect& _web3, std::vector<dev::KeyPair> _accounts): WebThreeStubServer::WebThreeStubServer(jsonrpc::AbstractServerConnector* _conn, WebThreeDirect& _web3, std::vector<dev::KeyPair> _accounts):
AbstractWebThreeStubServer(_conn), AbstractWebThreeStubServer(_conn),
m_web3(_web3) m_web3(_web3)
@ -207,6 +255,13 @@ std::string WebThreeStubServer::call(Json::Value const& _json)
return ret; return ret;
} }
bool WebThreeStubServer::changed(int const& _id)
{
if (!client())
return false;
return client()->checkWatch(_id);
}
std::string WebThreeStubServer::codeAt(string const& _address) std::string WebThreeStubServer::codeAt(string const& _address)
{ {
// temp // temp
@ -235,6 +290,13 @@ std::string WebThreeStubServer::gasPrice()
return toJS(10 * dev::eth::szabo); return toJS(10 * dev::eth::szabo);
} }
Json::Value WebThreeStubServer::getMessages(int const& _id)
{
if (!client())
return Json::Value();
return toJson(client()->messages(_id));
}
bool WebThreeStubServer::listening() bool WebThreeStubServer::listening()
{ {
return m_web3.isNetworkStarted(); return m_web3.isNetworkStarted();
@ -245,65 +307,30 @@ bool WebThreeStubServer::mining()
return client() ? client()->isMining() : false; return client() ? client()->isMining() : false;
} }
std::string WebThreeStubServer::compile(string const& _s) int WebThreeStubServer::newFilter(Json::Value const& _json)
{ {
return toJS(dev::eth::compileLLL(_s)); unsigned ret = -1;
if (!client())
return ret;
ret = client()->installWatch(toMessageFilter(_json));
return ret;
} }
static dev::eth::MessageFilter toMessageFilter(Json::Value const& _json) int WebThreeStubServer::newFilterString(std::string const& _filter)
{ {
dev::eth::MessageFilter filter; unsigned ret = -1;
if (!_json.isObject() || _json.empty()){ if (!client())
return filter; return ret;
} if (_filter.compare("chain") == 0)
ret = client()->installWatch(dev::eth::ChainChangedFilter);
if (!_json["earliest"].empty()) else if (_filter.compare("pending") == 0)
filter.withEarliest(_json["earliest"].asInt()); ret = client()->installWatch(dev::eth::PendingChangedFilter);
if (!_json["latest"].empty()) return ret;
filter.withLatest(_json["lastest"].asInt());
if (!_json["max"].empty())
filter.withMax(_json["max"].asInt());
if (!_json["skip"].empty())
filter.withSkip(_json["skip"].asInt());
if (!_json["from"].empty())
{
if (_json["from"].isArray())
for (auto i : _json["from"])
filter.from(jsToAddress(i.asString()));
else
filter.from(jsToAddress(_json["from"].asString()));
}
if (!_json["to"].empty())
{
if (_json["to"].isArray())
for (auto i : _json["to"])
filter.from(jsToAddress(i.asString()));
else
filter.from(jsToAddress(_json["to"].asString()));
}
if (!_json["altered"].empty())
{
if (_json["altered"].isArray())
for (auto i: _json["altered"])
if (i.isObject())
filter.altered(jsToAddress(i["id"].asString()), jsToU256(i["at"].asString()));
else
filter.altered((jsToAddress(i.asString())));
else if (_json["altered"].isObject())
filter.altered(jsToAddress(_json["altered"]["id"].asString()), jsToU256(_json["altered"]["at"].asString()));
else
filter.altered(jsToAddress(_json["altered"].asString()));
}
return filter;
} }
Json::Value WebThreeStubServer::messages(Json::Value const& _json) std::string WebThreeStubServer::compile(string const& _s)
{ {
Json::Value res; return toJS(dev::eth::compileLLL(_s));
if (!client())
return res;
return toJson(client()->messages(toMessageFilter(_json)));
} }
int WebThreeStubServer::number() int WebThreeStubServer::number()
@ -412,34 +439,7 @@ Json::Value WebThreeStubServer::uncleByNumber(int const& _number, int const& _i)
return toJson(client()->uncle(client()->hashFromNumber(_number), _i)); return toJson(client()->uncle(client()->hashFromNumber(_number), _i));
} }
int WebThreeStubServer::watch(string const& _json) bool WebThreeStubServer::uninstallFilter(int const& _id)
{
unsigned ret = -1;
if (!client())
return ret;
if (_json.compare("chain") == 0)
ret = client()->installWatch(dev::eth::ChainChangedFilter);
else if (_json.compare("pending") == 0)
ret = client()->installWatch(dev::eth::PendingChangedFilter);
else
{
Json::Reader reader;
Json::Value object;
reader.parse(_json, object);
ret = client()->installWatch(toMessageFilter(object));
}
return ret;
}
bool WebThreeStubServer::check(int const& _id)
{
if (!client())
return false;
return client()->checkWatch(_id);
}
bool WebThreeStubServer::killWatch(int const& _id)
{ {
if (!client()) if (!client())
return false; return false;

9
libethrpc/WebThreeStubServer.h

@ -43,17 +43,18 @@ public:
virtual Json::Value blockByHash(std::string const& _hash); virtual Json::Value blockByHash(std::string const& _hash);
virtual Json::Value blockByNumber(int const& _number); virtual Json::Value blockByNumber(int const& _number);
virtual std::string call(Json::Value const& _json); virtual std::string call(Json::Value const& _json);
virtual bool check(int const& _id); virtual bool changed(int const& _id);
virtual std::string codeAt(std::string const& _address); virtual std::string codeAt(std::string const& _address);
virtual std::string coinbase(); virtual std::string coinbase();
virtual std::string compile(std::string const& _s); virtual std::string compile(std::string const& _s);
virtual double countAt(std::string const& _address); virtual double countAt(std::string const& _address);
virtual int defaultBlock(); virtual int defaultBlock();
virtual std::string gasPrice(); virtual std::string gasPrice();
virtual bool killWatch(int const& _id); virtual Json::Value getMessages(int const& _id);
virtual bool listening(); virtual bool listening();
virtual Json::Value messages(Json::Value const& _json);
virtual bool mining(); virtual bool mining();
virtual int newFilter(Json::Value const& _json);
virtual int newFilterString(std::string const& _filter);
virtual int number(); virtual int number();
virtual int peerCount(); virtual int peerCount();
virtual bool setCoinbase(std::string const& _address); virtual bool setCoinbase(std::string const& _address);
@ -65,7 +66,7 @@ public:
virtual Json::Value transactionByNumber(int const& _number, int const& _i); virtual Json::Value transactionByNumber(int const& _number, int const& _i);
virtual Json::Value uncleByHash(std::string const& _hash, int const& _i); virtual Json::Value uncleByHash(std::string const& _hash, int const& _i);
virtual Json::Value uncleByNumber(int const& _number, int const& _i); virtual Json::Value uncleByNumber(int const& _number, int const& _i);
virtual int watch(std::string const& _json); virtual bool uninstallFilter(int const& _id);
void setAccounts(std::vector<dev::KeyPair> const& _accounts); void setAccounts(std::vector<dev::KeyPair> const& _accounts);
private: private:

43
libethrpc/abstractwebthreestubserver.h

@ -18,17 +18,18 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(new jsonrpc::Procedure("blockByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::blockByHashI); this->bindAndAddMethod(new jsonrpc::Procedure("blockByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::blockByHashI);
this->bindAndAddMethod(new jsonrpc::Procedure("blockByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::blockByNumberI); this->bindAndAddMethod(new jsonrpc::Procedure("blockByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::blockByNumberI);
this->bindAndAddMethod(new jsonrpc::Procedure("call", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::callI); this->bindAndAddMethod(new jsonrpc::Procedure("call", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::callI);
this->bindAndAddMethod(new jsonrpc::Procedure("check", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "id",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::checkI); this->bindAndAddMethod(new jsonrpc::Procedure("changed", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::changedI);
this->bindAndAddMethod(new jsonrpc::Procedure("codeAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::codeAtI); this->bindAndAddMethod(new jsonrpc::Procedure("codeAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::codeAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("coinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::coinbaseI); this->bindAndAddMethod(new jsonrpc::Procedure("coinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::coinbaseI);
this->bindAndAddMethod(new jsonrpc::Procedure("compile", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::compileI); this->bindAndAddMethod(new jsonrpc::Procedure("compile", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::compileI);
this->bindAndAddMethod(new jsonrpc::Procedure("countAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_REAL, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::countAtI); this->bindAndAddMethod(new jsonrpc::Procedure("countAt", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_REAL, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::countAtI);
this->bindAndAddMethod(new jsonrpc::Procedure("defaultBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::defaultBlockI); this->bindAndAddMethod(new jsonrpc::Procedure("defaultBlock", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::defaultBlockI);
this->bindAndAddMethod(new jsonrpc::Procedure("gasPrice", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::gasPriceI); this->bindAndAddMethod(new jsonrpc::Procedure("gasPrice", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::gasPriceI);
this->bindAndAddMethod(new jsonrpc::Procedure("killWatch", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_BOOLEAN, "id",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::killWatchI); this->bindAndAddMethod(new jsonrpc::Procedure("getMessages", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::getMessagesI);
this->bindAndAddMethod(new jsonrpc::Procedure("listening", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::listeningI); this->bindAndAddMethod(new jsonrpc::Procedure("listening", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::listeningI);
this->bindAndAddMethod(new jsonrpc::Procedure("messages", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_ARRAY, "params",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::messagesI);
this->bindAndAddMethod(new jsonrpc::Procedure("mining", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::miningI); this->bindAndAddMethod(new jsonrpc::Procedure("mining", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, NULL), &AbstractWebThreeStubServer::miningI);
this->bindAndAddMethod(new jsonrpc::Procedure("newFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::newFilterI);
this->bindAndAddMethod(new jsonrpc::Procedure("newFilterString", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::newFilterStringI);
this->bindAndAddMethod(new jsonrpc::Procedure("number", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::numberI); this->bindAndAddMethod(new jsonrpc::Procedure("number", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::numberI);
this->bindAndAddMethod(new jsonrpc::Procedure("peerCount", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::peerCountI); this->bindAndAddMethod(new jsonrpc::Procedure("peerCount", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::peerCountI);
this->bindAndAddMethod(new jsonrpc::Procedure("setCoinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::setCoinbaseI); this->bindAndAddMethod(new jsonrpc::Procedure("setCoinbase", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::setCoinbaseI);
@ -40,7 +41,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(new jsonrpc::Procedure("transactionByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::transactionByNumberI); this->bindAndAddMethod(new jsonrpc::Procedure("transactionByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::transactionByNumberI);
this->bindAndAddMethod(new jsonrpc::Procedure("uncleByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::uncleByHashI); this->bindAndAddMethod(new jsonrpc::Procedure("uncleByHash", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::uncleByHashI);
this->bindAndAddMethod(new jsonrpc::Procedure("uncleByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::uncleByNumberI); this->bindAndAddMethod(new jsonrpc::Procedure("uncleByNumber", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_INTEGER,"param2",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::uncleByNumberI);
this->bindAndAddMethod(new jsonrpc::Procedure("watch", jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_INTEGER, "params",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::watchI); this->bindAndAddMethod(new jsonrpc::Procedure("uninstallFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::uninstallFilterI);
} }
@ -69,9 +70,9 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->call(request[0u]); response = this->call(request[0u]);
} }
inline virtual void checkI(const Json::Value& request, Json::Value& response) inline virtual void changedI(const Json::Value& request, Json::Value& response)
{ {
response = this->check(request["id"].asInt()); response = this->changed(request[0u].asInt());
} }
inline virtual void codeAtI(const Json::Value& request, Json::Value& response) inline virtual void codeAtI(const Json::Value& request, Json::Value& response)
@ -104,9 +105,9 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->gasPrice(); response = this->gasPrice();
} }
inline virtual void killWatchI(const Json::Value& request, Json::Value& response) inline virtual void getMessagesI(const Json::Value& request, Json::Value& response)
{ {
response = this->killWatch(request["id"].asInt()); response = this->getMessages(request[0u].asInt());
} }
inline virtual void listeningI(const Json::Value& request, Json::Value& response) inline virtual void listeningI(const Json::Value& request, Json::Value& response)
@ -114,14 +115,19 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->listening(); response = this->listening();
} }
inline virtual void messagesI(const Json::Value& request, Json::Value& response) inline virtual void miningI(const Json::Value& request, Json::Value& response)
{ {
response = this->messages(request["params"]); response = this->mining();
} }
inline virtual void miningI(const Json::Value& request, Json::Value& response) inline virtual void newFilterI(const Json::Value& request, Json::Value& response)
{ {
response = this->mining(); response = this->newFilter(request[0u]);
}
inline virtual void newFilterStringI(const Json::Value& request, Json::Value& response)
{
response = this->newFilterString(request[0u].asString());
} }
inline virtual void numberI(const Json::Value& request, Json::Value& response) inline virtual void numberI(const Json::Value& request, Json::Value& response)
@ -179,9 +185,9 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
response = this->uncleByNumber(request[0u].asInt(), request[1u].asInt()); response = this->uncleByNumber(request[0u].asInt(), request[1u].asInt());
} }
inline virtual void watchI(const Json::Value& request, Json::Value& response) inline virtual void uninstallFilterI(const Json::Value& request, Json::Value& response)
{ {
response = this->watch(request["params"].asString()); response = this->uninstallFilter(request[0u].asInt());
} }
@ -190,17 +196,18 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual Json::Value blockByHash(const std::string& param1) = 0; virtual Json::Value blockByHash(const std::string& param1) = 0;
virtual Json::Value blockByNumber(const int& param1) = 0; virtual Json::Value blockByNumber(const int& param1) = 0;
virtual std::string call(const Json::Value& param1) = 0; virtual std::string call(const Json::Value& param1) = 0;
virtual bool check(const int& id) = 0; virtual bool changed(const int& param1) = 0;
virtual std::string codeAt(const std::string& param1) = 0; virtual std::string codeAt(const std::string& param1) = 0;
virtual std::string coinbase() = 0; virtual std::string coinbase() = 0;
virtual std::string compile(const std::string& param1) = 0; virtual std::string compile(const std::string& param1) = 0;
virtual double countAt(const std::string& param1) = 0; virtual double countAt(const std::string& param1) = 0;
virtual int defaultBlock() = 0; virtual int defaultBlock() = 0;
virtual std::string gasPrice() = 0; virtual std::string gasPrice() = 0;
virtual bool killWatch(const int& id) = 0; virtual Json::Value getMessages(const int& param1) = 0;
virtual bool listening() = 0; virtual bool listening() = 0;
virtual Json::Value messages(const Json::Value& params) = 0;
virtual bool mining() = 0; virtual bool mining() = 0;
virtual int newFilter(const Json::Value& param1) = 0;
virtual int newFilterString(const std::string& param1) = 0;
virtual int number() = 0; virtual int number() = 0;
virtual int peerCount() = 0; virtual int peerCount() = 0;
virtual bool setCoinbase(const std::string& param1) = 0; virtual bool setCoinbase(const std::string& param1) = 0;
@ -212,7 +219,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual Json::Value transactionByNumber(const int& param1, const int& param2) = 0; virtual Json::Value transactionByNumber(const int& param1, const int& param2) = 0;
virtual Json::Value uncleByHash(const std::string& param1, const int& param2) = 0; virtual Json::Value uncleByHash(const std::string& param1, const int& param2) = 0;
virtual Json::Value uncleByNumber(const int& param1, const int& param2) = 0; virtual Json::Value uncleByNumber(const int& param1, const int& param2) = 0;
virtual int watch(const std::string& params) = 0; virtual bool uninstallFilter(const int& param1) = 0;
}; };
#endif //_ABSTRACTWEBTHREESTUBSERVER_H_ #endif //_ABSTRACTWEBTHREESTUBSERVER_H_

9
libethrpc/spec.json

@ -28,10 +28,11 @@
{ "method": "compile", "params": [""], "order": [], "returns": ""}, { "method": "compile", "params": [""], "order": [], "returns": ""},
{ "method": "messages", "params": { "params": {}}, "order": ["params"], "returns": []}, { "method": "newFilter", "params": [{}], "order": [], "returns": 0},
{ "method": "watch", "params": { "params": ""}, "order": ["params"], "returns": 0}, { "method": "newFilterString", "params": [""], "order": [], "returns": 0},
{ "method": "check", "params": { "id": 0}, "order": [], "returns": true}, { "method": "uninstallFilter", "params": [0], "order": [], "returns": true},
{ "method": "killWatch", "params": { "id": 0}, "order": ["params"], "returns": true} { "method": "changed", "params": [0], "order": [], "returns": true},
{ "method": "getMessages", "params": [0], "order": [], "returns": []}
] ]

59
test/webthreestubclient.h

@ -83,12 +83,12 @@ class WebThreeStubClient
} }
bool check(const int& id) throw (jsonrpc::JsonRpcException) bool changed(const int& param1) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
p["id"] = id; p.append(param1);
Json::Value result = this->client->CallMethod("check",p); Json::Value result = this->client->CallMethod("changed",p);
if (result.isBool()) if (result.isBool())
return result.asBool(); return result.asBool();
else else
@ -171,14 +171,14 @@ class WebThreeStubClient
} }
bool killWatch(const int& id) throw (jsonrpc::JsonRpcException) Json::Value getMessages(const int& param1) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
p["id"] = id; p.append(param1);
Json::Value result = this->client->CallMethod("killWatch",p); Json::Value result = this->client->CallMethod("getMessages",p);
if (result.isBool()) if (result.isArray())
return result.asBool(); return result;
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
@ -196,26 +196,39 @@ class WebThreeStubClient
} }
Json::Value messages(const Json::Value& params) throw (jsonrpc::JsonRpcException) bool mining() throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
p["params"] = params; p = Json::nullValue;
Json::Value result = this->client->CallMethod("mining",p);
if (result.isBool())
return result.asBool();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
Json::Value result = this->client->CallMethod("messages",p); }
if (result.isArray())
return result; int newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->client->CallMethod("newFilter",p);
if (result.isInt())
return result.asInt();
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
} }
bool mining() throw (jsonrpc::JsonRpcException) int newFilterString(const std::string& param1) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
p = Json::nullValue; p.append(param1);
Json::Value result = this->client->CallMethod("mining",p);
if (result.isBool()) Json::Value result = this->client->CallMethod("newFilterString",p);
return result.asBool(); if (result.isInt())
return result.asInt();
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
@ -367,14 +380,14 @@ p.append(param2);
} }
int watch(const std::string& params) throw (jsonrpc::JsonRpcException) bool uninstallFilter(const int& param1) throw (jsonrpc::JsonRpcException)
{ {
Json::Value p; Json::Value p;
p["params"] = params; p.append(param1);
Json::Value result = this->client->CallMethod("watch",p); Json::Value result = this->client->CallMethod("uninstallFilter",p);
if (result.isInt()) if (result.isBool())
return result.asInt(); return result.asBool();
else else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());

Loading…
Cancel
Save