-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathColonyNetworkENS.sol
112 lines (91 loc) · 4.01 KB
/
ColonyNetworkENS.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
/*
This file is part of The Colony Network.
The Colony Network is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The Colony Network is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with The Colony Network. If not, see <http://www.gnu.org/licenses/>.
*/
pragma solidity ^0.4.23;
pragma experimental "v0.5.0";
import "./ens/ENS.sol";
import "./ColonyNetworkStorage.sol";
/// @title First-In-First-Served ENS Registrar
/// @notice A registrar that allocates subdomains to the first person to claim them.
/// @notice Source modified from https://github.com/ensdomains/ens/blob/master/contracts/FIFSRegistrar.sol
contract ColonyNetworkENS is ColonyNetworkStorage {
bytes32 constant USER_HASH = keccak256("user");
bytes32 constant COLONY_HASH = keccak256("colony");
modifier unowned(bytes32 node, string username) {
address currentOwner = ENS(ens).owner(keccak256(abi.encodePacked(node, keccak256(username))));
require(currentOwner == 0, "colony-label-already-owned");
_;
}
event UserLabelRegistered(address indexed user, bytes32 label);
event ColonyLabelRegistered(address indexed colony, bytes32 label);
function setupRegistrar(address _ens, bytes32 _rootNode) public auth {
ens = _ens;
rootNode = _rootNode;
userNode = keccak256(abi.encodePacked(rootNode, USER_HASH));
colonyNode = keccak256(abi.encodePacked(rootNode, COLONY_HASH));
ENS(ens).setSubnodeOwner(rootNode, USER_HASH, this);
ENS(ens).setSubnodeOwner(rootNode, COLONY_HASH, this);
}
function registerUserLabel(string username, string orbitdb)
public
unowned(userNode, username)
{
require(bytes(username).length > 0, "colony-user-label-invalid");
require(bytes(userLabels[msg.sender]).length == 0, "colony-user-label-already-owned");
bytes32 subnode = keccak256(username);
ENS(ens).setSubnodeOwner(userNode, subnode, this);
bytes32 node = keccak256(abi.encodePacked(userNode, subnode));
ENS(ens).setResolver(node, this);
records[node].addr = msg.sender;
records[node].orbitdb = orbitdb;
userLabels[msg.sender] = username;
emit UserLabelRegistered(msg.sender, subnode);
}
function registerColonyLabel(string colonyName)
public
calledByColony
unowned(colonyNode, colonyName)
{
require(bytes(colonyName).length > 0, "colony-colony-label-invalid");
require(bytes(colonyLabels[msg.sender]).length == 0, "colony-already-labeled");
bytes32 subnode = keccak256(colonyName);
ENS(ens).setSubnodeOwner(colonyNode, subnode, this);
bytes32 node = keccak256(abi.encodePacked(colonyNode, subnode));
ENS(ens).setResolver(node, this);
records[node].addr = msg.sender;
colonyLabels[msg.sender] = colonyName;
emit ColonyLabelRegistered(msg.sender, subnode);
}
function getProfileDBAddress(bytes32 node) public view returns (string) {
return records[node].orbitdb;
}
function lookupUsername(address addr) public view returns(string) {
if (bytes(userLabels[addr]).length != 0) {
return string(abi.encodePacked(userLabels[addr], ".user.joincolony.eth"));
} else if (bytes(colonyLabels[addr]).length != 0) {
return string(abi.encodePacked(colonyLabels[addr], ".colony.joincolony.eth"));
} else {
return "";
}
}
// ENS Resolver functions
bytes4 constant INTERFACE_META_ID = 0x01ffc9a7;
bytes4 constant ADDR_INTERFACE_ID = 0x3b3b57de;
function supportsInterface(bytes4 interfaceID) public view returns (bool) {
return (interfaceID == INTERFACE_META_ID ||
interfaceID == ADDR_INTERFACE_ID );
}
function addr(bytes32 node) public view returns (address) {
return records[node].addr;
}
}