diff --git a/chain/wallet/handlers/DapCommandList.cpp b/chain/wallet/handlers/DapCommandList.cpp index 32cc285742927b34ab1ec5759846ed81f21448c6..07c93eb304d92b5eca1c7111450fcc8c2cdcbc4c 100644 --- a/chain/wallet/handlers/DapCommandList.cpp +++ b/chain/wallet/handlers/DapCommandList.cpp @@ -1228,7 +1228,7 @@ QVariant DapCommandList::votingList(const QVariant &args) } auto command = QString("voting list -net %1").arg(params[0]); - return requestToNode(QPair<QString*, QString>(m_cliPath,command)); + return requestToNode(QPair<QString*, QString>(m_cliPath,command),Dap::RequestType::JSON); } QVariant DapCommandList::votingDump(const QVariant &args) diff --git a/chain/wallet/handlers/DapVoitingListCommand.cpp b/chain/wallet/handlers/DapVoitingListCommand.cpp index 47b4aaba1274a2f9e75d4f4dfd1c97694b3eafbf..958400b4ad1f44e8e94b31ec86616d4f1390d0ef 100644 --- a/chain/wallet/handlers/DapVoitingListCommand.cpp +++ b/chain/wallet/handlers/DapVoitingListCommand.cpp @@ -9,36 +9,53 @@ DapVoitingListCommand::DapVoitingListCommand(const QString &asServicename, QObje QVariant DapVoitingListCommand::respondToClient(const QVariant &args) { DapAbstractCommand::respondToClient(args); - auto result = cmdList->votingList(args).toString(); + auto result = cmdList->votingList(args); + QJsonObject reply = result.toJsonObject(); + QJsonObject resultObject; - if(result.isEmpty()) + if(reply.isEmpty()) { - resultObject.insert(ERROR_KEY, "Error. Noda gave an empty answer."); - } + resultObject.insert(ERROR_KEY, "Error. Node gave an empty answer."); + addWeb3Result(resultObject, args); - QRegularExpression regular( - R"(\n*voting_tx: (.+)\n+\s+question: \"(.+)\"\n+\s*\n*)", QRegularExpression::MultilineOption); - QRegularExpressionMatchIterator matchItr = regular.globalMatch(result); + QJsonDocument resultDoc; + resultDoc.setObject(resultObject); + return resultDoc.toJson(); + } + if(reply.contains("errors")) + { + resultObject.insert(ERROR_KEY, reply["errors"].toString()); + addWeb3Result(resultObject, args); - if(matchItr.hasNext()) + QJsonDocument resultDoc; + resultDoc.setObject(resultObject); + return resultDoc.toJson(); + } + if(!reply["result"].isArray() || !reply["result"].toArray().first().isArray()) { - QJsonArray resultArray; - while (matchItr.hasNext()) - { - QRegularExpressionMatch match = matchItr.next(); - - QJsonObject object; - object.insert("hash", match.captured(1).simplified()); - object.insert("question", match.captured(2).simplified()); - resultArray.append(std::move(object)); - } - resultObject.insert(RESULT_KEY, std::move(resultArray)); + resultObject.insert(ERROR_KEY, "Error. Answer is does't array."); + addWeb3Result(resultObject, args); + + QJsonDocument resultDoc; + resultDoc.setObject(resultObject); + return resultDoc.toJson(); } - else + + QJsonArray voteArray = reply["result"].toArray().first().toArray(); + + QJsonArray resultArray; + + for(auto item: voteArray) { - resultObject.insert(ERROR_KEY, result); + QJsonObject vote = item.toObject(); + + QJsonObject object; + object.insert("hash", vote["voting_tx"].toString()); + object.insert("question", vote["question"].toString()); + resultArray.append(std::move(object)); } + resultObject.insert(RESULT_KEY, std::move(resultArray)); addWeb3Result(resultObject, args); QJsonDocument resultDoc;