1 | | - | {-# STDLIB_VERSION 5 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let key_registry = "registry" |
---|
5 | | - | |
---|
6 | | - | let registry = valueOrErrorMessage(addressFromString(value(getString(this, key_registry))), "Registry is not valid address") |
---|
7 | | - | |
---|
8 | | - | let isInitialized = isDefined(getString(this, key_registry)) |
---|
9 | | - | |
---|
10 | | - | func isAdmin (inv) = (inv.caller == this) |
---|
11 | | - | |
---|
12 | | - | |
---|
13 | | - | func isValidAddress (maybeAddress) = isDefined(addressFromString(maybeAddress)) |
---|
14 | | - | |
---|
15 | | - | |
---|
16 | | - | func modifiers (validations) = unit |
---|
17 | | - | |
---|
18 | | - | |
---|
19 | | - | func onlyAdmin (inv) = if (isAdmin(inv)) |
---|
20 | | - | then unit |
---|
21 | | - | else throw("Permission denied") |
---|
22 | | - | |
---|
23 | | - | |
---|
24 | | - | func onlyInitialized () = if (isInitialized) |
---|
25 | | - | then unit |
---|
26 | | - | else throw("Contract is not initialized") |
---|
27 | | - | |
---|
28 | | - | |
---|
29 | | - | func _splitLastLabel (name) = { |
---|
30 | | - | let labels = split(name, ".") |
---|
31 | | - | let lastIndex = (size(labels) - 1) |
---|
32 | | - | let lastLabel = labels[lastIndex] |
---|
33 | | - | let restLabels = makeString(removeByIndex(labels, lastIndex), ".") |
---|
34 | | - | $Tuple2(lastLabel, restLabels) |
---|
35 | | - | } |
---|
36 | | - | |
---|
37 | | - | |
---|
38 | | - | func _findResolver (name) = { |
---|
39 | | - | let $t012621313 = _splitLastLabel(name) |
---|
40 | | - | let lastLabel = $t012621313._1 |
---|
41 | | - | let restLabels = $t012621313._2 |
---|
42 | | - | let throwIf = !(isDefined(registry)) |
---|
43 | | - | if ((throwIf == throwIf)) |
---|
44 | | - | then if ((size(restLabels) == 0)) |
---|
45 | | - | then $Tuple2(unit, name) |
---|
46 | | - | else match invoke(registry, "getResolver", [lastLabel], nil) { |
---|
47 | | - | case resolverAddress: String => |
---|
48 | | - | $Tuple2(addressFromString(resolverAddress), restLabels) |
---|
49 | | - | case _ => |
---|
50 | | - | $Tuple2(unit, name) |
---|
51 | | - | } |
---|
52 | | - | else throw("Strict value is not equal to itself.") |
---|
53 | | - | } |
---|
54 | | - | |
---|
55 | | - | |
---|
56 | | - | @Callable(inv) |
---|
57 | | - | func init (registryAddress) = valueOrElse(modifiers([onlyAdmin(inv), if (isValidAddress(registryAddress)) |
---|
58 | | - | then unit |
---|
59 | | - | else throw("Registry must be a valid address"), if (!(isInitialized)) |
---|
60 | | - | then unit |
---|
61 | | - | else throw("Contract has already been initialized")]), [StringEntry(key_registry, registryAddress)]) |
---|
62 | | - | |
---|
63 | | - | |
---|
64 | | - | |
---|
65 | | - | @Callable(inv) |
---|
66 | | - | func resolve (name,callData) = valueOrElse(modifiers([onlyInitialized()]), { |
---|
67 | | - | let $t021362184 = _findResolver(name) |
---|
68 | | - | let resolver = $t021362184._1 |
---|
69 | | - | let restLabels = $t021362184._2 |
---|
70 | | - | let $t021902334 = match callData { |
---|
71 | | - | case _ => |
---|
72 | | - | if (("getAddr" == $match0)) |
---|
73 | | - | then $Tuple2("getAddr", [value(restLabels)]) |
---|
74 | | - | else $Tuple2(unit, unit) |
---|
75 | | - | } |
---|
76 | | - | let callFunction = $t021902334._1 |
---|
77 | | - | let callArgs = $t021902334._2 |
---|
78 | | - | let supportsInterface = if (!(isDefined(resolver))) |
---|
79 | | - | then false |
---|
80 | | - | else match invoke(value(resolver), "supportsInterface", [callData], nil) { |
---|
81 | | - | case supportsInterface: Boolean => |
---|
82 | | - | supportsInterface |
---|
83 | | - | case _ => |
---|
84 | | - | false |
---|
85 | | - | } |
---|
86 | | - | $Tuple2(nil, if (!(supportsInterface)) |
---|
87 | | - | then unit |
---|
88 | | - | else match invoke(value(resolver), value(callFunction), value(callArgs), nil) { |
---|
89 | | - | case callbackData: String => |
---|
90 | | - | callbackData |
---|
91 | | - | case _ => |
---|
92 | | - | unit |
---|
93 | | - | }) |
---|
94 | | - | }) |
---|
95 | | - | |
---|
96 | | - | |
---|
| 1 | + | # no script |
---|