-
Notifications
You must be signed in to change notification settings - Fork 41
/
Registry.sol
148 lines (129 loc) · 4.65 KB
/
Registry.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interface/IRegistry.sol";
/// @notice The registry database for Furucombo
contract Registry is IRegistry, Ownable {
mapping(address => bytes32) public override handlers;
mapping(address => bytes32) public override callers;
mapping(address => uint256) public override bannedAgents;
bool public override fHalt;
bytes32 public constant DEPRECATED = bytes10(0x64657072656361746564);
event Registered(address indexed registration, bytes32 info);
event Unregistered(address indexed registration);
event CallerRegistered(address indexed registration, bytes32 info);
event CallerUnregistered(address indexed registration);
event Banned(address indexed agent);
event Unbanned(address indexed agent);
event Halted();
event Unhalted();
modifier isNotHalted() {
require(fHalt == false, "Halted");
_;
}
modifier isHalted() {
require(fHalt, "Not halted");
_;
}
modifier isNotBanned(address agent) {
require(bannedAgents[agent] == 0, "Banned");
_;
}
modifier isBanned(address agent) {
require(bannedAgents[agent] != 0, "Not banned");
_;
}
/**
* @notice Register a handler with a bytes32 information.
* @param registration Handler address.
* @param info Info string.
*/
function register(address registration, bytes32 info) external onlyOwner {
require(registration != address(0), "zero address");
require(info != DEPRECATED, "unregistered info");
require(handlers[registration] != DEPRECATED, "unregistered");
handlers[registration] = info;
emit Registered(registration, info);
}
/**
* @notice Unregister a handler. The handler will be deprecated.
* @param registration The handler to be unregistered.
*/
function unregister(address registration) external onlyOwner {
require(registration != address(0), "zero address");
require(handlers[registration] != bytes32(0), "no registration");
require(handlers[registration] != DEPRECATED, "unregistered");
handlers[registration] = DEPRECATED;
emit Unregistered(registration);
}
/**
* @notice Register a caller with a bytes32 information.
* @param registration Caller address.
* @param info Info string.
* @dev Dapps that triggers callback function should be registered.
* In this case, registration is the Dapp address and the leading 20 bytes
* of info is the handler address.
*/
function registerCaller(
address registration,
bytes32 info
) external onlyOwner {
require(registration != address(0), "zero address");
require(info != DEPRECATED, "unregistered info");
require(callers[registration] != DEPRECATED, "unregistered");
callers[registration] = info;
emit CallerRegistered(registration, info);
}
/**
* @notice Unregister a caller. The caller will be deprecated.
* @param registration The caller to be unregistered.
*/
function unregisterCaller(address registration) external onlyOwner {
require(registration != address(0), "zero address");
require(callers[registration] != bytes32(0), "no registration");
require(callers[registration] != DEPRECATED, "unregistered");
callers[registration] = DEPRECATED;
emit CallerUnregistered(registration);
}
/**
* @notice Ban agent from query
*
*/
function ban(address agent) external isNotBanned(agent) onlyOwner {
bannedAgents[agent] = 1;
emit Banned(agent);
}
/**
* @notice Unban agent from query
*/
function unban(address agent) external isBanned(agent) onlyOwner {
bannedAgents[agent] = 0;
emit Unbanned(agent);
}
/**
* @notice Check if the handler is valid.
* @param handler The handler to be verified.
*/
function isValidHandler(
address handler
) external view override returns (bool) {
return handlers[handler] != 0 && handlers[handler] != DEPRECATED;
}
/**
* @notice Check if the caller is valid.
* @param caller The caller to be verified.
*/
function isValidCaller(
address caller
) external view override returns (bool) {
return callers[caller] != 0 && callers[caller] != DEPRECATED;
}
function halt() external isNotHalted onlyOwner {
fHalt = true;
emit Halted();
}
function unhalt() external isHalted onlyOwner {
fHalt = false;
emit Unhalted();
}
}