Skip to content

Commit 833f313

Browse files
Formatted
1 parent 5101ac8 commit 833f313

3 files changed

Lines changed: 13 additions & 24 deletions

File tree

script/DeploySimpleStorage.s.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.30;
33

4-
import { Script } from "forge-std/Script.sol";
5-
import { SimpleStorage } from "../src/SimpleStorage.sol";
4+
import {Script} from "forge-std/Script.sol";
5+
import {SimpleStorage} from "../src/SimpleStorage.sol";
66

77
contract DeploySimpleStorage is Script {
88
function run() external returns (SimpleStorage) {

script/DeployVoting.s.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.30;
33

4-
import { Script } from "forge-std/Script.sol";
5-
import { Voting } from "../src/Voting.sol";
4+
import {Script} from "forge-std/Script.sol";
5+
import {Voting} from "../src/Voting.sol";
66

77
contract DeployVoting is Script {
8-
function run() external returns(Voting){
8+
function run() external returns (Voting) {
99
vm.startBroadcast();
1010
Voting voting = new Voting();
1111
vm.stopBroadcast();
1212
return voting;
1313
}
14-
}
14+
}

src/Voting.sol

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)