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