mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
voting cleanup
This commit is contained in:
parent
6a10127268
commit
6ab1089bda
@ -12,14 +12,14 @@ UNDECIDED = 'undecided'
|
|||||||
|
|
||||||
class Voting:
|
class Voting:
|
||||||
"""
|
"""
|
||||||
Everything to do with creating and checking votes.
|
Everything to do with verifying and counting votes for block election.
|
||||||
|
|
||||||
All functions in this class should be referentially transparent, that is,
|
All functions in this class should be referentially transparent, that is,
|
||||||
they always give the same output for a given input. This makes it easier
|
they always give the same output for a given input. This makes it easier
|
||||||
to test. This also means no logging!
|
to test. This also means no logging!
|
||||||
|
|
||||||
Assumptions regarding data:
|
Assumptions regarding data:
|
||||||
* Vote is a dictionary, but it is not assumed that any properties are.
|
* Vote is a dictionary, but no assumptions are made on it's properties.
|
||||||
* Everything else is assumed to be structurally correct, otherwise errors
|
* Everything else is assumed to be structurally correct, otherwise errors
|
||||||
may be thrown.
|
may be thrown.
|
||||||
"""
|
"""
|
||||||
@ -30,9 +30,9 @@ class Voting:
|
|||||||
Calculate the election status of a block.
|
Calculate the election status of a block.
|
||||||
"""
|
"""
|
||||||
eligible_voters = set(block['block']['voters']) & set(keyring)
|
eligible_voters = set(block['block']['voters']) & set(keyring)
|
||||||
|
n_voters = len(eligible_voters)
|
||||||
eligible_votes, ineligible_votes = \
|
eligible_votes, ineligible_votes = \
|
||||||
cls.partition_eligible_votes(votes, eligible_voters)
|
cls.partition_eligible_votes(votes, eligible_voters)
|
||||||
n_voters = len(eligible_voters)
|
|
||||||
results = cls.count_votes(eligible_votes)
|
results = cls.count_votes(eligible_votes)
|
||||||
results['block_id'] = block['id']
|
results['block_id'] = block['id']
|
||||||
results['status'] = cls.decide_votes(n_voters, **results['counts'])
|
results['status'] = cls.decide_votes(n_voters, **results['counts'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user