diff --git a/planetmint/lib.py b/planetmint/lib.py index 2e59cca..b9d192a 100644 --- a/planetmint/lib.py +++ b/planetmint/lib.py @@ -670,7 +670,7 @@ class Planetmint(object): raise InvalidProposer("Public key is not a part of the validator set") # NOTE: Check if all validators have been assigned votes equal to their voting power - if not transaction.is_same_topology(current_validators, transaction.outputs): + if not self.is_same_topology(current_validators, transaction.outputs): raise UnequalValidatorSet("Validator set much be exactly same to the outputs of election") if transaction.operation == VALIDATOR_ELECTION: @@ -778,4 +778,18 @@ class Planetmint(object): status += f"\nvalidators={json.dumps(validators, indent=4)}" return status + def is_same_topology(cls, current_topology, election_topology): + voters = {} + for voter in election_topology: + if len(voter.public_keys) > 1: + return False + + [public_key] = voter.public_keys + voting_power = voter.amount + voters[public_key] = voting_power + + # Check whether the voters and their votes is same to that of the + # validators and their voting power in the network + return current_topology == voters + Block = namedtuple("Block", ("app_hash", "height", "transactions")) diff --git a/planetmint/transactions/types/elections/election.py b/planetmint/transactions/types/elections/election.py index 17b0fba..137a7e7 100644 --- a/planetmint/transactions/types/elections/election.py +++ b/planetmint/transactions/types/elections/election.py @@ -34,21 +34,6 @@ class Election(Transaction): # Vote ratio to approve an election ELECTION_THRESHOLD = 2 / 3 - @classmethod - def is_same_topology(cls, current_topology, election_topology): # TODO: move somewhere else - voters = {} - for voter in election_topology: - if len(voter.public_keys) > 1: - return False - - [public_key] = voter.public_keys - voting_power = voter.amount - voters[public_key] = voting_power - - # Check whether the voters and their votes is same to that of the - # validators and their voting power in the network - return current_topology == voters - @classmethod def validate_election(self, tx_signers, recipients, asset, metadata): if not isinstance(tx_signers, list):