tx · HQKJNcgRN3YhsZ2sAG5HFQ6LGi9FbojNaB2yCrm51qis 3MvCgypmBZFTRqL5HuRwCgS7maC7Fkv7pZY: -0.01000000 Waves 2022.10.20 18:40 [2280924] smart account 3MvCgypmBZFTRqL5HuRwCgS7maC7Fkv7pZY > SELF 0.00000000 Waves
{ "type": 13, "id": "HQKJNcgRN3YhsZ2sAG5HFQ6LGi9FbojNaB2yCrm51qis", "fee": 1000000, "feeAssetId": null, "timestamp": 1666280452325, "version": 2, "chainId": 84, "sender": "3MvCgypmBZFTRqL5HuRwCgS7maC7Fkv7pZY", "senderPublicKey": "BqGSAiYghM27RZ2Axx3bmTudq9koHT4575AeK31Wx2Pp", "proofs": [ "iHYKkeoCyjKPQLaS8DtkkmYFYP6yiRU5NPJXcUydicoQQqEwahYXLpKw3H8b7GPgTLcGi1GtoEKoqdCiTdiTrcG" ], "script": "base64:AAIFAAAAAAAAACkIAhIECgIICBIDCgEIEgMKAQgSBAoCCAgSAwoBCBIFCgMICAgSAwoBCAAAABUBAAAAEGdldFN0cmluZ09yVGhyb3cAAAACAAAAB2FkZHJlc3MAAAADa2V5CQEAAAATdmFsdWVPckVycm9yTWVzc2FnZQAAAAIJAAQdAAAAAgUAAAAHYWRkcmVzcwUAAAADa2V5CQABLAAAAAIJAAEsAAAAAgkAASwAAAACAgAAAAxDYW4ndCByZWFkICcFAAAAA2tleQIAAAANJyBhdCBhZGRyZXNzIAkABCUAAAABBQAAAAdhZGRyZXNzAQAAABFnZXRJbnRlZ2VyT3JUaHJvdwAAAAIAAAAHYWRkcmVzcwAAAANrZXkJAQAAABN2YWx1ZU9yRXJyb3JNZXNzYWdlAAAAAgkABBoAAAACBQAAAAdhZGRyZXNzBQAAAANrZXkJAAEsAAAAAgkAASwAAAACCQABLAAAAAICAAAADENhbid0IHJlYWQgJwUAAAADa2V5AgAAAA0nIGF0IGFkZHJlc3MgCQAEJQAAAAEFAAAAB2FkZHJlc3MBAAAAE3BhcnNlQWRkcmVzc09yVG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cmVhdGVkBwUAAAALbmFtZUNyZWF0ZWQFAAAABHVuaXQFAAAABHVuaXQEAAAAC25hbWVFeHBpcmVzBAAAAAckbWF0Y2gwCQEAAAAXX2NhbGxTdXBwb3J0ZWRJbnRlcmZhY2UAAAADBQAAAApyZWdpc3RyYW50AgAAAAtuYW1lRXhwaXJlcwUAAAAKcmVzdExhYmVscwMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAtuYW1lRXhwaXJlcwUAAAAHJG1hdGNoMAMJAABmAAAAAgUAAAALbmFtZUV4cGlyZXMAAAAAAAAAAAAFAAAAC25hbWVFeHBpcmVzBQAAAAR1bml0BQAAAAR1bml0BAAAAAppc1Jvb3ROYW1lAwkAAGYAAAACCQABMQAAAAEFAAAACWxhc3RMYWJlbAAAAAAAAAAAAAkAAAAAAAACCQABMQAAAAEFAAAACnJlc3RMYWJlbHMAAAAAAAAAAAAHAwMFAAAACmlzUm9vdE5hbWUGCQEAAAABIQAAAAEJAQAAAAlpc0RlZmluZWQAAAABBQAAAA9tYXliZVJlZ2lzdHJhbnQJAAUUAAAAAgUAAAADbmlsCQAFFgAAAAQFAAAAEXJlZ2lzdHJhbnRBZGRyZXNzBQAAAA5wYXJlbnRSZXNvbHZlcgUAAAANcGFyZW50Q3JlYXRlZAUAAAAEdW5pdAkABRQAAAACBQAAAANuaWwJAAUWAAAABAUAAAAFb3duZXIFAAAACHJlc29sdmVyBQAAAAtuYW1lQ3JlYXRlZAUAAAALbmFtZUV4cGlyZXMAAAAANe78uw==", "height": 2280924, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 8CfJRrbiFPx4hyb9GUP2pQy9asF8vnZ8SPUwgPVP3gD9 Next: HJs69bGWLZoxDjkYVFWb8CtmkRXR3TQnB3348YFQSrXm Diff:
Old | New | Differences | |
---|---|---|---|
13 | 13 | func key_entity (name,pk,property) = ((((name + "_") + pk) + "_") + property) | |
14 | 14 | ||
15 | 15 | ||
16 | - | func key_ | |
16 | + | func key_Name_owner (node) = key_entity("Name", node, "owner") | |
17 | 17 | ||
18 | 18 | ||
19 | - | func key_Name_ | |
19 | + | func key_Name_resolver (node) = key_entity("Name", node, "resolver") | |
20 | 20 | ||
21 | 21 | ||
22 | - | func key_Name_ | |
22 | + | func key_Name_createdAt (node) = key_entity("Name", node, "createdAt") | |
23 | 23 | ||
24 | 24 | ||
25 | - | func key_Name_ | |
25 | + | func _getOwner (node) = getString(this, key_Name_owner(node)) | |
26 | 26 | ||
27 | 27 | ||
28 | - | func key_Name_ | |
28 | + | func _setOwner (node,owner) = [StringEntry(key_Name_owner(node), owner)] | |
29 | 29 | ||
30 | 30 | ||
31 | - | func key_Name_ | |
31 | + | func _getResolver (node) = getString(this, key_Name_resolver(node)) | |
32 | 32 | ||
33 | 33 | ||
34 | - | let key_nameTTL = "nameTTL" | |
35 | - | ||
36 | - | let key_controllers = "controllers" | |
37 | - | ||
38 | - | func _setOwner (name,owner) = [StringEntry(key_Name_owner(name), owner)] | |
34 | + | func _setResolver (node,resolver) = [StringEntry(key_Name_resolver(node), resolver)] | |
39 | 35 | ||
40 | 36 | ||
41 | - | func _ | |
37 | + | func _getCreatedAt (node) = getInteger(this, key_Name_createdAt(node)) | |
42 | 38 | ||
43 | 39 | ||
44 | - | func _setResolver (name,resolver) = [StringEntry(key_Name_resolver(name), resolver)] | |
45 | - | ||
46 | - | ||
47 | - | func _getResolver (name) = getString(this, key_Name_resolver(name)) | |
48 | - | ||
49 | - | ||
50 | - | func _getToken (name) = getString(this, key_Name_token(name)) | |
51 | - | ||
52 | - | ||
53 | - | func _getCreatedAt (name) = getInteger(this, key_Name_createdAt(name)) | |
54 | - | ||
55 | - | ||
56 | - | func _getExpiresAt (name) = getInteger(this, key_Name_expiresAt(name)) | |
57 | - | ||
58 | - | ||
59 | - | func _getControllers () = getString(this, key_controllers) | |
60 | - | ||
61 | - | ||
62 | - | let controllers = match _getControllers() { | |
63 | - | case repr: String => | |
64 | - | split(repr, ",") | |
65 | - | case _ => | |
66 | - | nil | |
67 | - | } | |
68 | - | ||
69 | - | let nameTTL = getIntegerOrThrow(this, key_nameTTL) | |
70 | - | ||
71 | - | func isRegisteredName (name) = isDefined(getString(this, key_Name_token(name))) | |
72 | - | ||
73 | - | ||
74 | - | func isCreatedName (name) = isDefined(_getCreatedAt(name)) | |
75 | - | ||
76 | - | ||
77 | - | func isExpiredName (name) = match _getExpiresAt(name) { | |
78 | - | case expiresAt: Int => | |
79 | - | (lastBlock.timestamp > expiresAt) | |
80 | - | case _ => | |
81 | - | false | |
82 | - | } | |
83 | - | ||
84 | - | ||
85 | - | func isActiveName (name) = if (if (isRegisteredName(name)) | |
86 | - | then isCreatedName(name) | |
87 | - | else false) | |
88 | - | then !(isExpiredName(name)) | |
89 | - | else false | |
90 | - | ||
91 | - | ||
92 | - | func isValidName (name) = { | |
93 | - | let symbols = "abcdefghijklmnopqrstuvwxyz1234567890-" | |
94 | - | func validateChars (isValid,char) = if (isValid) | |
95 | - | then contains(symbols, char) | |
96 | - | else false | |
97 | - | ||
98 | - | if (if (if (if (if ((size(name) > 0)) | |
99 | - | then (63 >= size(name)) | |
100 | - | else false) | |
101 | - | then (indexOf(name, "--") != 2) | |
102 | - | else false) | |
103 | - | then (indexOf(name, "-") != 0) | |
104 | - | else false) | |
105 | - | then (lastIndexOf(name, "-") != (size(name) - 1)) | |
106 | - | else false) | |
107 | - | then { | |
108 | - | let $l = split(name, "") | |
109 | - | let $s = size($l) | |
110 | - | let $acc0 = true | |
111 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
112 | - | then $a | |
113 | - | else validateChars($a, $l[$i]) | |
114 | - | ||
115 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
116 | - | then $a | |
117 | - | else throw("List size exceeds 63") | |
118 | - | ||
119 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 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) | |
120 | - | } | |
121 | - | else false | |
122 | - | } | |
123 | - | ||
124 | - | ||
125 | - | func isAvailableName (name) = if (isValidName(name)) | |
126 | - | then if (!(isRegisteredName(name))) | |
127 | - | then true | |
128 | - | else isExpiredName(name) | |
129 | - | else false | |
130 | - | ||
131 | - | ||
132 | - | func isValidAddress (maybeAddress) = isDefined(addressFromString(maybeAddress)) | |
40 | + | func _setCreatedAt (node,createdAt) = [IntegerEntry(key_Name_createdAt(node), createdAt)] | |
133 | 41 | ||
134 | 42 | ||
135 | 43 | func isAdmin (inv) = (inv.caller == this) | |
136 | 44 | ||
137 | 45 | ||
138 | - | func isOwner (inv, | |
46 | + | func isOwner (inv,node) = (toString(inv.caller) == valueOrElse(_getOwner(node), "")) | |
139 | 47 | ||
140 | 48 | ||
141 | - | func | |
49 | + | func isValidAddress (maybeAddress) = isDefined(addressFromString(maybeAddress)) | |
142 | 50 | ||
143 | 51 | ||
144 | 52 | func _splitLastLabel (name) = { | |
150 | 58 | } | |
151 | 59 | ||
152 | 60 | ||
153 | - | func _issueNameToken (name) = [Issue(if ((size(name) > 16)) | |
154 | - | then (take(name, 15) + "~") | |
155 | - | else take(name, 16), (name + ".waves"), 1, 0, false)] | |
156 | - | ||
157 | - | ||
158 | - | func _registerNameWithToken (name,tokenId,createdAt) = [StringEntry(key_Name_token(name), tokenId), StringEntry(key_Token_name(tokenId), name), IntegerEntry(key_Name_createdAt(name), createdAt), IntegerEntry(key_Name_expiresAt(name), (createdAt + nameTTL))] | |
159 | - | ||
160 | - | ||
161 | - | func _restoreNameWithToken (name,tokenId) = [StringEntry(key_Name_token(name), tokenId), StringEntry(key_Token_name(tokenId), name)] | |
162 | - | ||
163 | - | ||
164 | - | func _transferTokenToOwner (tokenId,owner) = [ScriptTransfer(parseAddressOrThrow(owner), 1, fromBase58String(tokenId))] | |
61 | + | func _callSupportedInterface (registrant,interfaceId,restLabels) = match invoke(registrant, "supportsInterface", [interfaceId], nil) { | |
62 | + | case supportsInterface: Boolean => | |
63 | + | if (!(supportsInterface)) | |
64 | + | then unit | |
65 | + | else match invoke(value(registrant), interfaceId, [restLabels], nil) { | |
66 | + | case maybeString: String => | |
67 | + | maybeString | |
68 | + | case maybeInt: Int => | |
69 | + | maybeInt | |
70 | + | case _ => | |
71 | + | unit | |
72 | + | } | |
73 | + | case _ => | |
74 | + | unit | |
75 | + | } | |
165 | 76 | ||
166 | 77 | ||
167 | 78 | func modifiers (validations) = unit | |
172 | 83 | else throw("Permission denied") | |
173 | 84 | ||
174 | 85 | ||
175 | - | func | |
86 | + | func onlyOwner (inv,node) = if (if (isAdmin(inv)) | |
176 | 87 | then true | |
177 | - | else isController(toString(inv.caller))) | |
178 | - | then unit | |
179 | - | else throw("Permission denied") | |
180 | - | ||
181 | - | ||
182 | - | func onlyOwner (inv,name) = if (if (isAdmin(inv)) | |
183 | - | then true | |
184 | - | else isOwner(inv, name)) | |
88 | + | else isOwner(inv, node)) | |
185 | 89 | then unit | |
186 | 90 | else throw("Permission denied") | |
187 | 91 | ||
188 | 92 | ||
189 | 93 | @Callable(inv) | |
190 | - | func | |
94 | + | func setOwner (node,owner) = valueOrElse(modifiers([onlyOwner(inv, node), if (isValidAddress(owner)) | |
191 | 95 | then unit | |
192 | - | else throw(" | |
96 | + | else throw("Owner must be a valid address")]), _setOwner(node, owner)) | |
193 | 97 | ||
194 | 98 | ||
195 | 99 | ||
196 | 100 | @Callable(inv) | |
197 | - | func | |
101 | + | func owner (node) = $Tuple2(nil, _getOwner(node)) | |
198 | 102 | ||
199 | 103 | ||
200 | 104 | ||
201 | 105 | @Callable(inv) | |
202 | - | func addController (address) = valueOrElse(modifiers([onlyAdmin(inv), if (isValidAddress(address)) | |
203 | - | then unit | |
204 | - | else throw("Controller must be a valid address"), if (!(isController(address))) | |
205 | - | then unit | |
206 | - | else throw((("Controller `" + address) + "` is already registered"))]), [StringEntry(key_controllers, makeString((controllers :+ address), ","))]) | |
106 | + | func resolver (node) = $Tuple2(nil, _getResolver(node)) | |
207 | 107 | ||
208 | 108 | ||
209 | 109 | ||
210 | 110 | @Callable(inv) | |
211 | - | func | |
111 | + | func setResolver (node,resolver) = valueOrElse(modifiers([onlyOwner(inv, node), if (isValidAddress(resolver)) | |
212 | 112 | then unit | |
213 | - | else throw((("Controller `" + address) + "` is not registered"))]), { | |
214 | - | let controllerIndex = value(indexOf(controllers, address)) | |
215 | - | [StringEntry(key_controllers, makeString(removeByIndex(controllers, controllerIndex), ","))] | |
216 | - | }) | |
113 | + | else throw("Resolver must be a valid contract address")]), _setResolver(node, resolver)) | |
217 | 114 | ||
218 | 115 | ||
219 | 116 | ||
220 | 117 | @Callable(inv) | |
221 | - | func | |
118 | + | func nameCreated (node) = $Tuple2(nil, _getCreatedAt(node)) | |
222 | 119 | ||
223 | 120 | ||
224 | 121 | ||
225 | 122 | @Callable(inv) | |
226 | - | func | |
123 | + | func setRecord (node,owner,resolver) = valueOrElse(modifiers([onlyAdmin(inv)]), ((_setOwner(node, owner) ++ _setResolver(node, resolver)) ++ _setCreatedAt(node, lastBlock.timestamp))) | |
227 | 124 | ||
228 | 125 | ||
229 | 126 | ||
230 | 127 | @Callable(inv) | |
231 | - | func owner (name) = $Tuple2(nil, _getOwner(_splitLastLabel(name)._1)) | |
232 | - | ||
233 | - | ||
234 | - | ||
235 | - | @Callable(inv) | |
236 | - | func resolver (name) = $Tuple2(nil, _getResolver(_splitLastLabel(name)._1)) | |
237 | - | ||
238 | - | ||
239 | - | ||
240 | - | @Callable(inv) | |
241 | - | func setResolver (name,resolver) = valueOrElse(modifiers([if (isActiveName(name)) | |
128 | + | func whoIs (name) = valueOrElse(modifiers([if ((size(name) > 0)) | |
242 | 129 | then unit | |
243 | - | else throw("Name expired or not registered"), onlyOwner(inv, name), if (isValidAddress(resolver)) | |
244 | - | then unit | |
245 | - | else throw("Resolver must be a valid contract address")]), $Tuple2(nil, _setResolver(name, resolver))) | |
246 | - | ||
247 | - | ||
248 | - | ||
249 | - | @Callable(inv) | |
250 | - | func nameCreated (name) = $Tuple2(nil, _getCreatedAt(_splitLastLabel(name)._1)) | |
251 | - | ||
252 | - | ||
253 | - | ||
254 | - | @Callable(inv) | |
255 | - | func nameExpires (name) = $Tuple2(nil, _getExpiresAt(_splitLastLabel(name)._1)) | |
256 | - | ||
257 | - | ||
258 | - | ||
259 | - | @Callable(inv) | |
260 | - | func register (name,owner,createdAt) = valueOrElse(modifiers([onlyController(inv), if (isAvailableName(name)) | |
261 | - | then unit | |
262 | - | else throw((("`" + name) + "` cannot be registered")), if (isValidAddress(owner)) | |
263 | - | then unit | |
264 | - | else throw("Owner must be a valid address"), if ((createdAt > 0)) | |
265 | - | then unit | |
266 | - | else throw("CreatedAt cannot be negative"), if ((lastBlock.timestamp >= createdAt)) | |
267 | - | then unit | |
268 | - | else throw("CreatedAt cannot be in the future")]), { | |
269 | - | let issueNameToken = _issueNameToken(name) | |
270 | - | let tokenId = calculateAssetId(issueNameToken[0]) | |
271 | - | let tokenStr = toBase58String(tokenId) | |
272 | - | let registerNameWithToken = _registerNameWithToken(name, tokenStr, createdAt) | |
273 | - | let transferTokenToOwner = _transferTokenToOwner(tokenStr, owner) | |
274 | - | let setOwnership = _setOwner(name, owner) | |
275 | - | (((issueNameToken ++ registerNameWithToken) ++ transferTokenToOwner) ++ setOwnership) | |
276 | - | }) | |
277 | - | ||
278 | - | ||
279 | - | ||
280 | - | @Callable(inv) | |
281 | - | func reclaim (name) = valueOrElse(modifiers([if (isActiveName(name)) | |
282 | - | then unit | |
283 | - | else throw((("`" + name) + "` is not active"))]), { | |
284 | - | let newOwner = inv.caller | |
285 | - | let newOwnerAddress = toString(newOwner) | |
286 | - | let tokenStr = valueOrErrorMessage(_getToken(name), (("No token is issued for `" + name) + "`")) | |
287 | - | let tokenId = fromBase58String(tokenStr) | |
288 | - | let hasToken = (assetBalance(newOwner, tokenId) == 1) | |
289 | - | let isTokenOwner = isOwner(inv, name) | |
290 | - | let isTokenExists = match assetInfo(tokenId) { | |
291 | - | case token: Asset => | |
292 | - | (token.quantity == 1) | |
130 | + | else throw("Name cannot be empty")]), { | |
131 | + | let $t043014352 = _splitLastLabel(name) | |
132 | + | let lastLabel = $t043014352._1 | |
133 | + | let restLabels = $t043014352._2 | |
134 | + | let registrantAddress = _getOwner(lastLabel) | |
135 | + | let maybeRegistrant = match registrantAddress { | |
136 | + | case owner: String => | |
137 | + | addressFromString(owner) | |
293 | 138 | case _ => | |
294 | - | | |
139 | + | unit | |
295 | 140 | } | |
296 | - | if (if (isTokenOwner) | |
297 | - | then !(isTokenExists) | |
298 | - | else false) | |
299 | - | then { | |
300 | - | let issueNewToken = _issueNameToken(name) | |
301 | - | let newTokenId = calculateAssetId(issueNewToken[0]) | |
302 | - | let newTokenStr = toBase58String(newTokenId) | |
303 | - | let restoreNameWithNewToken = _restoreNameWithToken(name, newTokenStr) | |
304 | - | let transferNewTokenToOwner = _transferTokenToOwner(newTokenStr, newOwnerAddress) | |
305 | - | ((issueNewToken ++ restoreNameWithNewToken) ++ transferNewTokenToOwner) | |
306 | - | } | |
307 | - | else if (if (isTokenOwner) | |
308 | - | then hasToken | |
309 | - | else false) | |
310 | - | then throw("You already own a name token") | |
311 | - | else if (!(hasToken)) | |
312 | - | then throw("You don't have a name token") | |
313 | - | else _setOwner(name, newOwnerAddress) | |
141 | + | let registrant = value(maybeRegistrant) | |
142 | + | let parentResolver = _getResolver(lastLabel) | |
143 | + | let parentCreated = _getCreatedAt(lastLabel) | |
144 | + | let owner = match _callSupportedInterface(registrant, "owner", restLabels) { | |
145 | + | case owner: String => | |
146 | + | if (isValidAddress(owner)) | |
147 | + | then owner | |
148 | + | else unit | |
149 | + | case _ => | |
150 | + | unit | |
151 | + | } | |
152 | + | let resolver = match _callSupportedInterface(registrant, "resolver", restLabels) { | |
153 | + | case resolver: String => | |
154 | + | if (isValidAddress(resolver)) | |
155 | + | then resolver | |
156 | + | else unit | |
157 | + | case _ => | |
158 | + | unit | |
159 | + | } | |
160 | + | let nameCreated = match _callSupportedInterface(registrant, "nameCreated", restLabels) { | |
161 | + | case nameCreated: Int => | |
162 | + | if (if ((nameCreated > 0)) | |
163 | + | then (lastBlock.timestamp > nameCreated) | |
164 | + | else false) | |
165 | + | then nameCreated | |
166 | + | else unit | |
167 | + | case _ => | |
168 | + | unit | |
169 | + | } | |
170 | + | let nameExpires = match _callSupportedInterface(registrant, "nameExpires", restLabels) { | |
171 | + | case nameExpires: Int => | |
172 | + | if ((nameExpires > 0)) | |
173 | + | then nameExpires | |
174 | + | else unit | |
175 | + | case _ => | |
176 | + | unit | |
177 | + | } | |
178 | + | let isRootName = if ((size(lastLabel) > 0)) | |
179 | + | then (size(restLabels) == 0) | |
180 | + | else false | |
181 | + | if (if (isRootName) | |
182 | + | then true | |
183 | + | else !(isDefined(maybeRegistrant))) | |
184 | + | then $Tuple2(nil, $Tuple4(registrantAddress, parentResolver, parentCreated, unit)) | |
185 | + | else $Tuple2(nil, $Tuple4(owner, resolver, nameCreated, nameExpires)) | |
314 | 186 | }) | |
315 | 187 | ||
316 | 188 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | func getStringOrThrow (address,key) = valueOrErrorMessage(getString(address, key), ((("Can't read '" + key) + "' at address ") + toString(address))) | |
5 | 5 | ||
6 | 6 | ||
7 | 7 | func getIntegerOrThrow (address,key) = valueOrErrorMessage(getInteger(address, key), ((("Can't read '" + key) + "' at address ") + toString(address))) | |
8 | 8 | ||
9 | 9 | ||
10 | 10 | func parseAddressOrThrow (maybeAddress) = valueOrErrorMessage(addressFromString(maybeAddress), (("Can't parse address from '" + maybeAddress) + "'")) | |
11 | 11 | ||
12 | 12 | ||
13 | 13 | func key_entity (name,pk,property) = ((((name + "_") + pk) + "_") + property) | |
14 | 14 | ||
15 | 15 | ||
16 | - | func key_ | |
16 | + | func key_Name_owner (node) = key_entity("Name", node, "owner") | |
17 | 17 | ||
18 | 18 | ||
19 | - | func key_Name_ | |
19 | + | func key_Name_resolver (node) = key_entity("Name", node, "resolver") | |
20 | 20 | ||
21 | 21 | ||
22 | - | func key_Name_ | |
22 | + | func key_Name_createdAt (node) = key_entity("Name", node, "createdAt") | |
23 | 23 | ||
24 | 24 | ||
25 | - | func key_Name_ | |
25 | + | func _getOwner (node) = getString(this, key_Name_owner(node)) | |
26 | 26 | ||
27 | 27 | ||
28 | - | func key_Name_ | |
28 | + | func _setOwner (node,owner) = [StringEntry(key_Name_owner(node), owner)] | |
29 | 29 | ||
30 | 30 | ||
31 | - | func key_Name_ | |
31 | + | func _getResolver (node) = getString(this, key_Name_resolver(node)) | |
32 | 32 | ||
33 | 33 | ||
34 | - | let key_nameTTL = "nameTTL" | |
35 | - | ||
36 | - | let key_controllers = "controllers" | |
37 | - | ||
38 | - | func _setOwner (name,owner) = [StringEntry(key_Name_owner(name), owner)] | |
34 | + | func _setResolver (node,resolver) = [StringEntry(key_Name_resolver(node), resolver)] | |
39 | 35 | ||
40 | 36 | ||
41 | - | func _ | |
37 | + | func _getCreatedAt (node) = getInteger(this, key_Name_createdAt(node)) | |
42 | 38 | ||
43 | 39 | ||
44 | - | func _setResolver (name,resolver) = [StringEntry(key_Name_resolver(name), resolver)] | |
45 | - | ||
46 | - | ||
47 | - | func _getResolver (name) = getString(this, key_Name_resolver(name)) | |
48 | - | ||
49 | - | ||
50 | - | func _getToken (name) = getString(this, key_Name_token(name)) | |
51 | - | ||
52 | - | ||
53 | - | func _getCreatedAt (name) = getInteger(this, key_Name_createdAt(name)) | |
54 | - | ||
55 | - | ||
56 | - | func _getExpiresAt (name) = getInteger(this, key_Name_expiresAt(name)) | |
57 | - | ||
58 | - | ||
59 | - | func _getControllers () = getString(this, key_controllers) | |
60 | - | ||
61 | - | ||
62 | - | let controllers = match _getControllers() { | |
63 | - | case repr: String => | |
64 | - | split(repr, ",") | |
65 | - | case _ => | |
66 | - | nil | |
67 | - | } | |
68 | - | ||
69 | - | let nameTTL = getIntegerOrThrow(this, key_nameTTL) | |
70 | - | ||
71 | - | func isRegisteredName (name) = isDefined(getString(this, key_Name_token(name))) | |
72 | - | ||
73 | - | ||
74 | - | func isCreatedName (name) = isDefined(_getCreatedAt(name)) | |
75 | - | ||
76 | - | ||
77 | - | func isExpiredName (name) = match _getExpiresAt(name) { | |
78 | - | case expiresAt: Int => | |
79 | - | (lastBlock.timestamp > expiresAt) | |
80 | - | case _ => | |
81 | - | false | |
82 | - | } | |
83 | - | ||
84 | - | ||
85 | - | func isActiveName (name) = if (if (isRegisteredName(name)) | |
86 | - | then isCreatedName(name) | |
87 | - | else false) | |
88 | - | then !(isExpiredName(name)) | |
89 | - | else false | |
90 | - | ||
91 | - | ||
92 | - | func isValidName (name) = { | |
93 | - | let symbols = "abcdefghijklmnopqrstuvwxyz1234567890-" | |
94 | - | func validateChars (isValid,char) = if (isValid) | |
95 | - | then contains(symbols, char) | |
96 | - | else false | |
97 | - | ||
98 | - | if (if (if (if (if ((size(name) > 0)) | |
99 | - | then (63 >= size(name)) | |
100 | - | else false) | |
101 | - | then (indexOf(name, "--") != 2) | |
102 | - | else false) | |
103 | - | then (indexOf(name, "-") != 0) | |
104 | - | else false) | |
105 | - | then (lastIndexOf(name, "-") != (size(name) - 1)) | |
106 | - | else false) | |
107 | - | then { | |
108 | - | let $l = split(name, "") | |
109 | - | let $s = size($l) | |
110 | - | let $acc0 = true | |
111 | - | func $f0_1 ($a,$i) = if (($i >= $s)) | |
112 | - | then $a | |
113 | - | else validateChars($a, $l[$i]) | |
114 | - | ||
115 | - | func $f0_2 ($a,$i) = if (($i >= $s)) | |
116 | - | then $a | |
117 | - | else throw("List size exceeds 63") | |
118 | - | ||
119 | - | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 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) | |
120 | - | } | |
121 | - | else false | |
122 | - | } | |
123 | - | ||
124 | - | ||
125 | - | func isAvailableName (name) = if (isValidName(name)) | |
126 | - | then if (!(isRegisteredName(name))) | |
127 | - | then true | |
128 | - | else isExpiredName(name) | |
129 | - | else false | |
130 | - | ||
131 | - | ||
132 | - | func isValidAddress (maybeAddress) = isDefined(addressFromString(maybeAddress)) | |
40 | + | func _setCreatedAt (node,createdAt) = [IntegerEntry(key_Name_createdAt(node), createdAt)] | |
133 | 41 | ||
134 | 42 | ||
135 | 43 | func isAdmin (inv) = (inv.caller == this) | |
136 | 44 | ||
137 | 45 | ||
138 | - | func isOwner (inv, | |
46 | + | func isOwner (inv,node) = (toString(inv.caller) == valueOrElse(_getOwner(node), "")) | |
139 | 47 | ||
140 | 48 | ||
141 | - | func | |
49 | + | func isValidAddress (maybeAddress) = isDefined(addressFromString(maybeAddress)) | |
142 | 50 | ||
143 | 51 | ||
144 | 52 | func _splitLastLabel (name) = { | |
145 | 53 | let labels = split(name, ".") | |
146 | 54 | let lastIndex = (size(labels) - 1) | |
147 | 55 | let lastLabel = labels[lastIndex] | |
148 | 56 | let restLabels = makeString(removeByIndex(labels, lastIndex), ".") | |
149 | 57 | $Tuple2(lastLabel, restLabels) | |
150 | 58 | } | |
151 | 59 | ||
152 | 60 | ||
153 | - | func _issueNameToken (name) = [Issue(if ((size(name) > 16)) | |
154 | - | then (take(name, 15) + "~") | |
155 | - | else take(name, 16), (name + ".waves"), 1, 0, false)] | |
156 | - | ||
157 | - | ||
158 | - | func _registerNameWithToken (name,tokenId,createdAt) = [StringEntry(key_Name_token(name), tokenId), StringEntry(key_Token_name(tokenId), name), IntegerEntry(key_Name_createdAt(name), createdAt), IntegerEntry(key_Name_expiresAt(name), (createdAt + nameTTL))] | |
159 | - | ||
160 | - | ||
161 | - | func _restoreNameWithToken (name,tokenId) = [StringEntry(key_Name_token(name), tokenId), StringEntry(key_Token_name(tokenId), name)] | |
162 | - | ||
163 | - | ||
164 | - | func _transferTokenToOwner (tokenId,owner) = [ScriptTransfer(parseAddressOrThrow(owner), 1, fromBase58String(tokenId))] | |
61 | + | func _callSupportedInterface (registrant,interfaceId,restLabels) = match invoke(registrant, "supportsInterface", [interfaceId], nil) { | |
62 | + | case supportsInterface: Boolean => | |
63 | + | if (!(supportsInterface)) | |
64 | + | then unit | |
65 | + | else match invoke(value(registrant), interfaceId, [restLabels], nil) { | |
66 | + | case maybeString: String => | |
67 | + | maybeString | |
68 | + | case maybeInt: Int => | |
69 | + | maybeInt | |
70 | + | case _ => | |
71 | + | unit | |
72 | + | } | |
73 | + | case _ => | |
74 | + | unit | |
75 | + | } | |
165 | 76 | ||
166 | 77 | ||
167 | 78 | func modifiers (validations) = unit | |
168 | 79 | ||
169 | 80 | ||
170 | 81 | func onlyAdmin (inv) = if (isAdmin(inv)) | |
171 | 82 | then unit | |
172 | 83 | else throw("Permission denied") | |
173 | 84 | ||
174 | 85 | ||
175 | - | func | |
86 | + | func onlyOwner (inv,node) = if (if (isAdmin(inv)) | |
176 | 87 | then true | |
177 | - | else isController(toString(inv.caller))) | |
178 | - | then unit | |
179 | - | else throw("Permission denied") | |
180 | - | ||
181 | - | ||
182 | - | func onlyOwner (inv,name) = if (if (isAdmin(inv)) | |
183 | - | then true | |
184 | - | else isOwner(inv, name)) | |
88 | + | else isOwner(inv, node)) | |
185 | 89 | then unit | |
186 | 90 | else throw("Permission denied") | |
187 | 91 | ||
188 | 92 | ||
189 | 93 | @Callable(inv) | |
190 | - | func | |
94 | + | func setOwner (node,owner) = valueOrElse(modifiers([onlyOwner(inv, node), if (isValidAddress(owner)) | |
191 | 95 | then unit | |
192 | - | else throw(" | |
96 | + | else throw("Owner must be a valid address")]), _setOwner(node, owner)) | |
193 | 97 | ||
194 | 98 | ||
195 | 99 | ||
196 | 100 | @Callable(inv) | |
197 | - | func | |
101 | + | func owner (node) = $Tuple2(nil, _getOwner(node)) | |
198 | 102 | ||
199 | 103 | ||
200 | 104 | ||
201 | 105 | @Callable(inv) | |
202 | - | func addController (address) = valueOrElse(modifiers([onlyAdmin(inv), if (isValidAddress(address)) | |
203 | - | then unit | |
204 | - | else throw("Controller must be a valid address"), if (!(isController(address))) | |
205 | - | then unit | |
206 | - | else throw((("Controller `" + address) + "` is already registered"))]), [StringEntry(key_controllers, makeString((controllers :+ address), ","))]) | |
106 | + | func resolver (node) = $Tuple2(nil, _getResolver(node)) | |
207 | 107 | ||
208 | 108 | ||
209 | 109 | ||
210 | 110 | @Callable(inv) | |
211 | - | func | |
111 | + | func setResolver (node,resolver) = valueOrElse(modifiers([onlyOwner(inv, node), if (isValidAddress(resolver)) | |
212 | 112 | then unit | |
213 | - | else throw((("Controller `" + address) + "` is not registered"))]), { | |
214 | - | let controllerIndex = value(indexOf(controllers, address)) | |
215 | - | [StringEntry(key_controllers, makeString(removeByIndex(controllers, controllerIndex), ","))] | |
216 | - | }) | |
113 | + | else throw("Resolver must be a valid contract address")]), _setResolver(node, resolver)) | |
217 | 114 | ||
218 | 115 | ||
219 | 116 | ||
220 | 117 | @Callable(inv) | |
221 | - | func | |
118 | + | func nameCreated (node) = $Tuple2(nil, _getCreatedAt(node)) | |
222 | 119 | ||
223 | 120 | ||
224 | 121 | ||
225 | 122 | @Callable(inv) | |
226 | - | func | |
123 | + | func setRecord (node,owner,resolver) = valueOrElse(modifiers([onlyAdmin(inv)]), ((_setOwner(node, owner) ++ _setResolver(node, resolver)) ++ _setCreatedAt(node, lastBlock.timestamp))) | |
227 | 124 | ||
228 | 125 | ||
229 | 126 | ||
230 | 127 | @Callable(inv) | |
231 | - | func owner (name) = $Tuple2(nil, _getOwner(_splitLastLabel(name)._1)) | |
232 | - | ||
233 | - | ||
234 | - | ||
235 | - | @Callable(inv) | |
236 | - | func resolver (name) = $Tuple2(nil, _getResolver(_splitLastLabel(name)._1)) | |
237 | - | ||
238 | - | ||
239 | - | ||
240 | - | @Callable(inv) | |
241 | - | func setResolver (name,resolver) = valueOrElse(modifiers([if (isActiveName(name)) | |
128 | + | func whoIs (name) = valueOrElse(modifiers([if ((size(name) > 0)) | |
242 | 129 | then unit | |
243 | - | else throw("Name expired or not registered"), onlyOwner(inv, name), if (isValidAddress(resolver)) | |
244 | - | then unit | |
245 | - | else throw("Resolver must be a valid contract address")]), $Tuple2(nil, _setResolver(name, resolver))) | |
246 | - | ||
247 | - | ||
248 | - | ||
249 | - | @Callable(inv) | |
250 | - | func nameCreated (name) = $Tuple2(nil, _getCreatedAt(_splitLastLabel(name)._1)) | |
251 | - | ||
252 | - | ||
253 | - | ||
254 | - | @Callable(inv) | |
255 | - | func nameExpires (name) = $Tuple2(nil, _getExpiresAt(_splitLastLabel(name)._1)) | |
256 | - | ||
257 | - | ||
258 | - | ||
259 | - | @Callable(inv) | |
260 | - | func register (name,owner,createdAt) = valueOrElse(modifiers([onlyController(inv), if (isAvailableName(name)) | |
261 | - | then unit | |
262 | - | else throw((("`" + name) + "` cannot be registered")), if (isValidAddress(owner)) | |
263 | - | then unit | |
264 | - | else throw("Owner must be a valid address"), if ((createdAt > 0)) | |
265 | - | then unit | |
266 | - | else throw("CreatedAt cannot be negative"), if ((lastBlock.timestamp >= createdAt)) | |
267 | - | then unit | |
268 | - | else throw("CreatedAt cannot be in the future")]), { | |
269 | - | let issueNameToken = _issueNameToken(name) | |
270 | - | let tokenId = calculateAssetId(issueNameToken[0]) | |
271 | - | let tokenStr = toBase58String(tokenId) | |
272 | - | let registerNameWithToken = _registerNameWithToken(name, tokenStr, createdAt) | |
273 | - | let transferTokenToOwner = _transferTokenToOwner(tokenStr, owner) | |
274 | - | let setOwnership = _setOwner(name, owner) | |
275 | - | (((issueNameToken ++ registerNameWithToken) ++ transferTokenToOwner) ++ setOwnership) | |
276 | - | }) | |
277 | - | ||
278 | - | ||
279 | - | ||
280 | - | @Callable(inv) | |
281 | - | func reclaim (name) = valueOrElse(modifiers([if (isActiveName(name)) | |
282 | - | then unit | |
283 | - | else throw((("`" + name) + "` is not active"))]), { | |
284 | - | let newOwner = inv.caller | |
285 | - | let newOwnerAddress = toString(newOwner) | |
286 | - | let tokenStr = valueOrErrorMessage(_getToken(name), (("No token is issued for `" + name) + "`")) | |
287 | - | let tokenId = fromBase58String(tokenStr) | |
288 | - | let hasToken = (assetBalance(newOwner, tokenId) == 1) | |
289 | - | let isTokenOwner = isOwner(inv, name) | |
290 | - | let isTokenExists = match assetInfo(tokenId) { | |
291 | - | case token: Asset => | |
292 | - | (token.quantity == 1) | |
130 | + | else throw("Name cannot be empty")]), { | |
131 | + | let $t043014352 = _splitLastLabel(name) | |
132 | + | let lastLabel = $t043014352._1 | |
133 | + | let restLabels = $t043014352._2 | |
134 | + | let registrantAddress = _getOwner(lastLabel) | |
135 | + | let maybeRegistrant = match registrantAddress { | |
136 | + | case owner: String => | |
137 | + | addressFromString(owner) | |
293 | 138 | case _ => | |
294 | - | | |
139 | + | unit | |
295 | 140 | } | |
296 | - | if (if (isTokenOwner) | |
297 | - | then !(isTokenExists) | |
298 | - | else false) | |
299 | - | then { | |
300 | - | let issueNewToken = _issueNameToken(name) | |
301 | - | let newTokenId = calculateAssetId(issueNewToken[0]) | |
302 | - | let newTokenStr = toBase58String(newTokenId) | |
303 | - | let restoreNameWithNewToken = _restoreNameWithToken(name, newTokenStr) | |
304 | - | let transferNewTokenToOwner = _transferTokenToOwner(newTokenStr, newOwnerAddress) | |
305 | - | ((issueNewToken ++ restoreNameWithNewToken) ++ transferNewTokenToOwner) | |
306 | - | } | |
307 | - | else if (if (isTokenOwner) | |
308 | - | then hasToken | |
309 | - | else false) | |
310 | - | then throw("You already own a name token") | |
311 | - | else if (!(hasToken)) | |
312 | - | then throw("You don't have a name token") | |
313 | - | else _setOwner(name, newOwnerAddress) | |
141 | + | let registrant = value(maybeRegistrant) | |
142 | + | let parentResolver = _getResolver(lastLabel) | |
143 | + | let parentCreated = _getCreatedAt(lastLabel) | |
144 | + | let owner = match _callSupportedInterface(registrant, "owner", restLabels) { | |
145 | + | case owner: String => | |
146 | + | if (isValidAddress(owner)) | |
147 | + | then owner | |
148 | + | else unit | |
149 | + | case _ => | |
150 | + | unit | |
151 | + | } | |
152 | + | let resolver = match _callSupportedInterface(registrant, "resolver", restLabels) { | |
153 | + | case resolver: String => | |
154 | + | if (isValidAddress(resolver)) | |
155 | + | then resolver | |
156 | + | else unit | |
157 | + | case _ => | |
158 | + | unit | |
159 | + | } | |
160 | + | let nameCreated = match _callSupportedInterface(registrant, "nameCreated", restLabels) { | |
161 | + | case nameCreated: Int => | |
162 | + | if (if ((nameCreated > 0)) | |
163 | + | then (lastBlock.timestamp > nameCreated) | |
164 | + | else false) | |
165 | + | then nameCreated | |
166 | + | else unit | |
167 | + | case _ => | |
168 | + | unit | |
169 | + | } | |
170 | + | let nameExpires = match _callSupportedInterface(registrant, "nameExpires", restLabels) { | |
171 | + | case nameExpires: Int => | |
172 | + | if ((nameExpires > 0)) | |
173 | + | then nameExpires | |
174 | + | else unit | |
175 | + | case _ => | |
176 | + | unit | |
177 | + | } | |
178 | + | let isRootName = if ((size(lastLabel) > 0)) | |
179 | + | then (size(restLabels) == 0) | |
180 | + | else false | |
181 | + | if (if (isRootName) | |
182 | + | then true | |
183 | + | else !(isDefined(maybeRegistrant))) | |
184 | + | then $Tuple2(nil, $Tuple4(registrantAddress, parentResolver, parentCreated, unit)) | |
185 | + | else $Tuple2(nil, $Tuple4(owner, resolver, nameCreated, nameExpires)) | |
314 | 186 | }) | |
315 | 187 | ||
316 | 188 |
github/deemru/w8io/026f985 70.85 ms ◑