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