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:AAIEAAAAAAAAAB0IAhIDCgEIEgMKAQgSAwoBCBIECgIIARIECgIICAAAACIAAAAABE5PTkUCAAAABG5vbmUAAAAABkJBTk5FRAIAAAAGYmFubmVkAAAAAAZBQ1RJVkUCAAAABmFjdGl2ZQAAAAAFQ0xPU0UCAAAABWNsb3NlAAAAAARPUEVOAgAAAARvcGVuAAAAAAhhc3NldEtleQIAAAAFYXNzZXQAAAAAC2tleVByaWNlS2V5AgAAAAlrZXlfcHJpY2UAAAAACG93bmVyS2V5AgAAAAVvd25lcgAAAAAQcmVjaGFyZ2VMaW1pdEtleQIAAAAOcmVjaGFyZ2VfbGltaXQAAAAAB2FjdGlvbnMJAARMAAAAAgUAAAAET1BFTgkABEwAAAACBQAAAAVDTE9TRQUAAAADbmlsAAAAABRkZXZpY2VJbml0aWFsQ291bnRlcgAAAAAAAAAAAAAAAAAJa2V5RGV2aWNlAAAAAAAAAAAAAAAAAA1rZXlWYWxpZFVudGlsAAAAAAAAAAABAQAAAA5nZXROdW1iZXJCeUtleQAAAAEAAAADa2V5BAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAAB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AAAAGZGV2aWNlBQAAAAVrZXlJRAkAAAIAAAABAgAAABNLZXkgbm90IHdoaXRlbGlzdGVkAwkBAAAAFm5vdEFsbG93ZWREZXZpY2VBY3Rpb24AAAABBQAAAAZhY3Rpb24JAAACAAAAAQIAAAAVQWN0aW9uIGlzIG5vdCBhbGxvd2VkAwkBAAAAE2tleVRpbWVzdGFtcEludmFsaWQAAAABBQAAAAdrZXlJbmZvCQAAAgAAAAECAAAAC0tleSBleHBpcmVkBAAAAAdjaGFuZ2VzCQAETAAAAAIJAQAAAAtTdHJpbmdFbnRyeQAAAAIJAQAAAA9kZXZpY2VBY3Rpb25LZXkAAAABBQAAAAlkZXZpY2VTdHIFAAAABmFjdGlvbgkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgkBAAAAFmRldmljZUFjdGlvbkNvdW50ZXJLZXkAAAABBQAAAAlkZXZpY2VTdHIJAABkAAAAAgkBAAAAGGRldmljZUFjdGlvbkNvdW50ZXJWYWx1ZQAAAAEFAAAACWRldmljZVN0cgAAAAAAAAAAAQUAAAADbmlsAwMJAABmAAAAAgUAAAAIcmVjaGFyZ2UICQAD7wAAAAEIBQAAAAFpAAAABmNhbGxlcgAAAAdyZWd1bGFyCQEAAAACIT0AAAACBQAAAAhyZWNoYXJnZQAAAAAAAAAAAAcJAARMAAAAAgkBAAAADlNjcmlwdFRyYW5zZmVyAAAAAwgFAAAAAWkAAAAGY2FsbGVyBQAAAAhyZWNoYXJnZQUAAAAEdW5pdAUAAAAHY2hhbmdlcwUAAAAHY2hhbmdlcwAAAAEAAAACdHgBAAAABnZlcmlmeQAAAAAJAAH0AAAAAwgFAAAAAnR4AAAACWJvZHlCeXRlcwkAAZEAAAACCAUAAAACdHgAAAAGcHJvb2ZzAAAAAAAAAAAACAUAAAACdHgAAAAPc2VuZGVyUHVibGljS2V5leiI/w==", "height": 1380756, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: EEbZ7Ps4jtbkz3vi6ya4xvpCyE7aWk9qosu8zydH39ft Next: B54YdMfGDWnR6kuqDQohKzjNtYWw6TapBw7VQejkmWct Diff:
OldNewDifferences
1616 let keyPriceKey = "key_price"
1717
1818 let ownerKey = "owner"
19+
20+let rechargeLimitKey = "recharge_limit"
1921
2022 let actions = [OPEN, CLOSE]
2123
141143
142144 func priceIsWrong (i,assetId,price) = if ((1 > size(i.payments)))
143145 then throw("wrong payments count")
144- else if ((i.payments[0].assetId != assetId))
145- then throw("wrong asset, supported only xyz")
146+ else if ((i.payments[0].assetId != unit))
147+ then throw("wrong asset, supported only wws")
146148 else if ((i.payments[0].amount != price))
147149 then throw(("wrong payment value, expected " + toString(price)))
148150 else false
207209 let keyInfo = getAssetInfo(fromBase58String(keyID))
208210 let device = deviceFromKey(keyInfo)
209211 let deviceStr = toBase58String(device.bytes)
212+ let recharge = getExtNumberByKey(rechargeLimitKey)
210213 if (hasNoKey)
211214 then throw("Key not owned")
212215 else if ((deviceActionKey(deviceStr) == NONE))
217220 then throw("Action is not allowed")
218221 else if (keyTimestampInvalid(keyInfo))
219222 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+ }
221231 }
222232
223233
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 4 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let NONE = "none"
55
66 let BANNED = "banned"
77
88 let ACTIVE = "active"
99
1010 let CLOSE = "close"
1111
1212 let OPEN = "open"
1313
1414 let assetKey = "asset"
1515
1616 let keyPriceKey = "key_price"
1717
1818 let ownerKey = "owner"
19+
20+let rechargeLimitKey = "recharge_limit"
1921
2022 let actions = [OPEN, CLOSE]
2123
2224 let deviceInitialCounter = 0
2325
2426 let keyDevice = 0
2527
2628 let keyValidUntil = 1
2729
2830 func getNumberByKey (key) = match getInteger(this, key) {
2931 case a: Int =>
3032 a
3133 case _ =>
3234 0
3335 }
3436
3537
3638 func getStrByKey (key) = match getString(this, key) {
3739 case a: String =>
3840 a
3941 case _ =>
4042 NONE
4143 }
4244
4345
4446 func getExtNumberByKey (key) = match getInteger(this, key) {
4547 case a: Int =>
4648 a
4749 case _ =>
4850 0
4951 }
5052
5153
5254 func getExtStrByKey (addr,key) = match getString(addr, key) {
5355 case a: String =>
5456 a
5557 case _ =>
5658 NONE
5759 }
5860
5961
6062 func getAssetId () = fromBase58String(getStrByKey(assetKey))
6163
6264
6365 func userStatusKey (addr) = ("user_" + addr)
6466
6567
6668 func userStatusValue (addr) = match getString(this, userStatusKey(addr)) {
6769 case a: String =>
6870 a
6971 case _ =>
7072 NONE
7173 }
7274
7375
7476 func deviceActionKey (addr) = ("device_" + addr)
7577
7678
7779 func deviceActionCounterKey (addr) = ("device_counter_" + addr)
7880
7981
8082 func deviceActionValue (addr) = getStrByKey(deviceActionKey(addr))
8183
8284
8385 func deviceActionCounterValue (addr) = getNumberByKey(deviceActionCounterKey(addr))
8486
8587
8688 func nftKey (nft) = ("key_" + nft)
8789
8890
8991 func nftValue (nft) = getStrByKey(nftKey(nft))
9092
9193
9294 func deviceNotWhitelistedKey (device,key) = {
9395 let nftId = nftKey(key)
9496 let valInDevice = getExtStrByKey(device, nftId)
9597 if ((valInDevice != NONE))
9698 then false
9799 else true
98100 }
99101
100102
101103 func deviceFromKey (key) = {
102104 let device = split(key.description, "_")[keyDevice]
103105 match addressFromString(device) {
104106 case t: Address =>
105107 t
106108 case _ =>
107109 throw("Not a device key")
108110 }
109111 }
110112
111113
112114 func getAssetInfo (asset) = match assetInfo(asset) {
113115 case t: Asset =>
114116 t
115117 case _ =>
116118 throw("Not a key")
117119 }
118120
119121
120122 func keyTimestampInvalid (key) = {
121123 let timestamp = parseIntValue(split(key.description, "_")[keyValidUntil])
122124 (lastBlock.timestamp > timestamp)
123125 }
124126
125127
126128 func keyPriceFromDevice (device) = match getInteger(device, keyPriceKey) {
127129 case t: Int =>
128130 t
129131 case _ =>
130132 throw("Price not specified in device")
131133 }
132134
133135
134136 func ownerFromDevice (device) = match getString(device, ownerKey) {
135137 case t: String =>
136138 t
137139 case _ =>
138140 throw("Owner not specified in device")
139141 }
140142
141143
142144 func priceIsWrong (i,assetId,price) = if ((1 > size(i.payments)))
143145 then throw("wrong payments count")
144- else if ((i.payments[0].assetId != assetId))
145- then throw("wrong asset, supported only xyz")
146+ else if ((i.payments[0].assetId != unit))
147+ then throw("wrong asset, supported only wws")
146148 else if ((i.payments[0].amount != price))
147149 then throw(("wrong payment value, expected " + toString(price)))
148150 else false
149151
150152
151153 func notAllowedDeviceAction (action) = match indexOf(actions, action) {
152154 case a: Int =>
153155 false
154156 case _ =>
155157 true
156158 }
157159
158160
159161 @Callable(i)
160162 func addDevice (deviceAddr) = if ((i.caller != this))
161163 then throw("Not permitted")
162164 else if ((deviceActionValue(deviceAddr) != NONE))
163165 then throw("Device already added")
164166 else [StringEntry(deviceActionKey(deviceAddr), CLOSE), IntegerEntry(deviceActionCounterKey(deviceAddr), deviceInitialCounter)]
165167
166168
167169
168170 @Callable(i)
169171 func addUser (deviceAddr) = if ((i.caller != this))
170172 then throw("Not permitted")
171173 else [StringEntry(userStatusKey(deviceAddr), ACTIVE)]
172174
173175
174176
175177 @Callable(i)
176178 func removeUser (deviceAddr) = if ((i.caller != this))
177179 then throw("Not permitted")
178180 else [DeleteEntry(userStatusKey(deviceAddr))]
179181
180182
181183
182184 @Callable(i)
183185 func requestKey (deviceAddr,duration) = {
184186 let issuedAt = lastBlock.timestamp
185187 let validUntil = (issuedAt + duration)
186188 let deviceOwner = ownerFromDevice(addressFromStringValue(deviceAddr))
187189 let keyPrice = keyPriceFromDevice(addressFromStringValue(deviceAddr))
188190 let assetId = getAssetId()
189191 if ((toBase58String(i.caller.bytes) != deviceOwner))
190192 then throw("Not permitted")
191193 else if ((deviceActionKey(deviceAddr) == NONE))
192194 then throw("No such device")
193195 else if (priceIsWrong(i, assetId, keyPrice))
194196 then throw("wrong price")
195197 else {
196198 let issue = Issue("DeviceKeyGen", ((deviceAddr + "_") + toString(validUntil)), 1, 0, false)
197199 let newAssetId = calculateAssetId(issue)
198200 [issue, ScriptTransfer(i.caller, 1, newAssetId)]
199201 }
200202 }
201203
202204
203205
204206 @Callable(i)
205207 func deviceAction (keyID,action) = {
206208 let hasNoKey = (1 > assetBalance(i.caller, fromBase58String(keyID)))
207209 let keyInfo = getAssetInfo(fromBase58String(keyID))
208210 let device = deviceFromKey(keyInfo)
209211 let deviceStr = toBase58String(device.bytes)
212+ let recharge = getExtNumberByKey(rechargeLimitKey)
210213 if (hasNoKey)
211214 then throw("Key not owned")
212215 else if ((deviceActionKey(deviceStr) == NONE))
213216 then throw("No such device")
214217 else if (deviceNotWhitelistedKey(device, keyID))
215218 then throw("Key not whitelisted")
216219 else if (notAllowedDeviceAction(action))
217220 then throw("Action is not allowed")
218221 else if (keyTimestampInvalid(keyInfo))
219222 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+ }
221231 }
222232
223233
224234 @Verifier(tx)
225235 func verify () = sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)
226236

github/deemru/w8io/026f985 
51.81 ms