-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-Operational-Multicall.sol
117 lines (93 loc) · 4.16 KB
/
1-Operational-Multicall.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
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
113
114
115
116
pragma solidity ^0.4.25;
contract ExerciseC6A {
/********************************************************************************************/
/* DATA VARIABLES */
/********************************************************************************************/
struct UserProfile {
bool isRegistered;
bool isAdmin;
}
bool public isOperational;
address private contractOwner; // Account used to deploy contract
mapping(address => UserProfile) userProfiles; // Mapping for storing user profiles
uint8 public votes = 0;
uint8 necessaryVotes = 3;
mapping(address => bool) voters;
address[] votersArray;
/********************************************************************************************/
/* EVENT DEFINITIONS */
/********************************************************************************************/
// No events
/**
* @dev Constructor
* The deploying account becomes contractOwner
*/
constructor() public {
contractOwner = msg.sender;
isOperational = true;
}
/********************************************************************************************/
/* FUNCTION MODIFIERS */
/********************************************************************************************/
// Modifiers help avoid duplication of code. They are typically used to validate something
// before a function is allowed to be executed.
/**
* @dev Modifier that requires the "ContractOwner" account to be the function caller
*/
modifier requireContractOwner() {
require(msg.sender == contractOwner, "Caller is not contract owner");
_;
}
modifier requireOperational() {
require (isOperational, "Contract is not operational");
_;
}
modifier admin() {
require(userProfiles[msg.sender].isAdmin, "User is not admin");
_;
}
modifier hasNotVoted() {
require(!voters[msg.sender], "User has already voted");
_;
}
/********************************************************************************************/
/* UTILITY FUNCTIONS */
/********************************************************************************************/
/**
* @dev Check if a user is registered
*
* @return A bool that indicates if the user is registered
*/
function changeOperationalStatus(bool mode) public admin hasNotVoted {
if (mode != isOperational) {
voters[msg.sender] = true;
votes++;
votersArray.push(msg.sender);
if (votes == necessaryVotes) {
isOperational = mode;
votes = 0;
for (uint16 i = 0; i<votersArray.length; i++ ) {
delete voters[votersArray[i]];
}
delete votersArray;
}
}
}
function isUserRegistered(address account) external view returns(bool) {
require(account != address(0), "'account' must be a valid address.");
return userProfiles[account].isRegistered;
}
/********************************************************************************************/
/* SMART CONTRACT FUNCTIONS */
/********************************************************************************************/
function registerUser(address account, bool isAdmin) external requireContractOwner requireOperational {
require(!userProfiles[account].isRegistered, "User is already registered.");
userProfiles[account] = UserProfile({ isRegistered: true, isAdmin: isAdmin});
}
function getOperationalStatus() public view returns (bool) {
return isOperational;
}
function getVotersArray() public view returns (address[]) {
return votersArray;
}
}