This is an automated email from the ASF dual-hosted git repository. gstein pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/steve.git
commit 06daa222a080c2530b22621c533236e10d3cbb6b Author: Greg Stein <[email protected]> AuthorDate: Mon May 30 19:54:12 2022 -0500 gather votes for an issue, to tally --- v3/steve/election.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/v3/steve/election.py b/v3/steve/election.py index 2cc5b93..accfed5 100644 --- a/v3/steve/election.py +++ b/v3/steve/election.py @@ -73,6 +73,8 @@ class Election: 'SELECT * FROM ISSUES WHERE iid = ?') self.q_get_record = self.db.add_query('record', 'SELECT * FROM RECORD WHERE rid = ?') + self.q_by_issue = self.db.add_query('votes', + 'SELECT * FROM VOTES WHERE issue_token = ?') def open(self): @@ -208,6 +210,25 @@ class Election: #print('TOKEN:', token) self.c_add_vote.perform((voter_token, issue_token, salt, token)) + def gather_issue_votes(self, iid): + md = self.q_metadata.first_row() + issue = self.q_get_issue.first_row((iid,)) + issue_token = crypto.gen_token(md.opened_key, iid, issue.salt) + + # Use this dict to retain "most recent" votes. + dedup = { } # (VOTER_TOKEN, ISSUE_TOKEN) : VOTESTRING + + self.q_by_issue.perform((issue_token,)) + for row in self.q_by_issue.fetchall(): + votestring = crypto.decrypt_votestring( + row.voter_token, issue_token, row.salt, row.token) + dedup[row.voter_token, row.issue_token] = votestring + + # Make sure the votes are not in database-order. + votes = list(dedup.values()) + crypto.shuffle(votes) # in-place + return votes + def is_tampered(self): # The Election should be open.
