-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArcVote.sol
More file actions
45 lines (31 loc) · 1.21 KB
/
ArcVote.sol
File metadata and controls
45 lines (31 loc) · 1.21 KB
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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
contract ArcVote {
struct Candidate {
string name;
uint256 voteCount;
}
Candidate[] public candidates;
mapping (address => bool) public hasVoted;
//necessario para atualizar o site
event VoteConfirmed (address voter, string candidateName);
constructor (){
candidates.push(Candidate("USDC (Circle)", 0));
candidates.push(Candidate("EURC (Euro)", 0));
candidates.push(Candidate("Arc Native Token", 0));
candidates.push(Candidate("Wrapped BTC", 0));
candidates.push(Candidate("Wrapped ETH", 0));
}
function vote (uint256 _candidateIndex) public {
require(!hasVoted[msg.sender], "You have already voted!");
//verifica se o ID existe
require(_candidateIndex < candidates.length, "Invalid Candidate.");
//gravar o voto
hasVoted[msg.sender] = true;
candidates[_candidateIndex].voteCount += 1;
emit VoteConfirmed(msg.sender, candidates[_candidateIndex].name);
}
function getCandidatesCount() public view returns (uint256) {
return candidates.length;
}
}