Browse Source

jsonrpc api changes in progress6, almost finished

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
0e2c4cb438
  1. 356
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  2. 51
      libweb3jsonrpc/WebThreeStubServerBase.h
  3. 100
      libweb3jsonrpc/abstractwebthreestubserver.h
  4. 35
      libweb3jsonrpc/spec.json
  5. 77
      test/webthreestubclient.h

356
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -677,7 +677,7 @@ Json::Value WebThreeStubServerBase::eth_getCompilers()
}
std::string WebThreeStubServerBase::eth_compileLLL(std::string const& _code)
string WebThreeStubServerBase::eth_compileLLL(string const& _code)
{
// TODO throw here jsonrpc errors
string res;
@ -687,7 +687,7 @@ std::string WebThreeStubServerBase::eth_compileLLL(std::string const& _code)
return res;
}
std::string WebThreeStubServerBase::eth_compileSerpent(std::string const& _code)
string WebThreeStubServerBase::eth_compileSerpent(string const& _code)
{
// TODO throw here jsonrpc errors
string res;
@ -708,7 +708,7 @@ std::string WebThreeStubServerBase::eth_compileSerpent(std::string const& _code)
return res;
}
std::string WebThreeStubServerBase::eth_compileSolidity(std::string const& _code)
string WebThreeStubServerBase::eth_compileSolidity(string const& _code)
{
// TOOD throw here jsonrpc errors
string res;
@ -730,62 +730,105 @@ std::string WebThreeStubServerBase::eth_compileSolidity(std::string const& _code
return res;
}
std::string WebThreeStubServerBase::shh_addToGroup(std::string const& _group, std::string const& _who)
string WebThreeStubServerBase::eth_newFilter(Json::Value const& _json)
{
(void)_group;
(void)_who;
return "";
}
Json::Value WebThreeStubServerBase::eth_changed(int _id)
{
auto entries = client()->checkWatch(_id);
if (entries.size())
cnote << "FIRING WATCH" << _id << entries.size();
return toJson(entries);
}
std::string WebThreeStubServerBase::db_get(std::string const& _name, std::string const& _key)
{
string ret = db()->get(_name, _key);
return toJS(dev::asBytes(ret));
}
Json::Value WebThreeStubServerBase::eth_filterLogs(int _id)
{
return toJson(client()->logs(_id));
LogFilter filter;
try
{
filter = toLogFilter(_json);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
return toJS(client()->installWatch(filter));
}
Json::Value WebThreeStubServerBase::eth_logs(Json::Value const& _json)
string WebThreeStubServerBase::eth_newBlockFilter(string const& _filter)
{
return toJson(client()->logs(toLogFilter(_json)));
h256 filter;
if (_filter.compare("chain") == 0)
filter = dev::eth::ChainChangedFilter;
else if (_filter.compare("pending") == 0)
filter = dev::eth::PendingChangedFilter;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
return toJS(client()->installWatch(filter));
}
std::string WebThreeStubServerBase::db_getString(std::string const& _name, std::string const& _key)
bool WebThreeStubServerBase::eth_uninstallFilter(string const& _filterId)
{
return db()->get(_name, _key);;
unsigned id;
try
{
id = jsToInt(_filterId);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
// TODO: throw an error if there is no watch with given id?
client()->uninstallWatch(id);
return true;
}
bool WebThreeStubServerBase::shh_haveIdentity(std::string const& _id)
Json::Value WebThreeStubServerBase::eth_getFilterChanges(string const& _filterId)
{
return m_ids.count(jsToPublic(_id)) > 0;
unsigned id;
try
{
id = jsToInt(_filterId);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
// TODO: throw an error if there is no watch with given id?
auto entries = client()->checkWatch(id);
if (entries.size())
cnote << "FIRING WATCH" << id << entries.size();
return toJson(entries);
}
int WebThreeStubServerBase::eth_newFilter(Json::Value const& _json)
Json::Value WebThreeStubServerBase::eth_getFilterLogs(string const& _filterId)
{
unsigned ret = -1;
ret = client()->installWatch(toLogFilter(_json));
return ret;
unsigned id;
try
{
id = jsToInt(_filterId);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
// TODO: throw an error if there is no watch with given id?
return toJson(client()->logs(id));
}
int WebThreeStubServerBase::eth_newFilterString(std::string const& _filter)
Json::Value WebThreeStubServerBase::eth_getLogs(Json::Value const& _json)
{
unsigned ret = -1;
if (_filter.compare("chain") == 0)
ret = client()->installWatch(dev::eth::ChainChangedFilter);
else if (_filter.compare("pending") == 0)
ret = client()->installWatch(dev::eth::PendingChangedFilter);
return ret;
LogFilter filter;
try
{
filter = toLogFilter(_json);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
return toJson(client()->logs(filter));
}
Json::Value WebThreeStubServerBase::eth_getWork()
@ -797,90 +840,212 @@ Json::Value WebThreeStubServerBase::eth_getWork()
return ret;
}
bool WebThreeStubServerBase::eth_submitWork(std::string const& _nonce)
bool WebThreeStubServerBase::eth_submitWork(string const& _nonce)
{
return client()->submitNonce(jsToFixed<32>(_nonce));
h256 nonce;
try
{
nonce = jsToFixed<32>(_nonce);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
return client()->submitNonce(nonce);
}
int WebThreeStubServerBase::eth_register(std::string const& _address)
string WebThreeStubServerBase::eth_register(string const& _address)
{
return m_accounts->addProxyAccount(jsToAddress(_address));
Address address;
try
{
address = jsToAddress(_address);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
return toJS(m_accounts->addProxyAccount(address));
}
bool WebThreeStubServerBase::eth_unregister(int _id)
bool WebThreeStubServerBase::eth_unregister(string const& _accountId)
{
return m_accounts->removeProxyAccount(_id);
unsigned id;
try
{
id = jsToInt(_accountId);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
// TODO: throw an error on no account with given id
return m_accounts->removeProxyAccount(id);
}
Json::Value WebThreeStubServerBase::eth_queuedTransactions(int _id)
Json::Value WebThreeStubServerBase::eth_queuedTransactions(string const& _accountId)
{
unsigned id;
try
{
id = jsToInt(_accountId);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
// TODO: throw an error on no account with given id
Json::Value ret(Json::arrayValue);
for (TransactionSkeleton const& t: m_accounts->getQueuedTransactions(_id))
for (TransactionSkeleton const& t: m_accounts->getQueuedTransactions(id))
ret.append(toJson(t));
m_accounts->clearQueue(_id);
m_accounts->clearQueue(id);
return ret;
}
std::string WebThreeStubServerBase::shh_newGroup(std::string const& _id, std::string const& _who)
bool WebThreeStubServerBase::db_put(string const& _name, string const& _key, string const& _value)
{
(void)_id;
(void)_who;
return "";
db()->put(_name, _key,_value);
return true;
}
std::string WebThreeStubServerBase::shh_newIdentity()
string WebThreeStubServerBase::db_get(string const& _name, string const& _key)
{
// cnote << this << m_ids;
KeyPair kp = KeyPair::create();
m_ids[kp.pub()] = kp.secret();
return toJS(kp.pub());
return db()->get(_name, _key);;
}
bool WebThreeStubServerBase::shh_post(Json::Value const& _json)
{
shh::Message m = toMessage(_json);
shh::Message m;
try
{
m = toMessage(_json);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
Secret from;
if (m.from() && m_ids.count(m.from()))
{
cwarn << "Silently signing message from identity" << m.from().abridged() << ": User validation hook goes here.";
// TODO: insert validification hook here.
from = m_ids[m.from()];
}
face()->inject(toSealed(_json, m, from));
return true;
}
bool WebThreeStubServerBase::db_put(std::string const& _name, std::string const& _key, std::string const& _value)
std::string WebThreeStubServerBase::shh_newIdentity()
{
string v = asString(jsToBytes(_value));
db()->put(_name, _key, v);
return true;
KeyPair kp = KeyPair::create();
m_ids[kp.pub()] = kp.secret();
return toJS(kp.pub());
}
bool WebThreeStubServerBase::db_putString(std::string const& _name, std::string const& _key, std::string const& _value)
bool WebThreeStubServerBase::shh_hasIdentity(string const& _identity)
{
db()->put(_name, _key,_value);
Public identity;
try
{
identity = jsToPublic(_identity);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
return m_ids.count(identity) > 0;
}
string WebThreeStubServerBase::shh_newGroup(string const& _id, string const& _who)
{
(void)_id;
(void)_who;
return "";
}
string WebThreeStubServerBase::shh_addToGroup(std::string const& _group, string const& _who)
{
(void)_group;
(void)_who;
return "";
}
string WebThreeStubServerBase::shh_newFilter(Json::Value const& _json)
{
pair<shh::FullTopic, Public> w;
try
{
w = toWatch(_json);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
auto ret = face()->installWatch(w.first);
m_shhWatches.insert(make_pair(ret, w.second));
return toJS(ret);
}
bool WebThreeStubServerBase::shh_uninstallFilter(string const& _filterId)
{
int id;
try
{
id = jsToInt(_filterId);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
face()->uninstallWatch(id);
return true;
}
Json::Value WebThreeStubServerBase::shh_changed(int _id)
Json::Value WebThreeStubServerBase::shh_changed(string const& _filterId)
{
int id;
try
{
id = jsToInt(_filterId);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
Json::Value ret(Json::arrayValue);
auto pub = m_shhWatches[_id];
auto pub = m_shhWatches[id];
if (!pub || m_ids.count(pub))
for (h256 const& h: face()->checkWatch(_id))
for (h256 const& h: face()->checkWatch(id))
{
auto e = face()->envelope(h);
shh::Message m;
if (pub)
{
cwarn << "Silently decrypting message from identity" << pub.abridged() << ": User validation hook goes here.";
m = e.open(face()->fullTopic(_id), m_ids[pub]);
m = e.open(face()->fullTopic(id), m_ids[pub]);
}
else
m = e.open(face()->fullTopic(_id));
m = e.open(face()->fullTopic(id));
if (!m)
continue;
ret.append(toJson(h, e, m));
@ -889,22 +1054,33 @@ Json::Value WebThreeStubServerBase::shh_changed(int _id)
return ret;
}
Json::Value WebThreeStubServerBase::shh_getMessages(int _id)
Json::Value WebThreeStubServerBase::shh_getMessages(string const& _filterId)
{
int id;
try
{
id = jsToInt(_filterId);
}
catch (...)
{
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_RPC_INVALID_PARAMS);
}
Json::Value ret(Json::arrayValue);
auto pub = m_shhWatches[_id];
auto pub = m_shhWatches[id];
if (!pub || m_ids.count(pub))
for (h256 const& h: face()->watchMessages(_id))
for (h256 const& h: face()->watchMessages(id))
{
auto e = face()->envelope(h);
shh::Message m;
if (pub)
{
cwarn << "Silently decrypting message from identity" << pub.abridged() << ": User validation hook goes here.";
m = e.open(face()->fullTopic(_id), m_ids[pub]);
m = e.open(face()->fullTopic(id), m_ids[pub]);
}
else
m = e.open(face()->fullTopic(_id));
m = e.open(face()->fullTopic(id));
if (!m)
continue;
ret.append(toJson(h, e, m));
@ -912,20 +1088,6 @@ Json::Value WebThreeStubServerBase::shh_getMessages(int _id)
return ret;
}
int WebThreeStubServerBase::shh_newFilter(Json::Value const& _json)
{
auto w = toWatch(_json);
auto ret = face()->installWatch(w.first);
m_shhWatches.insert(make_pair(ret, w.second));
return ret;
}
bool WebThreeStubServerBase::shh_uninstallFilter(int _id)
{
face()->uninstallWatch(_id);
return true;
}
void WebThreeStubServerBase::authenticate(TransactionSkeleton const& _t, bool _toProxy)
{
if (_toProxy)
@ -936,12 +1098,6 @@ void WebThreeStubServerBase::authenticate(TransactionSkeleton const& _t, bool _t
client()->transact(m_accounts->secretKey(_t.from), _t.value, _t.data, _t.gas, _t.gasPrice);
}
bool WebThreeStubServerBase::eth_uninstallFilter(int _id)
{
client()->uninstallWatch(_id);
return true;
}
void WebThreeStubServerBase::setAccounts(const std::vector<KeyPair>& _accounts)
{
m_accounts->setAccounts(_accounts);

51
libweb3jsonrpc/WebThreeStubServerBase.h

@ -100,41 +100,32 @@ public:
virtual std::string eth_compileLLL(std::string const& _s);
virtual std::string eth_compileSerpent(std::string const& _s);
virtual std::string eth_compileSolidity(std::string const& _code);
virtual Json::Value eth_changed(int _id);
virtual Json::Value eth_filterLogs(int _id);
virtual Json::Value eth_logs(Json::Value const& _json);
virtual int eth_newFilter(Json::Value const& _json);
virtual int eth_newFilterString(std::string const& _filter);
virtual bool eth_uninstallFilter(int _id);
virtual std::string eth_newFilter(Json::Value const& _json);
virtual std::string eth_newBlockFilter(std::string const& _filter);
virtual bool eth_uninstallFilter(std::string const& _filterId);
virtual Json::Value eth_getFilterChanges(std::string const& _filterId);
virtual Json::Value eth_getFilterLogs(std::string const& _filterId);
virtual Json::Value eth_getLogs(Json::Value const& _json);
virtual Json::Value eth_getWork();
virtual bool eth_submitWork(std::string const& _nonce);
virtual int eth_register(std::string const& _address);
virtual bool eth_unregister(int _id);
virtual Json::Value eth_queuedTransactions(int _id);
virtual std::string db_get(std::string const& _name, std::string const& _key);
virtual std::string db_getString(std::string const& _name, std::string const& _key);
virtual std::string eth_register(std::string const& _address);
virtual bool eth_unregister(std::string const& _accountId);
virtual Json::Value eth_queuedTransactions(std::string const& _accountId);
virtual bool db_put(std::string const& _name, std::string const& _key, std::string const& _value);
virtual bool db_putString(std::string const& _name, std::string const& _key, std::string const& _value);
virtual std::string db_get(std::string const& _name, std::string const& _key);
virtual std::string shh_addToGroup(std::string const& _group, std::string const& _who);
virtual Json::Value shh_changed(int _id);
virtual Json::Value shh_getMessages(int _id);
virtual bool shh_haveIdentity(std::string const& _id);
virtual int shh_newFilter(Json::Value const& _json);
virtual std::string shh_newGroup(std::string const& _id, std::string const& _who);
virtual std::string shh_newIdentity();
virtual bool shh_post(Json::Value const& _json);
virtual bool shh_uninstallFilter(int _id);
virtual std::string shh_newIdentity();
virtual bool shh_hasIdentity(std::string const& _identity);
virtual std::string shh_newGroup(std::string const& _id, std::string const& _who);
virtual std::string shh_addToGroup(std::string const& _group, std::string const& _who);
virtual std::string shh_newFilter(Json::Value const& _json);
virtual bool shh_uninstallFilter(std::string const& _filterId);
virtual Json::Value shh_changed(std::string const& _filterId);
virtual Json::Value shh_getMessages(std::string const& _filterId);
void setAccounts(std::vector<dev::KeyPair> const& _accounts);
void setIdentities(std::vector<dev::KeyPair> const& _ids);
std::map<dev::Public, dev::Secret> const& ids() const { return m_ids; }

100
libweb3jsonrpc/abstractwebthreestubserver.h

@ -43,30 +43,28 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
this->bindAndAddMethod(jsonrpc::Procedure("eth_compileLLL", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_compileLLLI);
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_newFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_newFilterI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_newFilterString", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_newFilterStringI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_uninstallFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_uninstallFilterI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_changed", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_changedI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_filterLogs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_filterLogsI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_logs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_logsI);
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_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_getFilterChanges", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getFilterChangesI);
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_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_submitWork", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_submitWorkI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_register", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_registerI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_unregister", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_unregisterI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_queuedTransactions", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::eth_queuedTransactionsI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_register", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_registerI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_unregister", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_unregisterI);
this->bindAndAddMethod(jsonrpc::Procedure("eth_queuedTransactions", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_queuedTransactionsI);
this->bindAndAddMethod(jsonrpc::Procedure("db_put", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING,"param3",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::db_putI);
this->bindAndAddMethod(jsonrpc::Procedure("db_get", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::db_getI);
this->bindAndAddMethod(jsonrpc::Procedure("db_putString", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING,"param3",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::db_putStringI);
this->bindAndAddMethod(jsonrpc::Procedure("db_getString", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::db_getStringI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_post", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::shh_postI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_newIdentity", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::shh_newIdentityI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_haveIdentity", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::shh_haveIdentityI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_hasIdentity", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::shh_hasIdentityI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_newGroup", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::shh_newGroupI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_addToGroup", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::shh_addToGroupI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_newFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::shh_newFilterI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_uninstallFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::shh_uninstallFilterI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_changed", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::shh_changedI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_getMessages", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_INTEGER, NULL), &AbstractWebThreeStubServer::shh_getMessagesI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_newFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::shh_newFilterI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_uninstallFilter", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::shh_uninstallFilterI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_changed", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::shh_changedI);
this->bindAndAddMethod(jsonrpc::Procedure("shh_getMessages", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::shh_getMessagesI);
}
inline virtual void web3_sha3I(const Json::Value &request, Json::Value &response)
@ -206,25 +204,25 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
{
response = this->eth_newFilter(request[0u]);
}
inline virtual void eth_newFilterStringI(const Json::Value &request, Json::Value &response)
inline virtual void eth_newBlockFilterI(const Json::Value &request, Json::Value &response)
{
response = this->eth_newFilterString(request[0u].asString());
response = this->eth_newBlockFilter(request[0u].asString());
}
inline virtual void eth_uninstallFilterI(const Json::Value &request, Json::Value &response)
{
response = this->eth_uninstallFilter(request[0u].asInt());
response = this->eth_uninstallFilter(request[0u].asString());
}
inline virtual void eth_changedI(const Json::Value &request, Json::Value &response)
inline virtual void eth_getFilterChangesI(const Json::Value &request, Json::Value &response)
{
response = this->eth_changed(request[0u].asInt());
response = this->eth_getFilterChanges(request[0u].asString());
}
inline virtual void eth_filterLogsI(const Json::Value &request, Json::Value &response)
inline virtual void eth_getFilterLogsI(const Json::Value &request, Json::Value &response)
{
response = this->eth_filterLogs(request[0u].asInt());
response = this->eth_getFilterLogs(request[0u].asString());
}
inline virtual void eth_logsI(const Json::Value &request, Json::Value &response)
inline virtual void eth_getLogsI(const Json::Value &request, Json::Value &response)
{
response = this->eth_logs(request[0u]);
response = this->eth_getLogs(request[0u]);
}
inline virtual void eth_getWorkI(const Json::Value &request, Json::Value &response)
{
@ -241,11 +239,11 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
}
inline virtual void eth_unregisterI(const Json::Value &request, Json::Value &response)
{
response = this->eth_unregister(request[0u].asInt());
response = this->eth_unregister(request[0u].asString());
}
inline virtual void eth_queuedTransactionsI(const Json::Value &request, Json::Value &response)
{
response = this->eth_queuedTransactions(request[0u].asInt());
response = this->eth_queuedTransactions(request[0u].asString());
}
inline virtual void db_putI(const Json::Value &request, Json::Value &response)
{
@ -255,14 +253,6 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
{
response = this->db_get(request[0u].asString(), request[1u].asString());
}
inline virtual void db_putStringI(const Json::Value &request, Json::Value &response)
{
response = this->db_putString(request[0u].asString(), request[1u].asString(), request[2u].asString());
}
inline virtual void db_getStringI(const Json::Value &request, Json::Value &response)
{
response = this->db_getString(request[0u].asString(), request[1u].asString());
}
inline virtual void shh_postI(const Json::Value &request, Json::Value &response)
{
response = this->shh_post(request[0u]);
@ -272,9 +262,9 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
(void)request;
response = this->shh_newIdentity();
}
inline virtual void shh_haveIdentityI(const Json::Value &request, Json::Value &response)
inline virtual void shh_hasIdentityI(const Json::Value &request, Json::Value &response)
{
response = this->shh_haveIdentity(request[0u].asString());
response = this->shh_hasIdentity(request[0u].asString());
}
inline virtual void shh_newGroupI(const Json::Value &request, Json::Value &response)
{
@ -290,15 +280,15 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
}
inline virtual void shh_uninstallFilterI(const Json::Value &request, Json::Value &response)
{
response = this->shh_uninstallFilter(request[0u].asInt());
response = this->shh_uninstallFilter(request[0u].asString());
}
inline virtual void shh_changedI(const Json::Value &request, Json::Value &response)
{
response = this->shh_changed(request[0u].asInt());
response = this->shh_changed(request[0u].asString());
}
inline virtual void shh_getMessagesI(const Json::Value &request, Json::Value &response)
{
response = this->shh_getMessages(request[0u].asInt());
response = this->shh_getMessages(request[0u].asString());
}
virtual std::string web3_sha3(const std::string& param1) = 0;
virtual std::string net_peerCount() = 0;
@ -331,30 +321,28 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
virtual std::string eth_compileLLL(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 int eth_newFilter(const Json::Value& param1) = 0;
virtual int eth_newFilterString(const std::string& param1) = 0;
virtual bool eth_uninstallFilter(int param1) = 0;
virtual Json::Value eth_changed(int param1) = 0;
virtual Json::Value eth_filterLogs(int param1) = 0;
virtual Json::Value eth_logs(const Json::Value& param1) = 0;
virtual std::string eth_newFilter(const Json::Value& param1) = 0;
virtual std::string eth_newBlockFilter(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_getFilterLogs(const std::string& param1) = 0;
virtual Json::Value eth_getLogs(const Json::Value& param1) = 0;
virtual Json::Value eth_getWork() = 0;
virtual bool eth_submitWork(const std::string& param1) = 0;
virtual int eth_register(const std::string& param1) = 0;
virtual bool eth_unregister(int param1) = 0;
virtual Json::Value eth_queuedTransactions(int param1) = 0;
virtual std::string eth_register(const std::string& param1) = 0;
virtual bool eth_unregister(const std::string& param1) = 0;
virtual Json::Value eth_queuedTransactions(const std::string& param1) = 0;
virtual bool db_put(const std::string& param1, const std::string& param2, const std::string& param3) = 0;
virtual std::string db_get(const std::string& param1, const std::string& param2) = 0;
virtual bool db_putString(const std::string& param1, const std::string& param2, const std::string& param3) = 0;
virtual std::string db_getString(const std::string& param1, const std::string& param2) = 0;
virtual bool shh_post(const Json::Value& param1) = 0;
virtual std::string shh_newIdentity() = 0;
virtual bool shh_haveIdentity(const std::string& param1) = 0;
virtual bool shh_hasIdentity(const std::string& param1) = 0;
virtual std::string shh_newGroup(const std::string& param1, const std::string& param2) = 0;
virtual std::string shh_addToGroup(const std::string& param1, const std::string& param2) = 0;
virtual int shh_newFilter(const Json::Value& param1) = 0;
virtual bool shh_uninstallFilter(int param1) = 0;
virtual Json::Value shh_changed(int param1) = 0;
virtual Json::Value shh_getMessages(int param1) = 0;
virtual std::string shh_newFilter(const Json::Value& param1) = 0;
virtual bool shh_uninstallFilter(const std::string& param1) = 0;
virtual Json::Value shh_changed(const std::string& param1) = 0;
virtual Json::Value shh_getMessages(const std::string& param1) = 0;
};
#endif //JSONRPC_CPP_STUB_ABSTRACTWEBTHREESTUBSERVER_H_

35
libweb3jsonrpc/spec.json

@ -32,36 +32,29 @@
{ "name": "eth_compileLLL", "params": [""], "order": [], "returns": ""},
{ "name": "eth_compileSerpent", "params": [""], "order": [], "returns": ""},
{ "name": "eth_compileSolidity", "params": [""], "order": [], "returns": ""},
{ "name": "eth_newFilter", "params": [{}], "order": [], "returns": 0},
{ "name": "eth_newFilterString", "params": [""], "order": [], "returns": 0},
{ "name": "eth_uninstallFilter", "params": [0], "order": [], "returns": true},
{ "name": "eth_changed", "params": [0], "order": [], "returns": []},
{ "name": "eth_filterLogs", "params": [0], "order": [], "returns": []},
{ "name": "eth_logs", "params": [{}], "order": [], "returns": []},
{ "name": "eth_newFilter", "params": [{}], "order": [], "returns": ""},
{ "name": "eth_newBlockFilter", "params": [""], "order": [], "returns": ""},
{ "name": "eth_uninstallFilter", "params": [""], "order": [], "returns": true},
{ "name": "eth_getFilterChanges", "params": [""], "order": [], "returns": []},
{ "name": "eth_getFilterLogs", "params": [""], "order": [], "returns": []},
{ "name": "eth_getLogs", "params": [{}], "order": [], "returns": []},
{ "name": "eth_getWork", "params": [], "order": [], "returns": []},
{ "name": "eth_submitWork", "params": [""], "order": [], "returns": true},
{ "name": "eth_register", "params": [""], "order": [], "returns": 0},
{ "name": "eth_unregister", "params": [0], "order": [], "returns": true},
{ "name": "eth_queuedTransactions", "params": [0], "order": [], "returns": []},
{ "name": "eth_register", "params": [""], "order": [], "returns": ""},
{ "name": "eth_unregister", "params": [""], "order": [], "returns": true},
{ "name": "eth_queuedTransactions", "params": [""], "order": [], "returns": []},
{ "name": "db_put", "params": ["", "", ""], "order": [], "returns": true},
{ "name": "db_get", "params": ["", ""], "order": [], "returns": ""},
{ "name": "db_putString", "params": ["", "", ""], "order": [], "returns": true},
{ "name": "db_getString", "params": ["", ""], "order": [], "returns": ""},
{ "name": "shh_post", "params": [{}], "order": [], "returns": true},
{ "name": "shh_newIdentity", "params": [], "order": [], "returns": ""},
{ "name": "shh_haveIdentity", "params": [""], "order": [], "returns": false},
{ "name": "shh_hasIdentity", "params": [""], "order": [], "returns": false},
{ "name": "shh_newGroup", "params": ["", ""], "order": [], "returns": ""},
{ "name": "shh_addToGroup", "params": ["", ""], "order": [], "returns": ""},
{ "name": "shh_newFilter", "params": [{}], "order": [], "returns": 0},
{ "name": "shh_uninstallFilter", "params": [0], "order": [], "returns": true},
{ "name": "shh_changed", "params": [0], "order": [], "returns": []},
{ "name": "shh_getMessages", "params": [0], "order": [], "returns": []}
{ "name": "shh_newFilter", "params": [{}], "order": [], "returns": ""},
{ "name": "shh_uninstallFilter", "params": [""], "order": [], "returns": true},
{ "name": "shh_changed", "params": [""], "order": [], "returns": []},
{ "name": "shh_getMessages", "params": [""], "order": [], "returns": []}
]

77
test/webthreestubclient.h

@ -332,27 +332,27 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
int eth_newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
std::string eth_newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_newFilter",p);
if (result.isInt())
return result.asInt();
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
int eth_newFilterString(const std::string& param1) throw (jsonrpc::JsonRpcException)
std::string eth_newBlockFilter(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_newFilterString",p);
if (result.isInt())
return result.asInt();
Json::Value result = this->CallMethod("eth_newBlockFilter",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool eth_uninstallFilter(int param1) throw (jsonrpc::JsonRpcException)
bool eth_uninstallFilter(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
@ -362,31 +362,31 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value eth_changed(int param1) throw (jsonrpc::JsonRpcException)
Json::Value eth_getFilterChanges(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_changed",p);
Json::Value result = this->CallMethod("eth_getFilterChanges",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value eth_filterLogs(int param1) throw (jsonrpc::JsonRpcException)
Json::Value eth_getFilterLogs(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_filterLogs",p);
Json::Value result = this->CallMethod("eth_getFilterLogs",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value eth_logs(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
Json::Value eth_getLogs(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_logs",p);
Json::Value result = this->CallMethod("eth_getLogs",p);
if (result.isArray())
return result;
else
@ -412,17 +412,17 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
int eth_register(const std::string& param1) throw (jsonrpc::JsonRpcException)
std::string eth_register(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_register",p);
if (result.isInt())
return result.asInt();
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool eth_unregister(int param1) throw (jsonrpc::JsonRpcException)
bool eth_unregister(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
@ -432,7 +432,7 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value eth_queuedTransactions(int param1) throw (jsonrpc::JsonRpcException)
Json::Value eth_queuedTransactions(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
@ -465,29 +465,6 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool db_putString(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
p.append(param2);
p.append(param3);
Json::Value result = this->CallMethod("db_putString",p);
if (result.isBool())
return result.asBool();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
std::string db_getString(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
p.append(param2);
Json::Value result = this->CallMethod("db_getString",p);
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool shh_post(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
@ -508,11 +485,11 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool shh_haveIdentity(const std::string& param1) throw (jsonrpc::JsonRpcException)
bool shh_hasIdentity(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("shh_haveIdentity",p);
Json::Value result = this->CallMethod("shh_hasIdentity",p);
if (result.isBool())
return result.asBool();
else
@ -540,17 +517,17 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
int shh_newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
std::string shh_newFilter(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("shh_newFilter",p);
if (result.isInt())
return result.asInt();
if (result.isString())
return result.asString();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
bool shh_uninstallFilter(int param1) throw (jsonrpc::JsonRpcException)
bool shh_uninstallFilter(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
@ -560,7 +537,7 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value shh_changed(int param1) throw (jsonrpc::JsonRpcException)
Json::Value shh_changed(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
@ -570,7 +547,7 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value shh_getMessages(int param1) throw (jsonrpc::JsonRpcException)
Json::Value shh_getMessages(const std::string& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);

Loading…
Cancel
Save