Revert "Problem: No need to store different types of elections in their own tables"

This reverts commit db45374d3c690429d18a25bcc319f8056c016500.
This commit is contained in:
z-bowen 2018-09-04 10:55:23 +02:00
parent db45374d3c
commit bd76b31e40
5 changed files with 9 additions and 6 deletions

View File

@ -300,11 +300,11 @@ def get_validator_set(conn, height=None):
@register_query(LocalMongoDBConnection) @register_query(LocalMongoDBConnection)
def get_election_result_by_id(conn, election_id): def get_election_result_by_id(conn, election_id, table):
query = {'election_id': election_id} query = {'election_id': election_id}
cursor = conn.run( cursor = conn.run(
conn.collection('validators') conn.collection(table)
.find(query, projection={'_id': False}) .find(query, projection={'_id': False})
) )

View File

@ -361,7 +361,7 @@ def get_validator_set(conn, height):
@singledispatch @singledispatch
def get_election_result_by_id(conn, election_id): def get_election_result_by_id(conn, election_id, table):
"""Return a validator set change with the specified election_id """Return a validator set change with the specified election_id
""" """

View File

@ -23,6 +23,8 @@ 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,)
ELECTION_TYPE = None ELECTION_TYPE = None
# the name of the mongodb table managed by the election
DB_TABLE = None
# the model for votes issued by the election # the model for votes issued by the election
VOTE_TYPE = None VOTE_TYPE = None
# Election Statuses: # Election Statuses:
@ -219,7 +221,7 @@ class Election(Transaction):
return self.ONGOING return self.ONGOING
def get_election_result(self, election_id, bigchain): def get_election_result(self, election_id, bigchain):
result = bigchain.get_election_result_by_id(election_id) result = bigchain.get_election_result_by_id(election_id, self.DB_TABLE)
return result return result
@classmethod @classmethod

View File

@ -429,8 +429,8 @@ class BigchainDB(object):
validators = result['validators'] validators = result['validators']
return validators return validators
def get_election_result_by_id(self, election_id): def get_result_by_election_id(self, election_id, table):
result = backend.query.get_election_result_by_id(self.connection, election_id) result = backend.query.get_election_result_by_id(self.connection, election_id, table)
return result return result
def store_pre_commit_state(self, state): def store_pre_commit_state(self, state):

View File

@ -17,6 +17,7 @@ class ValidatorElection(Election):
# by renaming CREATE to VALIDATOR_ELECTION # by renaming CREATE to VALIDATOR_ELECTION
CREATE = ELECTION_TYPE CREATE = ELECTION_TYPE
ALLOWED_OPERATIONS = (ELECTION_TYPE,) ALLOWED_OPERATIONS = (ELECTION_TYPE,)
DB_TABLE = 'validators'
VOTE_TYPE = ValidatorElectionVote VOTE_TYPE = ValidatorElectionVote
def validate(self, bigchain, current_transactions=[]): def validate(self, bigchain, current_transactions=[]):