From b62e74be2b62f43e4700340e5a1854865cd2a3f2 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 23 Oct 2014 12:40:36 +0200 Subject: [PATCH] propert format of response --- libqethereum/QEthereum.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libqethereum/QEthereum.cpp b/libqethereum/QEthereum.cpp index a9b6a32ef..c81ec2dfb 100644 --- a/libqethereum/QEthereum.cpp +++ b/libqethereum/QEthereum.cpp @@ -51,6 +51,18 @@ static QString toJsonRpcMessage(QString _json) return QString::fromUtf8(QJsonDocument(res).toJson()); } +static QString formatResponse(QString _json) +{ + QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object(); + QJsonObject res; + if (f.contains("id")) + res["_id"] = f["id"]; + if (f.contains("result")) + res["data"] = f["result"]; + + return QString::fromUtf8(QJsonDocument(res).toJson()); +} + void QWebThree::postData(QString _json) { emit processData(toJsonRpcMessage(_json)); @@ -80,7 +92,7 @@ bool QWebThreeConnector::StopListening() bool QWebThreeConnector::SendResponse(std::string const& _response, void* _addInfo) { Q_UNUSED(_addInfo); - emit m_qweb->send(QString::fromStdString(_response)); + emit m_qweb->send(formatResponse(QString::fromStdString(_response))); return true; }