Problem: Election class variable to VOTE_TYPE unnecessary

Solution: Removed the variable and hardcoded everything to use the `Vote` class
This commit is contained in:
z-bowen 2018-09-06 17:16:12 +02:00
parent fdacca7976
commit 2eb32d93f6

View File

@ -24,8 +24,6 @@ class Election(Transaction):
# NOTE: this transaction class extends create so the operation inheritance is achieved # NOTE: this transaction class extends create so the operation inheritance is achieved
# by setting an ELECTION_TYPE and renaming CREATE = ELECTION_TYPE and ALLOWED_OPERATIONS = (ELECTION_TYPE,) # by setting an ELECTION_TYPE and renaming CREATE = ELECTION_TYPE and ALLOWED_OPERATIONS = (ELECTION_TYPE,)
OPERATION = None OPERATION = None
# the model for votes issued by the election
VOTE_TYPE = Vote
# Custom validation schema # Custom validation schema
TX_SCHEMA_CUSTOM = None TX_SCHEMA_CUSTOM = None
# Election Statuses: # Election Statuses:
@ -166,7 +164,7 @@ class Election(Transaction):
def count_votes(cls, election_pk, transactions, getter=getattr): def count_votes(cls, election_pk, transactions, getter=getattr):
votes = 0 votes = 0
for txn in transactions: for txn in transactions:
if getter(txn, 'operation') == cls.VOTE_TYPE.OPERATION: if getter(txn, 'operation') == Vote.OPERATION:
for output in getter(txn, 'outputs'): for output in getter(txn, 'outputs'):
# NOTE: We enforce that a valid vote to election id will have only # NOTE: We enforce that a valid vote to election id will have only
# election_pk in the output public keys, including any other public key # election_pk in the output public keys, including any other public key
@ -232,7 +230,7 @@ class Election(Transaction):
def approved_update(cls, bigchain, new_height, txns): def approved_update(cls, bigchain, new_height, txns):
votes = {} votes = {}
for txn in txns: for txn in txns:
if not isinstance(txn, cls.VOTE_TYPE): if not isinstance(txn, Vote):
continue continue
election_id = txn.asset['id'] election_id = txn.asset['id']