-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathens.sol
More file actions
129 lines (116 loc) · 3.98 KB
/
ens.sol
File metadata and controls
129 lines (116 loc) · 3.98 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
122
123
124
125
126
127
128
129
import 'interface.sol';
import 'dapple/debug.sol';
import 'controllers/standard_registry.sol';
contract ENS is ENSApp
, Debug
{
uint next_id;
ENSController public root;
mapping( uint => ENSController ) _controllers;
StandardRegistryController public std;
function ENS( ENSController root_controller ) {
next_id = 1;
root = root_controller;
// TODO there is no reason for this to live here.
// It should go in ExtendedImpl.
std = new StandardRegistryController();
std.ens_controller_init( this );
}
// new_node is the old name, TODO remove it and fix tests
function new_node() returns (uint) { return claim_node(); }
function claim_node() returns (uint) {
var ret = next_id;
_controllers[next_id] = ENSController(msg.sender);
next_id++;
return ret;
}
function get_controller( uint node ) returns (ENSController controller) {
return (_controllers[node]);
}
function get( bytes path ) returns ( bytes32 value, bool is_link, bool ok ) {
(, , value, is_link, ok) = resolve_path( path );
if( ok ) {
return (value, is_link, ok);
} else {
return (0x0, false, false);
}
}
function set( bytes path, bytes32 value, bool is_link ) returns ( bool ok ) {
var (node, key, , , path_ok) = resolve_path( path );
if( path_ok ) {
var controller = _controllers[node];
return controller.ens_set( node, msg.sender, key, value, is_link );
} else {
return false;
}
}
function node_get( uint node, bytes32 key ) returns (bytes32 value, bool is_link, bool ok) {
var controller = _controllers[node];
return controller.ens_get( node, msg.sender, key );
}
function node_set( uint node, bytes32 key, bytes32 value ) returns (bool ok) {
var controller = _controllers[node];
return controller.ens_set( node, msg.sender, key, value, false );
}
function resolve_path( bytes query )
constant
internal
returns (uint node, bytes32 key, bytes32 value, bool is_link, bool ok)
{
uint current_node = 1;
uint path_position = 0;
while( true ) {
bytes32 partial_key = 0x0;
uint shift = uint(256)**31;
bool escaped = false;
if( is_separator( query[path_position] ) ) {
path_position++;
}
while( path_position < query.length ) {
byte character = query[path_position];
path_position++;
if( is_separator(character) ) {
break;
}
if( is_escape(character) ) {
path_position++;
continue;
}
partial_key = partial_key | bytes32((uint(character) * shift));
shift /= 256;
}
var controller = _controllers[current_node];
log_bytes32(key);
log_uint(current_node);
(value, is_link, ok) = controller.ens_get( current_node, msg.sender, partial_key );
return;
}
// parse key
// get from node
// if not ok:
// fail
// if not link:
// return node, key, value, false, true
// else:
// node = value
// recurse
}
function is_separator(byte c) internal returns (bool) {
return c == byte("/");
}
function is_escape(byte c) internal returns (bool) {
return c == byte("\\");
}
}
contract ENSExtendedImpl is ENS {
function path_info( bytes path ) returns (uint node_id, bytes last_key, bool ok) {
bytes memory ret;
return (0, ret, false);
}
function transfer_node( uint node, ENSController new_controller) returns (bool ok) {
if( msg.sender == address(_controllers[node]) ) {
_controllers[node] = new_controller;
}
return false;
}
}