Browse Source

getLogsEx && propert order of returned Ex logs

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
2ff5f57355
  1. 23
      libweb3jsonrpc/JsonHelper.cpp
  2. 2
      libweb3jsonrpc/JsonHelper.h
  3. 14
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  4. 1
      libweb3jsonrpc/WebThreeStubServerBase.h
  5. 6
      libweb3jsonrpc/abstractwebthreestubserver.h
  6. 1
      libweb3jsonrpc/spec.json
  7. 10
      test/libweb3jsonrpc/webthreestubclient.h

23
libweb3jsonrpc/JsonHelper.cpp

@ -277,13 +277,14 @@ Json::Value toJson(dev::eth::LogEntry const& _e)
return res;
}
Json::Value toJson(std::map<h256, dev::eth::LocalisedLogEntries> const& _entriesByBlock)
Json::Value toJson(std::unordered_map<h256, dev::eth::LocalisedLogEntries> const& _entriesByBlock, vector<h256> const& _order)
{
Json::Value res(Json::arrayValue);
for (auto const& i: _entriesByBlock)
for (auto const& i: _order)
{
auto entries = _entriesByBlock.at(i);
Json::Value currentBlock(Json::objectValue);
LocalisedLogEntry entry = i.second[0];
LocalisedLogEntry entry = entries[0];
if (entry.mined)
{
@ -294,18 +295,20 @@ Json::Value toJson(std::map<h256, dev::eth::LocalisedLogEntries> const& _entries
else
currentBlock["type"] = "pending";
currentBlock["polarity"] = entry.polarity == BlockPolarity::Live ? true : false;
currentBlock["logs"] = Json::Value(Json::arrayValue);
for (LocalisedLogEntry const& e: i.second)
for (LocalisedLogEntry const& e: entries)
{
Json::Value log(Json::objectValue);
log["logIndex"] = e.logIndex;
log["polarity"] = e.polarity == BlockPolarity::Live ? true : false;
log["transactionIndex"] = e.transactionIndex;
log["transactionHash"] = toJS(e.transactionHash);
log["address"] = toJS(e.address);
log["data"] = toJS(e.data);
log["topics"] = toJS(e.topics);
log["topics"] = Json::Value(Json::arrayValue);
for (auto const& t: e.topics)
log["topics"].append(toJS(t));
currentBlock["logs"].append(log);
}
@ -318,7 +321,8 @@ Json::Value toJson(std::map<h256, dev::eth::LocalisedLogEntries> const& _entries
Json::Value toJsonByBlock(LocalisedLogEntries const& _entries)
{
map <h256, LocalisedLogEntries> entriesByBlock;
vector<h256> order;
unordered_map <h256, LocalisedLogEntries> entriesByBlock;
for (dev::eth::LocalisedLogEntry const& e: _entries)
{
@ -326,12 +330,15 @@ Json::Value toJsonByBlock(LocalisedLogEntries const& _entries)
continue;
if (entriesByBlock.count(e.blockHash) == 0)
{
entriesByBlock[e.blockHash] = LocalisedLogEntries();
order.push_back(e.blockHash);
}
entriesByBlock[e.blockHash].push_back(e);
}
return toJson(entriesByBlock);
return toJson(entriesByBlock, order);
}
TransactionSkeleton toTransactionSkeleton(Json::Value const& _json)

2
libweb3jsonrpc/JsonHelper.h

@ -62,7 +62,7 @@ Json::Value toJson(TransactionReceipt const& _t);
Json::Value toJson(LocalisedTransactionReceipt const& _t);
Json::Value toJson(LocalisedLogEntry const& _e);
Json::Value toJson(LogEntry const& _e);
Json::Value toJson(std::map<h256, LocalisedLogEntries> const& _entriesByBlock);
Json::Value toJson(std::unordered_map<h256, LocalisedLogEntries> const& _entriesByBlock);
Json::Value toJsonByBlock(LocalisedLogEntries const& _entries);
TransactionSkeleton toTransactionSkeleton(Json::Value const& _json);
LogFilter toLogFilter(Json::Value const& _json);

14
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -725,7 +725,19 @@ Json::Value WebThreeStubServerBase::eth_getLogs(Json::Value const& _json)
{
try
{
return toJson(client()->logs(toLogFilter(_json)));
return toJson(client()->logs(toLogFilter(_json, *client())));
}
catch (...)
{
BOOST_THROW_EXCEPTION(JsonRpcException(Errors::ERROR_RPC_INVALID_PARAMS));
}
}
Json::Value WebThreeStubServerBase::eth_getLogsEx(Json::Value const& _json)
{
try
{
return toJsonByBlock(client()->logs(toLogFilter(_json)));
}
catch (...)
{

1
libweb3jsonrpc/WebThreeStubServerBase.h

@ -136,6 +136,7 @@ public:
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_getLogsEx(Json::Value const& _json);
virtual Json::Value eth_getWork();
virtual bool eth_submitWork(std::string const& _nonce, std::string const&, std::string const& _mixHash);
virtual std::string eth_register(std::string const& _address);

6
libweb3jsonrpc/abstractwebthreestubserver.h

@ -57,6 +57,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
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_getLogsEx", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_getLogsExI);
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_register", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_registerI);
@ -296,6 +297,10 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
{
response = this->eth_getLogs(request[0u]);
}
inline virtual void eth_getLogsExI(const Json::Value &request, Json::Value &response)
{
response = this->eth_getLogsEx(request[0u]);
}
inline virtual void eth_getWorkI(const Json::Value &request, Json::Value &response)
{
(void)request;
@ -511,6 +516,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServer<AbstractWebThr
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_getLogsEx(const Json::Value& param1) = 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 std::string eth_register(const std::string& param1) = 0;

1
libweb3jsonrpc/spec.json

@ -46,6 +46,7 @@
{ "name": "eth_getFilterLogs", "params": [""], "order": [], "returns": []},
{ "name": "eth_getFilterLogsEx", "params": [""], "order": [], "returns": []},
{ "name": "eth_getLogs", "params": [{}], "order": [], "returns": []},
{ "name": "eth_getLogsEx", "params": [{}], "order": [], "returns": []},
{ "name": "eth_getWork", "params": [], "order": [], "returns": []},
{ "name": "eth_submitWork", "params": ["", "", ""], "order": [], "returns": true},
{ "name": "eth_register", "params": [""], "order": [], "returns": ""},

10
test/libweb3jsonrpc/webthreestubclient.h

@ -474,6 +474,16 @@ class WebThreeStubClient : public jsonrpc::Client
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value eth_getLogsEx(const Json::Value& param1) throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p.append(param1);
Json::Value result = this->CallMethod("eth_getLogsEx",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
Json::Value eth_getWork() throw (jsonrpc::JsonRpcException)
{
Json::Value p;

Loading…
Cancel
Save