-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Expand file tree
/
Copy pathFixedFeeRegistrar.sol
More file actions
121 lines (113 loc) · 5.19 KB
/
FixedFeeRegistrar.sol
File metadata and controls
121 lines (113 loc) · 5.19 KB
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
//sol FixedFeeRegistrar
// Simple global registrar with fixed-fee reservations.
// @authors:
// Gav Wood <g@ethdev.com>
pragma solidity >=0.4.0 <0.9.0;
abstract contract Registrar {
event Changed(string indexed name);
function owner(string memory _name) public virtual view returns (address o_owner);
function addr(string memory _name) public virtual view returns (address o_address);
function subRegistrar(string memory _name) virtual public view returns (address o_subRegistrar);
function content(string memory _name) public virtual view returns (bytes32 o_content);
}
contract FixedFeeRegistrar is Registrar {
struct Record {
address addr;
address subRegistrar;
bytes32 content;
address owner;
}
modifier onlyrecordowner(string memory _name) { if (m_record(_name).owner == msg.sender) _; }
function reserve(string memory _name) public payable {
Record storage rec = m_record(_name);
if (rec.owner == 0x0000000000000000000000000000000000000000 && msg.value >= c_fee) {
rec.owner = msg.sender;
emit Changed(_name);
}
}
function disown(string memory _name, address payable _refund) onlyrecordowner(_name) public {
delete m_recordData[uint(keccak256(bytes(_name))) / 8];
if (!_refund.send(c_fee))
revert();
emit Changed(_name);
}
function transfer(string memory _name, address _newOwner) onlyrecordowner(_name) public {
m_record(_name).owner = _newOwner;
emit Changed(_name);
}
function setAddr(string memory _name, address _a) onlyrecordowner(_name) public {
m_record(_name).addr = _a;
emit Changed(_name);
}
function setSubRegistrar(string memory _name, address _registrar) onlyrecordowner(_name) public {
m_record(_name).subRegistrar = _registrar;
emit Changed(_name);
}
function setContent(string memory _name, bytes32 _content) onlyrecordowner(_name) public {
m_record(_name).content = _content;
emit Changed(_name);
}
function record(string memory _name) public view returns (address o_addr, address o_subRegistrar, bytes32 o_content, address o_owner) {
Record storage rec = m_record(_name);
o_addr = rec.addr;
o_subRegistrar = rec.subRegistrar;
o_content = rec.content;
o_owner = rec.owner;
}
function addr(string memory _name) public override view returns (address) { return m_record(_name).addr; }
function subRegistrar(string memory _name) public override view returns (address) { return m_record(_name).subRegistrar; }
function content(string memory _name) public override view returns (bytes32) { return m_record(_name).content; }
function owner(string memory _name) public override view returns (address) { return m_record(_name).owner; }
Record[2**253] m_recordData;
function m_record(string memory _name) view internal returns (Record storage o_record) {
return m_recordData[uint(keccak256(bytes(_name))) / 8];
}
uint constant c_fee = 69 ether;
}
// ----
// constructor()
// gas irOptimized: 77654
// gas irOptimized code: 302200
// gas legacy: 115395
// gas legacy code: 792400
// gas legacyOptimized: 84566
// gas legacyOptimized code: 387600
// reserve(string), 69 ether: 0x20, 3, "abc" ->
// ~ emit Changed(string): #0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45
// gas irOptimized: 45967
// gas legacy: 46842
// gas legacyOptimized: 46091
// owner(string): 0x20, 3, "abc" -> 0x1212121212121212121212121212120000000012
// reserve(string), 70 ether: 0x20, 3, "def" ->
// ~ emit Changed(string): #0x34607c9bbfeb9c23509680f04363f298fdb0b5f9abe327304ecd1daca08cda9c
// owner(string): 0x20, 3, "def" -> 0x1212121212121212121212121212120000000012
// reserve(string), 68 ether: 0x20, 3, "ghi" ->
// owner(string): 0x20, 3, "ghi" -> 0
// account: 1 -> 0x1212121212121212121212121212120000001012
// reserve(string), 69 ether: 0x20, 3, "abc" ->
// owner(string): 0x20, 3, "abc" -> 0x1212121212121212121212121212120000000012
// account: 0 -> 0x1212121212121212121212121212120000000012
// setContent(string,bytes32): 0x40, 0, 3, "abc" ->
// ~ emit Changed(string): #0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45
// transfer(string,address): 0x40, 555, 3, "abc" ->
// ~ emit Changed(string): #0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45
// owner(string): 0x20, 3, "abc" -> 555
// content(string): 0x20, 3, "abc" -> 0x00
// setContent(string,bytes32): 0x40, 333, 3, "def" ->
// ~ emit Changed(string): #0x34607c9bbfeb9c23509680f04363f298fdb0b5f9abe327304ecd1daca08cda9c
// setAddr(string,address): 0x40, 124, 3, "def" ->
// ~ emit Changed(string): #0x34607c9bbfeb9c23509680f04363f298fdb0b5f9abe327304ecd1daca08cda9c
// setSubRegistrar(string,address): 0x40, 125, 3, "def" ->
// ~ emit Changed(string): #0x34607c9bbfeb9c23509680f04363f298fdb0b5f9abe327304ecd1daca08cda9c
// content(string): 0x20, 3, "def" -> 333
// addr(string): 0x20, 3, "def" -> 124
// subRegistrar(string): 0x20, 3, "def" -> 125
// balance: 0x124 -> 0
// disown(string,address): 0x40, 0x124, 3, "def" ->
// ~ emit Changed(string): #0x34607c9bbfeb9c23509680f04363f298fdb0b5f9abe327304ecd1daca08cda9c
// balance: 0x124 -> 0
// ~ emit Changed(string): #0x34607c9bbfeb9c23509680f04363f298fdb0b5f9abe327304ecd1daca08cda9c
// owner(string): 0x20, 3, "def" -> 0
// content(string): 0x20, 3, "def" -> 0
// addr(string): 0x20, 3, "def" -> 0
// subRegistrar(string): 0x20, 3, "def" -> 0