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 | | - | func isSupportsInterface (registryAddress,interfaceId) = match invoke(value(addressFromString(registryAddress)), "supportsInterface", ["getOwner"], nil) { |
---|
9 | | - | case supportsInterface: Boolean => |
---|
10 | | - | supportsInterface |
---|
11 | | - | case _ => |
---|
12 | | - | false |
---|
13 | | - | } |
---|
14 | | - | |
---|
15 | | - | |
---|
16 | | - | let isInitialized = isDefined(getString(this, key_registry)) |
---|
17 | | - | |
---|
18 | | - | func isAdmin (inv) = (inv.caller == this) |
---|
19 | | - | |
---|
20 | | - | |
---|
21 | | - | func isValidAddress (maybeAddress) = isDefined(addressFromString(maybeAddress)) |
---|
22 | | - | |
---|
23 | | - | |
---|
24 | | - | func modifiers (validations) = unit |
---|
25 | | - | |
---|
26 | | - | |
---|
27 | | - | func onlyAdmin (inv) = if (isAdmin(inv)) |
---|
28 | | - | then unit |
---|
29 | | - | else throw("Permission denied") |
---|
30 | | - | |
---|
31 | | - | |
---|
32 | | - | func onlyInitialized () = if (isInitialized) |
---|
33 | | - | then unit |
---|
34 | | - | else throw("Contract is not initialized") |
---|
35 | | - | |
---|
36 | | - | |
---|
37 | | - | func _getAddr (label) = match invoke(registry, "getOwner", [label], nil) { |
---|
38 | | - | case owner: String => |
---|
39 | | - | owner |
---|
40 | | - | case _ => |
---|
41 | | - | unit |
---|
42 | | - | } |
---|
43 | | - | |
---|
44 | | - | |
---|
45 | | - | @Callable(inv) |
---|
46 | | - | func init (registryAddress) = valueOrElse(modifiers([onlyAdmin(inv), if (isValidAddress(registryAddress)) |
---|
47 | | - | then unit |
---|
48 | | - | else throw("Registry must be a valid address"), if (isSupportsInterface(registryAddress, "getOwner")) |
---|
49 | | - | then unit |
---|
50 | | - | else throw("Registry must support `getOwner` interface"), if (!(isInitialized)) |
---|
51 | | - | then unit |
---|
52 | | - | else throw("Contract has already been initialized")]), [StringEntry(key_registry, registryAddress)]) |
---|
53 | | - | |
---|
54 | | - | |
---|
55 | | - | |
---|
56 | | - | @Callable(inv) |
---|
57 | | - | func supportsInterface (interfaceId) = $Tuple2(nil, (interfaceId == "getAddr")) |
---|
58 | | - | |
---|
59 | | - | |
---|
60 | | - | |
---|
61 | | - | @Callable(inv) |
---|
62 | | - | func getAddr (label) = valueOrElse(modifiers([onlyInitialized()]), $Tuple2(nil, _getAddr(label))) |
---|
63 | | - | |
---|
64 | | - | |
---|
| 1 | + | # no script |
---|