-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoter.sol
58 lines (47 loc) · 1.33 KB
/
Voter.sol
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
// SPDX-License-Identifier: Apache-2.0
/**
* @author Spyridon Ninos, 3232020022
*
* this contract models a voter for the e-voting system implemented
* by the Referendum contract
*/
pragma solidity ^0.8.4;
contract Voter {
// made public so that the getters are defined implicitly
string public firstName;
string public lastName;
// reference to the Referendum deployed contract
Referendum referendum;
constructor(string memory _firstName, string memory _lastName) {
firstName = _firstName;
lastName = _lastName;
}
/**
* registers the voter to the provided referendum
*
* _referendumAddress: the address of the deployed referendum contract
*/
function register(address _referendumAddress) public {
referendum = Referendum(_referendumAddress);
referendum.register();
}
/**
* utility method that votes yes to the referendum
*/
function voteYes() public {
referendum.vote(true);
}
/**
* utility method that votes no to the referendum
*/
function voteNo() public {
referendum.vote(false);
}
}
/**
* required by the Voter contract in order to register and vote
*/
contract Referendum {
function register() public {}
function vote(bool _value) public {}
}