From b36107d1e84dcb5ec049c57eb58b86a15a723ee7 Mon Sep 17 00:00:00 2001
From: Denis Sumin <denis.smolov@demlabs.net>
Date: Tue, 18 Feb 2025 14:22:42 +0000
Subject: [PATCH] Release 3.1 19

---
 chain/wallet/handlers/DapCommandList.cpp      |  2 +-
 .../wallet/handlers/DapVoitingListCommand.cpp | 59 ++++++++++++-------
 2 files changed, 39 insertions(+), 22 deletions(-)

diff --git a/chain/wallet/handlers/DapCommandList.cpp b/chain/wallet/handlers/DapCommandList.cpp
index 32cc2857..07c93eb3 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 47b4aaba..958400b4 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;
-- 
GitLab