Problem: Election class variable ELECTION_TYPE is overly specific

Solution: Renamed `ELECTION_TYPE` to `OPERATION`
This commit is contained in:
z-bowen 2018-09-05 10:41:05 +02:00
parent 331b52cc4c
commit 0c64fbfb5d
3 changed files with 6 additions and 6 deletions

View File

@ -98,5 +98,5 @@ from bigchaindb.common.vote import Vote # noqa
Transaction.register_type(Transaction.CREATE, models.Transaction)
Transaction.register_type(Transaction.TRANSFER, models.Transaction)
Transaction.register_type(ValidatorElection.ELECTION_TYPE, ValidatorElection)
Transaction.register_type(ValidatorElection.OPERATION, ValidatorElection)
Transaction.register_type(Vote.VOTE, Vote)

View File

@ -23,7 +23,7 @@ class Election(Transaction):
# 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,)
ELECTION_TYPE = None
OPERATION = None
# the model for votes issued by the election
VOTE_TYPE = Vote
# Election Statuses:
@ -132,7 +132,7 @@ class Election(Transaction):
@classmethod
def generate(cls, initiator, voters, election_data, metadata=None):
(inputs, outputs) = cls.validate_create(initiator, voters, election_data, metadata)
election = cls(cls.ELECTION_TYPE, {'data': election_data}, inputs, outputs, metadata)
election = cls(cls.OPERATION, {'data': election_data}, inputs, outputs, metadata)
cls.validate_schema(election.to_dict(), skip_id=True)
return election

View File

@ -11,11 +11,11 @@ from .validator_utils import (new_validator_set, encode_validator)
class ValidatorElection(Election):
ELECTION_TYPE = 'VALIDATOR_ELECTION'
OPERATION = 'VALIDATOR_ELECTION'
# NOTE: this transaction class extends create so the operation inheritence is achieved
# by renaming CREATE to VALIDATOR_ELECTION
CREATE = ELECTION_TYPE
ALLOWED_OPERATIONS = (ELECTION_TYPE,)
CREATE = OPERATION
ALLOWED_OPERATIONS = (OPERATION,)
def validate(self, bigchain, current_transactions=[]):
"""For more details refer BEP-21: https://github.com/bigchaindb/BEPs/tree/master/21