tx · EEbZ7Ps4jtbkz3vi6ya4xvpCyE7aWk9qosu8zydH39ft 3N3QGoxpTairHzyavoHpRPyTVMyLdX46MwJ: -0.01400000 Waves 2021.02.02 18:55 [1380751] smart account 3N3QGoxpTairHzyavoHpRPyTVMyLdX46MwJ > SELF 0.00000000 Waves
{ "type": 13, "id": "EEbZ7Ps4jtbkz3vi6ya4xvpCyE7aWk9qosu8zydH39ft", "fee": 1400000, "feeAssetId": null, "timestamp": 1612281447142, "version": 2, "chainId": 84, "sender": "3N3QGoxpTairHzyavoHpRPyTVMyLdX46MwJ", "senderPublicKey": "84ye9pvBU1ixETjmeNbvvD5czb8ZEjsSJuNyFGkYFmwd", "proofs": [ "3iUbjT6mHzeJg62JyPofAjs3NcY2q1GvU45ExuV7ACMkDZ9EUa4noqbRNYRBn7rKRDta88WvQPwcTWZcYQz4rdQ7" ], "script": "base64:AAIEAAAAAAAAAB0IAhIDCgEIEgMKAQgSAwoBCBIECgIIARIECgIICAAAACEAAAAABE5PTkUCAAAABG5vbmUAAAAABkJBTk5FRAIAAAAGYmFubmVkAAAAAAZBQ1RJVkUCAAAABmFjdGl2ZQAAAAAFQ0xPU0UCAAAABWNsb3NlAAAAAARPUEVOAgAAAARvcGVuAAAAAAhhc3NldEtleQIAAAAFYXNzZXQAAAAAC2tleVByaWNlS2V5AgAAAAlrZXlfcHJpY2UAAAAACG93bmVyS2V5AgAAAAVvd25lcgAAAAAHYWN0aW9ucwkABEwAAAACBQAAAARPUEVOCQAETAAAAAIFAAAABUNMT1NFBQAAAANuaWwAAAAAFGRldmljZUluaXRpYWxDb3VudGVyAAAAAAAAAAAAAAAAAAlrZXlEZXZpY2UAAAAAAAAAAAAAAAAADWtleVZhbGlkVW50aWwAAAAAAAAAAAEBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAAByRtYXRjaDAJAAQaAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAANJbnQEA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iBpcyBub3QgYWxsb3dlZAMJAQAAABNrZXlUaW1lc3RhbXBJbnZhbGlkAAAAAQUAAAAHa2V5SW5mbwkAAAIAAAABAgAAAAtLZXkgZXhwaXJlZAkABEwAAAACCQEAAAALU3RyaW5nRW50cnkAAAACCQEAAAAPZGV2aWNlQWN0aW9uS2V5AAAAAQUAAAAJZGV2aWNlU3RyBQAAAAZhY3Rpb24JAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAABZkZXZpY2VBY3Rpb25Db3VudGVyS2V5AAAAAQUAAAAJZGV2aWNlU3RyCQAAZAAAAAIJAQAAABhkZXZpY2VBY3Rpb25Db3VudGVyVmFsdWUAAAABBQAAAAlkZXZpY2VTdHIAAAAAAAAAAAEFAAAAA25pbAAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAAJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAACAUAAAACdHgAAAAPc2VuZGVyUHVibGljS2V5stq+fQ==", "height": 1380751, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 6ZGgb1WXermoi8aooaTac7St6pDmY3J2nC5jR9XgbTJA Next: CwJVvzCg4MZ6x5kksHPBJfDiuJddPJmSi1uNrE8hvYwk Full:
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 4 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let NONE = "none" | |
5 | 5 | ||
6 | 6 | let BANNED = "banned" | |
7 | 7 | ||
8 | 8 | let ACTIVE = "active" | |
9 | 9 | ||
10 | 10 | let CLOSE = "close" | |
11 | 11 | ||
12 | 12 | let OPEN = "open" | |
13 | 13 | ||
14 | 14 | let assetKey = "asset" | |
15 | 15 | ||
16 | 16 | let keyPriceKey = "key_price" | |
17 | 17 | ||
18 | 18 | let ownerKey = "owner" | |
19 | 19 | ||
20 | 20 | let actions = [OPEN, CLOSE] | |
21 | 21 | ||
22 | 22 | let deviceInitialCounter = 0 | |
23 | 23 | ||
24 | 24 | let keyDevice = 0 | |
25 | 25 | ||
26 | 26 | let keyValidUntil = 1 | |
27 | 27 | ||
28 | 28 | func getNumberByKey (key) = match getInteger(this, key) { | |
29 | 29 | case a: Int => | |
30 | 30 | a | |
31 | 31 | case _ => | |
32 | 32 | 0 | |
33 | 33 | } | |
34 | 34 | ||
35 | 35 | ||
36 | 36 | func getStrByKey (key) = match getString(this, key) { | |
37 | 37 | case a: String => | |
38 | 38 | a | |
39 | 39 | case _ => | |
40 | 40 | NONE | |
41 | 41 | } | |
42 | 42 | ||
43 | 43 | ||
44 | 44 | func getExtNumberByKey (key) = match getInteger(this, key) { | |
45 | 45 | case a: Int => | |
46 | 46 | a | |
47 | 47 | case _ => | |
48 | 48 | 0 | |
49 | 49 | } | |
50 | 50 | ||
51 | 51 | ||
52 | 52 | func getExtStrByKey (addr,key) = match getString(addr, key) { | |
53 | 53 | case a: String => | |
54 | 54 | a | |
55 | 55 | case _ => | |
56 | 56 | NONE | |
57 | 57 | } | |
58 | 58 | ||
59 | 59 | ||
60 | 60 | func getAssetId () = fromBase58String(getStrByKey(assetKey)) | |
61 | 61 | ||
62 | 62 | ||
63 | 63 | func userStatusKey (addr) = ("user_" + addr) | |
64 | 64 | ||
65 | 65 | ||
66 | 66 | func userStatusValue (addr) = match getString(this, userStatusKey(addr)) { | |
67 | 67 | case a: String => | |
68 | 68 | a | |
69 | 69 | case _ => | |
70 | 70 | NONE | |
71 | 71 | } | |
72 | 72 | ||
73 | 73 | ||
74 | 74 | func deviceActionKey (addr) = ("device_" + addr) | |
75 | 75 | ||
76 | 76 | ||
77 | 77 | func deviceActionCounterKey (addr) = ("device_counter_" + addr) | |
78 | 78 | ||
79 | 79 | ||
80 | 80 | func deviceActionValue (addr) = getStrByKey(deviceActionKey(addr)) | |
81 | 81 | ||
82 | 82 | ||
83 | 83 | func deviceActionCounterValue (addr) = getNumberByKey(deviceActionCounterKey(addr)) | |
84 | 84 | ||
85 | 85 | ||
86 | 86 | func nftKey (nft) = ("key_" + nft) | |
87 | 87 | ||
88 | 88 | ||
89 | 89 | func nftValue (nft) = getStrByKey(nftKey(nft)) | |
90 | 90 | ||
91 | 91 | ||
92 | 92 | func deviceNotWhitelistedKey (device,key) = { | |
93 | 93 | let nftId = nftKey(key) | |
94 | 94 | let valInDevice = getExtStrByKey(device, nftId) | |
95 | 95 | if ((valInDevice != NONE)) | |
96 | 96 | then false | |
97 | 97 | else true | |
98 | 98 | } | |
99 | 99 | ||
100 | 100 | ||
101 | 101 | func deviceFromKey (key) = { | |
102 | 102 | let device = split(key.description, "_")[keyDevice] | |
103 | 103 | match addressFromString(device) { | |
104 | 104 | case t: Address => | |
105 | 105 | t | |
106 | 106 | case _ => | |
107 | 107 | throw("Not a device key") | |
108 | 108 | } | |
109 | 109 | } | |
110 | 110 | ||
111 | 111 | ||
112 | 112 | func getAssetInfo (asset) = match assetInfo(asset) { | |
113 | 113 | case t: Asset => | |
114 | 114 | t | |
115 | 115 | case _ => | |
116 | 116 | throw("Not a key") | |
117 | 117 | } | |
118 | 118 | ||
119 | 119 | ||
120 | 120 | func keyTimestampInvalid (key) = { | |
121 | 121 | let timestamp = parseIntValue(split(key.description, "_")[keyValidUntil]) | |
122 | 122 | (lastBlock.timestamp > timestamp) | |
123 | 123 | } | |
124 | 124 | ||
125 | 125 | ||
126 | 126 | func keyPriceFromDevice (device) = match getInteger(device, keyPriceKey) { | |
127 | 127 | case t: Int => | |
128 | 128 | t | |
129 | 129 | case _ => | |
130 | 130 | throw("Price not specified in device") | |
131 | 131 | } | |
132 | 132 | ||
133 | 133 | ||
134 | 134 | func ownerFromDevice (device) = match getString(device, ownerKey) { | |
135 | 135 | case t: String => | |
136 | 136 | t | |
137 | 137 | case _ => | |
138 | 138 | throw("Owner not specified in device") | |
139 | 139 | } | |
140 | 140 | ||
141 | 141 | ||
142 | 142 | func priceIsWrong (i,assetId,price) = if ((1 > size(i.payments))) | |
143 | 143 | then throw("wrong payments count") | |
144 | 144 | else if ((i.payments[0].assetId != assetId)) | |
145 | 145 | then throw("wrong asset, supported only xyz") | |
146 | 146 | else if ((i.payments[0].amount != price)) | |
147 | 147 | then throw(("wrong payment value, expected " + toString(price))) | |
148 | 148 | else false | |
149 | 149 | ||
150 | 150 | ||
151 | 151 | func notAllowedDeviceAction (action) = match indexOf(actions, action) { | |
152 | 152 | case a: Int => | |
153 | 153 | false | |
154 | 154 | case _ => | |
155 | 155 | true | |
156 | 156 | } | |
157 | 157 | ||
158 | 158 | ||
159 | 159 | @Callable(i) | |
160 | 160 | func addDevice (deviceAddr) = if ((i.caller != this)) | |
161 | 161 | then throw("Not permitted") | |
162 | 162 | else if ((deviceActionValue(deviceAddr) != NONE)) | |
163 | 163 | then throw("Device already added") | |
164 | 164 | else [StringEntry(deviceActionKey(deviceAddr), CLOSE), IntegerEntry(deviceActionCounterKey(deviceAddr), deviceInitialCounter)] | |
165 | 165 | ||
166 | 166 | ||
167 | 167 | ||
168 | 168 | @Callable(i) | |
169 | 169 | func addUser (deviceAddr) = if ((i.caller != this)) | |
170 | 170 | then throw("Not permitted") | |
171 | 171 | else [StringEntry(userStatusKey(deviceAddr), ACTIVE)] | |
172 | 172 | ||
173 | 173 | ||
174 | 174 | ||
175 | 175 | @Callable(i) | |
176 | 176 | func removeUser (deviceAddr) = if ((i.caller != this)) | |
177 | 177 | then throw("Not permitted") | |
178 | 178 | else [DeleteEntry(userStatusKey(deviceAddr))] | |
179 | 179 | ||
180 | 180 | ||
181 | 181 | ||
182 | 182 | @Callable(i) | |
183 | 183 | func requestKey (deviceAddr,duration) = { | |
184 | 184 | let issuedAt = lastBlock.timestamp | |
185 | 185 | let validUntil = (issuedAt + duration) | |
186 | 186 | let deviceOwner = ownerFromDevice(addressFromStringValue(deviceAddr)) | |
187 | 187 | let keyPrice = keyPriceFromDevice(addressFromStringValue(deviceAddr)) | |
188 | 188 | let assetId = getAssetId() | |
189 | 189 | if ((toBase58String(i.caller.bytes) != deviceOwner)) | |
190 | 190 | then throw("Not permitted") | |
191 | 191 | else if ((deviceActionKey(deviceAddr) == NONE)) | |
192 | 192 | then throw("No such device") | |
193 | 193 | else if (priceIsWrong(i, assetId, keyPrice)) | |
194 | 194 | then throw("wrong price") | |
195 | 195 | else { | |
196 | 196 | let issue = Issue("DeviceKeyGen", ((deviceAddr + "_") + toString(validUntil)), 1, 0, false) | |
197 | 197 | let newAssetId = calculateAssetId(issue) | |
198 | 198 | [issue, ScriptTransfer(i.caller, 1, newAssetId)] | |
199 | 199 | } | |
200 | 200 | } | |
201 | 201 | ||
202 | 202 | ||
203 | 203 | ||
204 | 204 | @Callable(i) | |
205 | 205 | func deviceAction (keyID,action) = { | |
206 | 206 | let hasNoKey = (1 > assetBalance(i.caller, fromBase58String(keyID))) | |
207 | 207 | let keyInfo = getAssetInfo(fromBase58String(keyID)) | |
208 | 208 | let device = deviceFromKey(keyInfo) | |
209 | 209 | let deviceStr = toBase58String(device.bytes) | |
210 | 210 | if (hasNoKey) | |
211 | 211 | then throw("Key not owned") | |
212 | 212 | else if ((deviceActionKey(deviceStr) == NONE)) | |
213 | 213 | then throw("No such device") | |
214 | 214 | else if (deviceNotWhitelistedKey(device, keyID)) | |
215 | 215 | then throw("Key not whitelisted") | |
216 | 216 | else if (notAllowedDeviceAction(action)) | |
217 | 217 | then throw("Action is not allowed") | |
218 | 218 | else if (keyTimestampInvalid(keyInfo)) | |
219 | 219 | then throw("Key expired") | |
220 | 220 | else [StringEntry(deviceActionKey(deviceStr), action), IntegerEntry(deviceActionCounterKey(deviceStr), (deviceActionCounterValue(deviceStr) + 1))] | |
221 | 221 | } | |
222 | 222 | ||
223 | 223 | ||
224 | 224 | @Verifier(tx) | |
225 | 225 | func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | |
226 | 226 |
github/deemru/w8io/169f3d6 46.27 ms ◑