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