VoteInOpenElections.sol
ElectionTally.sol is an electoral law that manages the tallying of votes in an election. It provides a mechanism to count votes, determine winners, and assign roles based on election results.
Overview
This law provides a mechanism to:
Count and validate votes in an election
Determine winners based on vote counts
Assign roles to election winners
Track election results and statistics
Enforce election rules and constraints
Configuration
When adopting an ElectionTally instance, four parameters must be provided:
maxWinners(uint256): Maximum number of winners that can be assigned the roleroleID(uint256): The role ID to be assigned to winnersvoterRoleID(uint256): The role ID required to voteminVotes(uint256): Minimum number of votes required for a valid election
Usage
Proposing an Action
When calling the law, two parameters must be provided:
candidate(address): The candidate to vote forvote(bool):true: Cast a vote for the candidatefalse: Remove a vote for the candidate
Execution Flow
Vote Validation
Verifies the voter has the required role
Checks if voter has already voted
Validates vote status
Candidate Validation
Verifies the candidate address
Checks candidate's eligibility
Validates maximum winners limit
Vote Processing
If
voteis true:Records vote for candidate
Updates vote counts
Checks if minimum votes reached
If
voteis false:Removes vote for candidate
Updates vote counts
Winner Determination
Tallys all votes
Identifies top vote-getters
Assigns roles to winners
Records election results
Technical Specifications
State Variables
Functions
initializeLaw
initializeLawInitializes law with configuration parameters
Sets up role IDs and election requirements
Initializes empty vote tracking
handleRequest
handleRequestProcesses the vote request
Validates voter and candidate status
Prepares role assignments for winners
Returns execution data
_changeState
_changeStateUpdates vote counts
Maintains candidate and winner lists
Records voting history
getData
getDataReturns the current state of the law
Includes all configuration and election data
Error Conditions
Voting Errors
"Not a voter"
"Already voted"
"Invalid vote"
Election Errors
"Insufficient votes"
"Invalid candidate"
"Election not active"
Role Assignment Errors
"Max winners reached"
"Invalid winner"
Validation Errors
Invalid role ID
Invalid candidate address
Zero address candidate
Invalid vote count
Current Deployments
Last updated