-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitignore
112 lines (82 loc) · 2.56 KB
/
.gitignore
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
node_modules
.env
# Hardhat files
/cache
/artifacts
# TypeChain files
/typechain
/typechain-types
# solidity-coverage files
/coverage
/coverage.json
# Hardhat Ignition default folder for deployments against a local node
ignition/deployments/chain-31337
/*
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Voting {
// Struct to represent each candidate
struct Candidate {
string name;
string party;
uint256 voteCount;
address voters;
}
Candidate[] public listOfCandidate;
// Mapping to store each candidate by its ID
mapping(uint256 => Candidate) public candidates;
// Mapping to track whether a voter has already voted
mapping(address => bool) public hasVoted;
// Number of candidates
uint256 public candidatesCount;
// Event that will be emitted whenever a vote is cast
event Voted(uint256 indexed candidateId, address indexed voter);
// Constructor to initialize the contract with some candidates
constructor() {
}
// Function to add a new candidate (private, only called during deployment)
function addCandidate(string memory _name, string memory _party) public {
listOfCandidate.push(Candidate(_name, _party,candidatesCount++,msg.sender));
}
// Function to vote for a candidate
function vote(uint256 _candidateId) public {
// Ensure the voter hasn't already voted
require(!hasVoted[msg.sender], "You have already voted.");
// Ensure the candidate ID is valid
require(_candidateId > 0 && _candidateId <= candidatesCount, "Invalid candidate ID.");
// Record that this voter has voted
hasVoted[msg.sender] = true;
// Increase the candidate's vote count
candidates[_candidateId].voteCount++;
// Emit an event for the vote
emit Voted(_candidateId, msg.sender);
}
// Get the total votes for a candidate
function getVotes() public view returns (Candidate[] memory) {
return listOfCandidate;
}
// Get candidate details by ID
function getCandidate(uint256 _candidateId) public view returns (uint256) {
require(_candidateId > 0 && _candidateId <= candidatesCount, "Invalid candidate ID.");
return _candidateId;
}
}
*/