-
Notifications
You must be signed in to change notification settings - Fork 0
/
registrar.sol
119 lines (106 loc) · 4.38 KB
/
registrar.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
/*
* Copyright (c) 2014 Gav Wood <[email protected]>
* Copyright (c) 2016 Savoir-faire Linux Inc.
*
* Author: Gav Wood <[email protected]>
* Author: Adrien Béraud <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* urnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
contract NameRegister {
function addr(bytes32 _name) constant returns (address o_owner) {}
function name(address _owner) constant returns (bytes32 o_name) {}
}
contract Registrar is NameRegister {
event Changed(bytes32 indexed name);
event PrimaryChanged(bytes32 indexed name, address indexed addr, address owner);
function owner(bytes32 _name) constant returns (address o_owner) {}
function addr(bytes32 _name) constant returns (address o_address) {}
function subRegistrar(bytes32 _name) constant returns (address o_subRegistrar) {}
function content(bytes32 _name) constant returns (bytes32 o_content) {}
function name(address _owner) constant returns (bytes32 o_name) {}
}
contract GlobalRegistrar is Registrar {
struct Record {
address owner;
address primary;
address subRegistrar;
bytes32 content;
uint value;
uint renewalDate;
}
function Registrar() {
}
function reserve(bytes32 _name, address _a) {
if (m_toRecord[_name].owner == 0 && m_toName[_a] == 0) {
m_toRecord[_name].owner = msg.sender;
m_toRecord[_name].primary = _a;
m_toName[_a] = _name;
Changed(_name);
PrimaryChanged(_name, _a, msg.sender);
}
}
function reserveFor(bytes32 _name, address _owner, address _a) {
if (m_toRecord[_name].owner == 0 && m_toName[_a] == 0) {
m_toRecord[_name].owner = _owner;
m_toRecord[_name].primary = _a;
m_toName[_a] = _name;
Changed(_name);
PrimaryChanged(_name, _a, _owner);
}
}
modifier onlyrecordowner(bytes32 _name) { if (m_toRecord[_name].owner == msg.sender) _; }
function transfer(bytes32 _name, address _newOwner) onlyrecordowner(_name) {
m_toRecord[_name].owner = _newOwner;
Changed(_name);
}
function disown(bytes32 _name) onlyrecordowner(_name) {
if (m_toName[m_toRecord[_name].primary] == _name)
{
PrimaryChanged(_name, m_toRecord[_name].primary, m_toRecord[_name].owner);
m_toName[m_toRecord[_name].primary] = "";
}
delete m_toRecord[_name];
Changed(_name);
}
function setAddress(bytes32 _name, address _a, bool _primary) onlyrecordowner(_name) {
m_toRecord[_name].primary = _a;
if (_primary)
{
PrimaryChanged(_name, _a, m_toRecord[_name].owner);
m_toName[_a] = _name;
}
Changed(_name);
}
function setSubRegistrar(bytes32 _name, address _registrar) onlyrecordowner(_name) {
m_toRecord[_name].subRegistrar = _registrar;
Changed(_name);
}
function setContent(bytes32 _name, bytes32 _content) onlyrecordowner(_name) {
m_toRecord[_name].content = _content;
Changed(_name);
}
function owner(bytes32 _name) constant returns (address) { return m_toRecord[_name].owner; }
function addr(bytes32 _name) constant returns (address) { return m_toRecord[_name].primary; }
function register(bytes32 _name) constant returns (address) { return m_toRecord[_name].subRegistrar; }
function content(bytes32 _name) constant returns (bytes32) { return m_toRecord[_name].content; }
function name(address _a) constant returns (bytes32 o_name) { return m_toName[_a]; }
mapping (address => bytes32) m_toName;
mapping (bytes32 => Record) m_toRecord;
}