tx · 7AZAbkKJcjr7Cduct2433dDyb9Bgnxuz484Gxs4qugUV

3MzFjVphaDKp1oZjd5KmCYou3wCzCzTmEFe:  -0.00300000 Waves

2022.09.20 22:17 [2237872] smart account 3MzFjVphaDKp1oZjd5KmCYou3wCzCzTmEFe > SELF 0.00000000 Waves

{ "type": 13, "id": "7AZAbkKJcjr7Cduct2433dDyb9Bgnxuz484Gxs4qugUV", "fee": 300000, "feeAssetId": null, "timestamp": 1663701479892, "version": 2, "chainId": 84, "sender": "3MzFjVphaDKp1oZjd5KmCYou3wCzCzTmEFe", "senderPublicKey": "FFVf3kC6HkjRMmf8W6Zr2bNKhJ5EN5W1vG44GbgvHd9Z", "proofs": [ "AH77aHC8G9jD8fg9ds7uKpUUHzbE4zRnyqHi6SoZf1w7WMAFYZMaqD71j35B36xqQPUMmXsHMpv47jDDVbDabvV" ], "script": "base64:AAIDAAAAAAAAAA4IARIDCgEIEgUKAwgBCAAAAA0AAAAABE5PTkUCAAAABG5vbmUBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAAA251bQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAUAAAADbnVtAQAAAAtnZXRTdHJCeUtleQAAAAEAAAADa2V5BAAAAANzdHIEAAAAByRtYXRjaDAJAAQdAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEFAAAABE5PTkUFAAAAA3N0cgEAAAAPZ2V0S2V5SXRlbVByaWNlAAAAAQAAAARpdGVtCQABLAAAAAIFAAAABGl0ZW0CAAAABl9wcmljZQEAAAARZ2V0VmFsdWVJdGVtUHJpY2UAAAABAAAABGl0ZW0JAQAAAA5nZXROdW1iZXJCeUtleQAAA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XRlbQAAAAMAAAAFdGl0bGUAAAAFcHJpY2UAAAAEZGF0YQQAAAAPc3VwcGxpZXJBZGRyZXNzCQACWAAAAAEICAUAAAABaQAAAAZjYWxsZXIAAAAFYnl0ZXMEAAAABGl0ZW0JAQAAAApnZXRLZXlJdGVtAAAAAgUAAAAPc3VwcGxpZXJBZGRyZXNzBQAAAAV0aXRsZQMJAABnAAAAAgAAAAAAAAAAAAUAAAAFcHJpY2UJAAACAAAAAQIAAAArcHVyY2hhc2UgY2Fubm90IGJlIGxlc3MgdGhhbiB0aGUgaXRlbSBwcmljZQMJAQAAAAIhPQAAAAIJAQAAABRnZXRWYWx1ZUl0ZW1TdXBwbGllcgAAAAEFAAAABGl0ZW0FAAAABE5PTkUJAAACAAAAAQIAAAAYVGhlIGl0ZW0gYWxyZWFkeSBleGl0c3RzCQEAAAAIV3JpdGVTZXQAAAABCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAASZ2V0S2V5SXRlbVN1cHBsaWVyAAAAAQUAAAAEaXRlbQUAAAAPc3VwcGxpZXJBZGRyZXNzCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAAPZ2V0S2V5SXRlbVByaWNlAAAAAQUAAAAEaXRlbQUAAAAFcHJpY2UJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAAA5nZXRLZXlJdGVtRGF0YQAAAAEFAAAABGl0ZW0FAAAABGRhdGEFAAAAA25pbAAAAACVl79s", "height": 2237872, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: G6DAxYWgrrwBWBFg4uwSHuQHzqxV8y7fjyjruXmhRAJf Next: LzGFe5oDRvadGJqCpt8fUXcb1cSp2WmFdCLsMk7LbAm Diff:
OldNewDifferences
1515
1616
1717 func getStrByKey (key) = {
18- let str = match getInteger(this, key) {
19- case a: Int =>
18+ let str = match getString(this, key) {
19+ case a: String =>
2020 a
2121 case _ =>
2222 NONE
5656
5757
5858 @Callable(i)
59-func purchase (CouponType) = {
59+func purchase (item) = {
6060 let pmt = extract(i.payment)
6161 if (isDefined(pmt.assetId))
6262 then throw("can use WAVES only at the moment")
6363 else {
64- let customerAddress = toBase58String(i.caller.bytes)
65- let price = match getInteger(this, (("Item_" + CouponType) + "_coupon_price")) {
66- case a: Int =>
67- a
68- case _ =>
69- 0
70- }
64+ let userAddress = toBase58String(i.caller.bytes)
65+ let price = getValueItemPrice(item)
66+ let supplierAddress = getValueItemSupplier(item)
7167 if ((pmt.amount != price))
7268 then throw("Purchase amount should be equal to price ")
73- else WriteSet([DataEntry(((("status: purchase_item_" + CouponType) + "_customer_") + customerAddress), "confirmed"), DataEntry(((("price: purchase_item_" + CouponType) + "_customer_") + customerAddress), price)])
69+ else if ((supplierAddress == NONE))
70+ then throw("The supplier does not exist")
71+ else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))])
7472 }
7573 }
7674
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let NONE = "none"
55
66 func getNumberByKey (key) = {
77 let num = match getInteger(this, key) {
88 case a: Int =>
99 a
1010 case _ =>
1111 0
1212 }
1313 num
1414 }
1515
1616
1717 func getStrByKey (key) = {
18- let str = match getInteger(this, key) {
19- case a: Int =>
18+ let str = match getString(this, key) {
19+ case a: String =>
2020 a
2121 case _ =>
2222 NONE
2323 }
2424 str
2525 }
2626
2727
2828 func getKeyItemPrice (item) = (item + "_price")
2929
3030
3131 func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
3232
3333
3434 func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
3535
3636
3737 func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
3838
3939
4040 func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
4141
4242
4343 func getKeyItemData (item) = (item + "_data")
4444
4545
4646 func getKeyItemSupplier (item) = (item + "_owner")
4747
4848
4949 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
5050
5151
5252 func getKeyBalanceSupplier (account) = (account + "_balance")
5353
5454
5555 func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
5656
5757
5858 @Callable(i)
59-func purchase (CouponType) = {
59+func purchase (item) = {
6060 let pmt = extract(i.payment)
6161 if (isDefined(pmt.assetId))
6262 then throw("can use WAVES only at the moment")
6363 else {
64- let customerAddress = toBase58String(i.caller.bytes)
65- let price = match getInteger(this, (("Item_" + CouponType) + "_coupon_price")) {
66- case a: Int =>
67- a
68- case _ =>
69- 0
70- }
64+ let userAddress = toBase58String(i.caller.bytes)
65+ let price = getValueItemPrice(item)
66+ let supplierAddress = getValueItemSupplier(item)
7167 if ((pmt.amount != price))
7268 then throw("Purchase amount should be equal to price ")
73- else WriteSet([DataEntry(((("status: purchase_item_" + CouponType) + "_customer_") + customerAddress), "confirmed"), DataEntry(((("price: purchase_item_" + CouponType) + "_customer_") + customerAddress), price)])
69+ else if ((supplierAddress == NONE))
70+ then throw("The supplier does not exist")
71+ else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))])
7472 }
7573 }
7674
7775
7876
7977 @Callable(i)
8078 func addItem (title,price,data) = {
8179 let supplierAddress = toBase58String(i.caller.bytes)
8280 let item = getKeyItem(supplierAddress, title)
8381 if ((0 >= price))
8482 then throw("purchase cannot be less than the item price")
8583 else if ((getValueItemSupplier(item) != NONE))
8684 then throw("The item already exitsts")
8785 else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)])
8886 }
8987
9088

github/deemru/w8io/169f3d6 
31.22 ms