tx · CT3gk6RLFunurfAVWCURJ9Zk6ADHegtcQqBHoQYBNAf9
3MxxyH2kVwFzdTaTrX6mWx5x5CBvmCBzngx: -0.00200000 Waves
2022.07.07 14:09 [2129188] smart account 3MxxyH2kVwFzdTaTrX6mWx5x5CBvmCBzngx > SELF 0.00000000 Waves
{
"type": 13,
"id": "CT3gk6RLFunurfAVWCURJ9Zk6ADHegtcQqBHoQYBNAf9",
"fee": 200000,
"feeAssetId": null,
"timestamp": 1657192238634,
"version": 2,
"chainId": 84,
"sender": "3MxxyH2kVwFzdTaTrX6mWx5x5CBvmCBzngx",
"senderPublicKey": "9QyAdqxHr3LvagmqsW2C1iNXmHGzeYbGV7PPQ9XEm5Sp",
"proofs": [
"5dc2rX4caqCGvHWouSHQfj9dqSGaRjvgaA17DkuPpz9mXDQ1HtSrSGSbXKi1NvY8RcAL7mmtJY7UnEnaoSXuttAP"
],
"script": "base64:AAIFAAAAAAAAABEIAhIECgIIARIAEgASAwoBCAAAAAoAAAAAC1pFUk9fUklHSFRTAgAAAAUwMDAwMAAAAAAFQURNSU4AAAAAAAAAAAAAAAAABFVTRVIAAAAAAAAAAAEAAAAABVdSSVRFAAAAAAAAAAACAAAAAARSRUFEAAAAAAAAAAADAAAAAAdFWEVDVVRFAAAAAAAAAAAEAAAAAAVST0xFUwkABEwAAAACBQAAAAVBRE1JTgkABEwAAAACBQAAAARVU0VSCQAETAAAAAIFAAAABVdSSVRFCQAETAAAAAIFAAAABFJFQUQJAARMAAAAAgUAAAAHRVhFQ1VURQUAAAADbmlsAQAAAAhnZXRSb2xlcwAAAAEAAAAGY2FsbGVyCQEAAAALdmFsdWVPckVsc2UAAAACCQAEHQAAAAIFAAAABHRoaXMJAAEsAAAAAgIAAAAGcm9sZXNfBQAAAAZjYWxsZXIFAAAAC1pFUk9fUklHSFRTAQAAAAdzZXRSb2xlAAAAAwAAAARtYXNrAAAABHJvbGUAAAADc2V0BAAAAAZiZWZvcmUJAAEvAAAAAgUAAAAEbWFzaw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sZQAAAAIFAAAACXVzZXJSb2xlcwUAAAAFQURNSU4JAARMAAAAAgkBAAAAC1N0cmluZ0VudHJ5AAAAAgkAASwAAAACAgAAAA1hZG1pbl9hY2Nlc3NfCQAEJQAAAAEIBQAAAAFpAAAABmNhbGxlcgIAAAAHc3VjY2VzcwUAAAADbmlsCQAAAgAAAAECAAAACk9ubHkgYWRtaW4AAAABaQEAAAAIb25seVVzZXIAAAAABAAAAAl1c2VyUm9sZXMJAQAAAAhnZXRSb2xlcwAAAAEJAAQlAAAAAQgFAAAAAWkAAAAGY2FsbGVyAwkBAAAACWNoZWNrUm9sZQAAAAIFAAAACXVzZXJSb2xlcwUAAAAEVVNFUgkABEwAAAACCQEAAAALU3RyaW5nRW50cnkAAAACCQABLAAAAAICAAAADHVzZXJfYWNjZXNzXwkABCUAAAABCAUAAAABaQAAAAZjYWxsZXICAAAAB3N1Y2Nlc3MFAAAAA25pbAkAAAIAAAABAgAAAAlPbmx5IHVzZXIAAAABaQEAAAAIR2V0Um9sZXMAAAABAAAABGFkZHIJAARMAAAAAgkBAAAAC1N0cmluZ0VudHJ5AAAAAgIAAAABMQkBAAAACGdldFJvbGVzAAAAAQUAAAAEYWRkcgUAAAADbmlsAAAAAPT1ZcE=",
"height": 2129188,
"applicationStatus": "succeeded",
"spentComplexity": 0
}
View: original | compacted
Prev: 8rK13jMtszcTiDuFjyPME4obxR3TqYQetm58bDLdGdya
Next: 7Cq6pFaaePude91pQ1sj6jdnDw4PbetUB8VHFXDRn5Bz
Full:
Old | New | | Differences |
---|
1 | 1 | | {-# STDLIB_VERSION 5 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | func getOwnerAddr () = { |
---|
5 | | - | let owner = getString(this, "owner") |
---|
6 | | - | if (!(isDefined(owner))) |
---|
7 | | - | then throw("init first") |
---|
8 | | - | else addressFromStringValue(value(owner)) |
---|
| 4 | + | let ZERO_RIGHTS = "00000" |
---|
| 5 | + | |
---|
| 6 | + | let ADMIN = 0 |
---|
| 7 | + | |
---|
| 8 | + | let USER = 1 |
---|
| 9 | + | |
---|
| 10 | + | let WRITE = 2 |
---|
| 11 | + | |
---|
| 12 | + | let READ = 3 |
---|
| 13 | + | |
---|
| 14 | + | let EXECUTE = 4 |
---|
| 15 | + | |
---|
| 16 | + | let ROLES = [ADMIN, USER, WRITE, READ, EXECUTE] |
---|
| 17 | + | |
---|
| 18 | + | func getRoles (caller) = valueOrElse(getString(this, ("roles_" + caller)), ZERO_RIGHTS) |
---|
| 19 | + | |
---|
| 20 | + | |
---|
| 21 | + | func setRole (mask,role,set) = { |
---|
| 22 | + | let before = take(mask, role) |
---|
| 23 | + | let newRole = if (set) |
---|
| 24 | + | then "1" |
---|
| 25 | + | else "0" |
---|
| 26 | + | let after = takeRight(mask, ((size(ROLES) - 1) - role)) |
---|
| 27 | + | ((before + newRole) + after) |
---|
9 | 28 | | } |
---|
10 | 29 | | |
---|
11 | 30 | | |
---|
12 | | - | func checkOwner (caller) = (caller == getOwnerAddr()) |
---|
| 31 | + | func checkRole (mask,role) = (drop(dropRight(mask, ((size(ROLES) - 1) - role)), role) == "1") |
---|
13 | 32 | | |
---|
14 | 33 | | |
---|
15 | | - | func changeOwnerInternal (caller,addr) = if (checkOwner(caller)) |
---|
16 | | - | then [StringEntry("owner", toString(addr))] |
---|
17 | | - | else throw("Only owner") |
---|
| 34 | + | @Callable(i) |
---|
| 35 | + | func setRoleForUser (userAddr,role) = if ((i.caller == this)) |
---|
| 36 | + | then if (if ((role >= 0)) |
---|
| 37 | + | then ((size(ROLES) - 1) >= role) |
---|
| 38 | + | else false) |
---|
| 39 | + | then { |
---|
| 40 | + | let userRoles = getRoles(userAddr) |
---|
| 41 | + | let res = setRole(userRoles, role, true) |
---|
| 42 | + | [StringEntry(("roles_" + userAddr), res)] |
---|
| 43 | + | } |
---|
| 44 | + | else throw("Wrong role") |
---|
| 45 | + | else throw("Only deployer") |
---|
18 | 46 | | |
---|
19 | 47 | | |
---|
20 | | - | func initInternal (caller,addr) = { |
---|
21 | | - | let owner = getString(this, "owner") |
---|
22 | | - | if (if ((caller == this)) |
---|
23 | | - | then !(isDefined(owner)) |
---|
24 | | - | else false) |
---|
25 | | - | then [StringEntry("owner", addr)] |
---|
| 48 | + | |
---|
| 49 | + | @Callable(i) |
---|
| 50 | + | func onlyAdmin () = { |
---|
| 51 | + | let userRoles = getRoles(toString(i.caller)) |
---|
| 52 | + | if (checkRole(userRoles, ADMIN)) |
---|
| 53 | + | then [StringEntry(("admin_access_" + toString(i.caller)), "success")] |
---|
26 | 54 | | else throw("Only admin") |
---|
27 | 55 | | } |
---|
28 | 56 | | |
---|
29 | 57 | | |
---|
| 58 | + | |
---|
30 | 59 | | @Callable(i) |
---|
31 | | - | func initOwner (addr) = initInternal(i.caller, addr) |
---|
| 60 | + | func onlyUser () = { |
---|
| 61 | + | let userRoles = getRoles(toString(i.caller)) |
---|
| 62 | + | if (checkRole(userRoles, USER)) |
---|
| 63 | + | then [StringEntry(("user_access_" + toString(i.caller)), "success")] |
---|
| 64 | + | else throw("Only user") |
---|
| 65 | + | } |
---|
32 | 66 | | |
---|
33 | 67 | | |
---|
34 | 68 | | |
---|
35 | 69 | | @Callable(i) |
---|
36 | | - | func changeOwner (addr) = changeOwnerInternal(i.caller, addressFromStringValue(addr)) |
---|
37 | | - | |
---|
38 | | - | |
---|
39 | | - | |
---|
40 | | - | @Callable(i) |
---|
41 | | - | func callFunc () = if (checkOwner(i.caller)) |
---|
42 | | - | then [IntegerEntry(toString(i.caller), height)] |
---|
43 | | - | else throw("Only Owner") |
---|
44 | | - | |
---|
45 | | - | |
---|
46 | | - | |
---|
47 | | - | @Callable(i) |
---|
48 | | - | func showOwner () = [StringEntry("1", toString(getOwnerAddr()))] |
---|
| 70 | + | func GetRoles (addr) = [StringEntry("1", getRoles(addr))] |
---|
49 | 71 | | |
---|
50 | 72 | | |
---|