mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
voting schema validate
This commit is contained in:
parent
fdad8cd796
commit
c68856bc43
@ -32,7 +32,7 @@ class Voting:
|
|||||||
eligible_votes, ineligible_votes = \
|
eligible_votes, ineligible_votes = \
|
||||||
cls.partition_eligible_votes(votes, eligible_voters)
|
cls.partition_eligible_votes(votes, eligible_voters)
|
||||||
results = cls.count_votes(eligible_votes)
|
results = cls.count_votes(eligible_votes)
|
||||||
results['status'] = decide_votes(results['counts'])
|
results['status'] = cls.decide_votes(results['counts'])
|
||||||
results['ineligible'] = ineligible_votes
|
results['ineligible'] = ineligible_votes
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@ -46,10 +46,15 @@ class Voting:
|
|||||||
|
|
||||||
for vote in votes:
|
for vote in votes:
|
||||||
voter_eligible = vote.get('node_pubkey') in eligible_voters
|
voter_eligible = vote.get('node_pubkey') in eligible_voters
|
||||||
if voter_eligible and cls.verify_vote_signature(vote):
|
if voter_eligible:
|
||||||
eligible.append(vote)
|
try:
|
||||||
else:
|
cls.verify_vote_signature(vote)
|
||||||
ineligible.append(vote)
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
eligible.append(vote)
|
||||||
|
continue
|
||||||
|
ineligible.append(vote)
|
||||||
|
|
||||||
return eligible, ineligible
|
return eligible, ineligible
|
||||||
|
|
||||||
@ -150,10 +155,10 @@ class Voting:
|
|||||||
pk_base58 = vote.get('node_pubkey')
|
pk_base58 = vote.get('node_pubkey')
|
||||||
|
|
||||||
if not (type(signature) == str and type(pk_base58) == str):
|
if not (type(signature) == str and type(pk_base58) == str):
|
||||||
raise ValueError("Malformed vote: %s" % vote)
|
raise ValueError('Malformed vote: %s' % vote)
|
||||||
|
|
||||||
public_key = PublicKey(pk_base58)
|
public_key = PublicKey(pk_base58)
|
||||||
body = serialize(signed_vote['vote']).encode()
|
body = serialize(vote['vote']).encode()
|
||||||
return public_key.verify(body, signature)
|
return public_key.verify(body, signature)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user