-
Notifications
You must be signed in to change notification settings - Fork 0
/
ControllerOwnable.sol
55 lines (47 loc) · 1.77 KB
/
ControllerOwnable.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
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.6;
import "@openzeppelin/contracts/access/Ownable.sol";
// as well as being ownable (i.e. our admin wallet)
// this contract has a modifier called onlyController
// it works the same way as Ownable but only the Owner
// can change the controller address so it gives us a way of
// re-pointing contracts if needed
contract ControllerOwnable is Ownable {
// the address of the controller that is allowed to call functions
address private controllerAddress;
// used to "freeze" the controller address - even the admin cannot
// change it from this point onwards
bool private canChangeControllerAddress = true;
modifier onlyController() {
_checkControllerAccess();
_;
}
function _checkControllerAccess() internal view virtual returns (bool) {
require(
controllerAddress != address(0),
"ControllerOwnable: Controller address must be defined"
);
require(
_msgSender() == controllerAddress,
"ControllerOwnable: Only the controller can call this method"
);
return true;
}
function setControllerAddress(address _controllerAddress) public onlyOwner {
require(
_controllerAddress != address(0),
"ControllerOwnable: Controller address must be defined"
);
require(
canChangeControllerAddress,
"ControllerOwnable: canChangeControllerAddress is disabled"
);
controllerAddress = _controllerAddress;
}
function getControllerAddress() public view returns (address) {
return controllerAddress;
}
function disableChangeControllerAddress() public onlyOwner {
canChangeControllerAddress = false;
}
}