From f8f5ba06e2829334dd13fd7494f1449990556eab Mon Sep 17 00:00:00 2001
From: mtrela <mtrela@syncad.com>
Date: Tue, 18 Aug 2020 15:10:05 +0200
Subject: [PATCH] The call `database_api.list_votes` works

---
 hive/server/database_api/methods.py | 41 +++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/hive/server/database_api/methods.py b/hive/server/database_api/methods.py
index 90384e273..e9d3d991d 100644
--- a/hive/server/database_api/methods.py
+++ b/hive/server/database_api/methods.py
@@ -213,7 +213,7 @@ async def find_votes(context, params: dict, votes_presentation = VotesPresentati
     return ret
 
 @return_error_info
-async def list_votes(context, start: list, limit: int, order: str):
+async def list_votes(context, start: list, limit: int, order: str, votes_presentation = VotesPresentation.DatabaseApi):
     """ Returns all votes, starting with the specified voter and/or author and permlink. """
     supported_order_list = ["by_comment_voter", "by_voter_comment"]
     assert order in supported_order_list, "Order {} is not supported".format(order)
@@ -221,6 +221,8 @@ async def list_votes(context, start: list, limit: int, order: str):
     assert len(start) == 3, "Expecting 3 elements in start array"
     db = context['db']
 
+    ret = []
+
     sql = """
         SELECT
             voter,
@@ -236,31 +238,48 @@ async def list_votes(context, start: list, limit: int, order: str):
             hive_votes_accounts_permlinks_view
     """
 
-    if order == "by_comment_voter": # ABW: wrong! fat node sorted by ( comment_id, voter_id )
+    if order == "by_comment_voter":
         sql += """
             WHERE
                 author >= :author AND 
                 permlink >= :permlink AND 
                 voter >= :voter
             ORDER BY
-                author ASC, 
-                permlink ASC, 
-                id ASC 
+                post_id ASC,
+                voter_id ASC
             LIMIT 
                 :limit
         """
-        return await db.query_all(sql, author=start[0], permlink=start[1], voter=start[2], limit=limit)
-    if order == "by_voter_comment": # ABW: wrong! fat node sorted by ( voter_id, comment_id )
+        rows = await db.query_all(sql, author=start[0], permlink=start[1], voter=start[2], limit=limit)
+
+    if order == "by_voter_comment":
         sql += """
             WHERE
                 voter >= :voter AND 
                 author >= :author AND 
                 permlink >= :permlink
             ORDER BY 
-                voter ASC,
-                id ASC
+                voter_id ASC,
+                post_id ASC
             LIMIT
                 :limit
         """
-        return await db.query_all(sql, author=start[1], permlink=start[2], voter=start[0], limit=limit)
-    return []
+        rows = await db.query_all(sql, author=start[1], permlink=start[2], voter=start[0], limit=limit)
+
+    for row in rows:
+        if votes_presentation == VotesPresentation.DatabaseApi:
+            ret.append(dict(voter=row.voter, author=row.author, permlink=row.permlink,
+                            weight=row.weight, rshares=row.rshares, vote_percent=row.percent,
+                            last_update=str(row.time), num_changes=row.num_changes))
+        elif votes_presentation == VotesPresentation.CondenserApi:
+            ret.append(dict(percent=str(row.percent), reputation=rep_to_raw(row.reputation),
+                            rshares=str(row.rshares), voter=row.voter))
+        elif votes_presentation == VotesPresentation.BridgeApi:
+            ret.append(dict(rshares=str(row.rshares), voter=row.voter))
+        else:
+            ret.append(dict(percent=row.percent, reputation=rep_to_raw(row.reputation),
+                            rshares=number_to_json_value(row.rshares), time=time_string_with_t(row.time), 
+                            voter=row.voter, weight=number_to_json_value(row.weight)
+                            ))
+
+    return ret
-- 
GitLab