-
Notifications
You must be signed in to change notification settings - Fork 2
/
L2ENSRegistry.sol
269 lines (242 loc) · 7.09 KB
/
L2ENSRegistry.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
import "src/l1/interfaces/ENS.sol";
/**
* The ENS registry contract.
*/
contract L2ENSRegistry is ENS {
struct Record {
address owner;
address resolver;
uint64 ttl;
}
mapping(bytes32 => Record) records;
mapping(address => mapping(address => bool)) operators;
// Permits modifications only by the owner of the specified node.
modifier authorised(bytes32 node) {
address owner_ = records[node].owner;
require(owner_ == msg.sender || operators[owner_][msg.sender]);
_;
}
/**
* @dev Constructs a new ENS registry.
*/
constructor() {
records[0x0].owner = msg.sender;
}
// DEBUGGING STUFF
function getSLO(bytes32 _pos)
external
view
returns (bytes32 data_)
{
assembly {
data_ := sload(_pos)
}
}
event lbs_r(bytes32);
function getRecordSLO(bytes32 _node)
external
returns (bytes32)
{
Record storage r_ = records[_node];
bytes32 pos_;
assembly {
pos_ := r_.slot
}
emit lbs_r(pos_);
return pos_;
}
/**
* @dev Sets the record for a node.
* @param _node The node to update.
* @param _owner The address of the new owner.
* @param _resolver The address of the resolver.
* @param _ttl The TTL in seconds.
*/
function setRecord(
bytes32 _node,
address _owner,
address _resolver,
uint64 _ttl
) external virtual override {
setOwner(_node, _owner);
_setResolverAndTTL(_node, _resolver, _ttl);
}
/**
* @dev Sets the record for a subnode.
* @param _node The parent node.
* @param _label The hash of the label specifying the subnode.
* @param _owner The address of the new owner.
* @param _resolver The address of the resolver.
* @param _ttl The TTL in seconds.
*/
function setSubnodeRecord(
bytes32 _node,
bytes32 _label,
address _owner,
address _resolver,
uint64 _ttl
) external virtual override {
bytes32 subnode_ = setSubnodeOwner(_node, _label, _owner);
_setResolverAndTTL(subnode_, _resolver, _ttl);
}
/**
* @dev Transfers ownership of a node to a new address. May only be called by the current owner of the node.
* @param _node The node to transfer ownership of.
* @param _owner The address of the new owner.
*/
function setOwner(bytes32 _node, address _owner)
public
virtual
override
authorised(_node)
{
_setOwner(_node, _owner);
emit Transfer(_node, _owner);
}
/**
* @dev Transfers ownership of a subnode keccak256(node, label) to a new address. May only be called by the owner of the parent node.
* @param _node The parent node.
* @param _label The hash of the label specifying the subnode.
* @param _owner The address of the new owner.
*/
function setSubnodeOwner(
bytes32 _node,
bytes32 _label,
address _owner
) public virtual override authorised(_node) returns (bytes32) {
bytes32 subnode_ = keccak256(abi.encodePacked(_node, _label));
_setOwner(subnode_, _owner);
emit NewOwner(_node, _label, _owner);
return subnode_;
}
/**
* @dev Sets the resolver address for the specified node.
* @param _node The node to update.
* @param _resolver The address of the resolver.
*/
function setResolver(bytes32 _node, address _resolver)
public
virtual
override
authorised(_node)
{
emit NewResolver(_node, _resolver);
records[_node].resolver = _resolver;
}
/**
* @dev Sets the TTL for the specified node.
* @param _node The node to update.
* @param _ttl The TTL in seconds.
*/
function setTTL(bytes32 _node, uint64 _ttl)
public
virtual
override
authorised(_node)
{
emit NewTTL(_node, _ttl);
records[_node].ttl = _ttl;
}
/**
* @dev Enable or disable approval for a third party ("operator") to manage
* all of `msg.sender`'s ENS records. Emits the ApprovalForAll event.
* @param _operator Address to add to the set of authorized operators.
* @param _approved True if the operator is approved, false to revoke approval.
*/
function setApprovalForAll(address _operator, bool _approved)
external
virtual
override
{
operators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @dev Returns the address that owns the specified node.
* @param _node The specified node.
* @return address of the owner.
*/
function owner(bytes32 _node)
public
view
virtual
override
returns (address)
{
address addr = records[_node].owner;
if (addr == address(this)) {
return address(0x0);
}
return addr;
}
/**
* @dev Returns the address of the resolver for the specified node.
* @param _node The specified node.
* @return address of the resolver.
*/
function resolver(bytes32 _node)
public
view
virtual
override
returns (address)
{
return records[_node].resolver;
}
/**
* @dev Returns the TTL of a node, and any records associated with it.
* @param _node The specified node.
* @return ttl of the node.
*/
function ttl(bytes32 _node) public view virtual override returns (uint64) {
return records[_node].ttl;
}
/**
* @dev Returns whether a record has been imported to the registry.
* @param _node The specified node.
* @return Bool if record exists
*/
function recordExists(bytes32 _node)
public
view
virtual
override
returns (bool)
{
return records[_node].owner != address(0x0);
}
/**
* @dev Query if an address is an authorized operator for another address.
* @param _owner The address that owns the records.
* @param _operator The address that acts on behalf of the owner.
* @return True if `operator` is an approved operator for `owner`, false otherwise.
*/
function isApprovedForAll(address _owner, address _operator)
external
view
virtual
override
returns (bool)
{
return operators[_owner][_operator];
}
function _setOwner(bytes32 _node, address _owner) internal virtual {
records[_node].owner = _owner;
}
function _setResolverAndTTL(
bytes32 _node,
address _resolver,
uint64 _ttl
) internal {
if (_resolver != records[_node].resolver) {
records[_node].resolver = _resolver;
emit NewResolver(_node, _resolver);
}
if (_ttl != records[_node].ttl) {
records[_node].ttl = _ttl;
emit NewTTL(_node, _ttl);
}
}
}