-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathBordaNewBug.sol
More file actions
48 lines (37 loc) · 1.28 KB
/
BordaNewBug.sol
File metadata and controls
48 lines (37 loc) · 1.28 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
46
47
48
pragma solidity ^0.8.0;
import "./IBorda.sol";
contract Borda is IBorda{
// The current winner
address public _winner;
// A map storing whether an address has already voted. Initialized to false.
mapping (address => bool) _voted;
// Points each candidate has recieved, initialized to zero.
mapping (address => uint256) _points;
// current maximum points of all candidates.
uint256 public pointsOfWinner;
function vote(address f, address s, address t) public override {
require(!_voted[msg.sender], "this voter has already cast its vote");
require( f != s && f != t && s != t, "candidates are not different");
_voted[msg.sender] = true;
voteTo(t, 1);
voteTo(s, 2);
voteTo(f, 3);
}
function voteTo(address c, uint256 p) private {
//update points
_points[c] = _points[c]+ p;
// update winner if needed
if (_points[c] > _points[_winner]) {
_winner = c;
}
}
function winner() external view override returns (address) {
return _winner;
}
function points(address c) public view override returns (uint256) {
return _points[c];
}
function voted(address x) public view override returns(bool) {
return _voted[x];
}
}