@@ -31,7 +31,8 @@ contract Voting {
3131 _onlyAdmin ();
3232 _;
3333 }
34- function _onlyAdmin () internal view {
34+
35+ function _onlyAdmin () internal view {
3536 require (msg .sender == ADMIN, "Only Admin " );
3637 }
3738
@@ -40,16 +41,14 @@ contract Voting {
4041 _;
4142 }
4243
43- function _votingActive () internal view {
44+ function _votingActive () internal view {
4445 require (votingOpen, "Voting closed " );
4546 }
47+
4648 // --- Core Functions ---
4749 function addCandidate (string calldata _name ) external onlyAdmin {
4850 require (bytes (_name).length > 0 , "Name required " );
49- candidates.push (Candidate ({
50- name: _name,
51- voteCount: 0
52- }));
51+ candidates.push (Candidate ({name: _name, voteCount: 0 }));
5352 emit CandidateAdded (_name);
5453 }
5554
@@ -82,23 +81,13 @@ contract Voting {
8281 return totalVoteCount;
8382 }
8483
85- function votesOf (uint256 candidateIndex )
86- external
87- view
88- onlyAdmin
89- returns (uint256 )
90- {
84+ function votesOf (uint256 candidateIndex ) external view onlyAdmin returns (uint256 ) {
9185 require (candidateIndex < candidates.length , "Invalid index " );
9286 require (! votingOpen, "Count after voting closed " );
9387 return candidates[candidateIndex].voteCount;
9488 }
9589
96- function getWinner ()
97- external
98- view
99- onlyAdmin
100- returns (string memory winnerName )
101- {
90+ function getWinner () external view onlyAdmin returns (string memory winnerName ) {
10291 require (! votingOpen, "Count after voting closed " );
10392 uint256 maxVotes;
10493 for (uint256 i = 0 ; i < candidates.length ; i++ ) {
0 commit comments