From d79569fb634c2d3340530c997c6cb733b949f4c7 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 15 Jun 2015 04:24:50 +0200 Subject: [PATCH] eth_getFilterChangesEx, eth_getFilterLogsEx returns json in proper format --- libweb3jsonrpc/WebThreeStubServerBase.cpp | 54 ++++++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 5bdd98e87..54568672e 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -198,6 +198,56 @@ static Json::Value toJson(dev::eth::LocalisedLogEntry const& _e) return res; } +static Json::Value toJsonEx(dev::eth::LocalisedLogEntries const& _es) +{ + map entriesByBlock; + + for (dev::eth::LocalisedLogEntry const& e: _es) + { + if (e.topics.size() == 0) // skip special log + continue; + + if (entriesByBlock.count(e.blockHash) == 0) + entriesByBlock[e.blockHash] = LocalisedLogEntries(); + + entriesByBlock[e.blockHash].push_back(e); + } + + Json::Value res(Json::arrayValue); + for (auto const& i: entriesByBlock) + { + Json::Value currentBlock(Json::objectValue); + LocalisedLogEntry entry = i.second[0]; + if (entry.mined) + { + + currentBlock["blockNumber"] = entry.blockNumber; + currentBlock["blockHash"] = toJS(entry.blockHash); + currentBlock["type"] = "mined"; + } + else + currentBlock["type"] = "pending"; + + currentBlock["logs"] = Json::Value(Json::arrayValue); + + for (LocalisedLogEntry const& e: i.second) + { + 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); + + currentBlock["logs"].append(log); + } + + res.append(currentBlock); + } +} + static Json::Value toJson(dev::eth::LocalisedLogEntries const& _es) { Json::Value res(Json::arrayValue); @@ -1001,7 +1051,7 @@ Json::Value WebThreeStubServerBase::eth_getFilterChangesEx(string const& _filter auto entries = client()->checkWatch(id); if (entries.size()) cnote << "FIRING WATCH" << id << entries.size(); - return toJson(entries); + return toJsonEx(entries); } catch (...) { @@ -1025,7 +1075,7 @@ Json::Value WebThreeStubServerBase::eth_getFilterLogsEx(string const& _filterId) { try { - return toJson(client()->logs(jsToInt(_filterId))); + return toJsonEx(client()->logs(jsToInt(_filterId))); } catch (...) {