tx · EHVLtGp9TM6QhaC2Rgv3XYvDb8rb4XgKFR6ixCSnviHx

3MuPe52GsMZN8tduGQ3jgoUBsJK1zAhjaqm:  -0.01000000 Waves

2022.03.17 09:12 [1967564] smart account 3MuPe52GsMZN8tduGQ3jgoUBsJK1zAhjaqm > SELF 0.00000000 Waves

{ "type": 13, "id": "EHVLtGp9TM6QhaC2Rgv3XYvDb8rb4XgKFR6ixCSnviHx", "fee": 1000000, "feeAssetId": null, "timestamp": 1647497531583, "version": 2, "chainId": 84, "sender": "3MuPe52GsMZN8tduGQ3jgoUBsJK1zAhjaqm", "senderPublicKey": "DKZcYM5WoZ3gBkiAgjzXdfQaZcfisgn2Zn4B226GHMcD", "proofs": [ "2CJMAQP1ukv2FdEbYQ8oqthBf4sMgzQSTNb3iuUTVUZGSPKCQqBG3Gg8jSPrB7sXXm6AAj6LWwLBRfknc3wzZjSn" ], "script": "base64:AAIFAAAAAAAAAA4IAhIFCgMIAQgSAwoBCAAAAA0AAAAABE5PTkUCAAAABG5vbmUBAAAADmdldE51bWJlckJ5S2V5AAAAAQAAAANrZXkEAAAAA251bQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQAAAAAAAAAAAAUAAAADbnVtAQAAAAtnZXRTdHJCeUtleQAAAAEAAAADa2V5BAAAAANzdHIEAAAAByRtYXRjaDAJAAQdAAAAAgUAAAAEdGhpcwUAAAADa2V5AwkAAAEAAAACBQAAAAckbWF0Y2gwAgAAAAZTdHJpbmcEAAAAAWEFAAAAByRtYXRjaDAFAAAAAWEFAAAABE5PTkUFAAAAA3N0cgEAAAAPZ2V0S2V5SXRlbVByaWNlAAAAAQAAAARpdGVtCQABLAAAAAIFAAAABGl0ZW0CAAAABl9wcmljZQEAAAARZ2V0VmFsdWVJdGVtUHJpY2UAAAABAAAABGl0ZW0JAQAAAA5nZXRO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VmFsdWVJdGVtUHJpY2UAAAABBQAAAARpdGVtBAAAAA9zdXBwbGllckFkZHJlc3MJAQAAABRnZXRWYWx1ZUl0ZW1TdXBwbGllcgAAAAEFAAAABGl0ZW0DCQAAZgAAAAIFAAAABXByaWNlCAUAAAADcG10AAAABmFtb3VudAkAAAIAAAABAgAAAC5wdXJjaGFzZSBhbW91bnQgY2Fubm90IGJlIGxlc3MgdGhhbiBpdGVtIHByaWNlAwkAAGYAAAACCAUAAAADcG10AAAABmFtb3VudAUAAAAFcHJpY2UJAAACAAAAAQIAAAAwcHVyY2hhc2UgYW1vdW50IGNhbm5vdCBiZSBoaWdoZXIgdGhhbiBpdGVtIHByaWNlAwkAAAAAAAACBQAAAA9zdXBwbGllckFkZHJlc3MFAAAABE5PTkUJAAACAAAAAQIAAAAXc3VwcGxpZXIgZG9lcyBub3QgZXhpc3QJAAUUAAAAAgkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgkBAAAAFWdldEtleVVzZXJJdGVtQ291bnRlcgAAAAIFAAAAC3VzZXJBZGRyZXNzBQAAAARpdGVtCQAAZAAAAAIJAQAAABdnZXRWYWx1ZVVzZXJJdGVtQ291bnRlcgAAAAIFAAAAC3VzZXJBZGRyZXNzBQAAAARpdGVtAAAAAAAAAAABCQAETAAAAAIJAQAAAAxJbnRlZ2VyRW50cnkAAAACCQEAAAAVZ2V0S2V5QmFsYW5jZVN1cHBsaWVyAAAAAQUAAAAPc3VwcGxpZXJBZGRyZXNzCQAAZAAAAAIJAQAAABdnZXRWYWx1ZUJhbGFuY2VTdXBwbGllcgAAAAEFAAAAD3N1cHBsaWVyQWRkcmVzcwgFAAAAA3BtdAAAAAZhbW91bnQFAAAAA25pbAUAAAAEdW5pdAAAAAAyL/Z3", "height": 1967564, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: FnX4UMjsbX962AT8hbUpmgXe8f6Yfu5PSKr275rTp2ab Next: 4ZzWwsmnqzxLZGDaMS8nqcGk11cwMVzj6G8MfLPANVxn Diff:
OldNewDifferences
6969
7070
7171 @Callable(i)
72-func purchase (accountName) = {
73- let pmt = if ((size(i.payments) == 1))
74- then i.payments[0]
75- else throw("Attached payment is required")
72+func purchase (item) = {
73+ let pmt = i.payments[0]
7674 if (isDefined(pmt.assetId))
7775 then throw("can use WAVES only at the moment")
7876 else {
79- let customerAddress = toBase58String(i.caller.bytes)
80- let price = match getInteger(this, (("item_" + accountName) + "_coupon_price")) {
81- case a: Int =>
82- a
83- case _ =>
84- 0
85- }
77+ let userAddress = toBase58String(i.caller.bytes)
78+ let price = getValueItemPrice(item)
79+ let supplierAddress = getValueItemSupplier(item)
8680 if ((price > pmt.amount))
8781 then throw("purchase amount cannot be less than item price")
8882 else if ((pmt.amount > price))
8983 then throw("purchase amount cannot be higher than item price")
90- else $Tuple2([StringEntry(((("status:purchase_item_" + accountName) + "_customer_") + customerAddress), "confirmed"), IntegerEntry(((("price:purchase_item_" + accountName) + "_customer_") + customerAddress), price)], unit)
84+ else if ((supplierAddress == NONE))
85+ then throw("supplier does not exist")
86+ else $Tuple2([IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))], unit)
9187 }
9288 }
9389
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
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) = {
1818 let str = match getString(this, key) {
1919 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)
5959 func addItem (title,price,data) = {
6060 let supplierAddress = toBase58String(i.caller.bytes)
6161 let item = getKeyItem(supplierAddress, title)
6262 if ((0 >= price))
6363 then throw("purchase amount cannot be less than item price")
6464 else if ((getValueItemSupplier(item) != NONE))
6565 then throw("an item is already exist")
6666 else $Tuple2([StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)], unit)
6767 }
6868
6969
7070
7171 @Callable(i)
72-func purchase (accountName) = {
73- let pmt = if ((size(i.payments) == 1))
74- then i.payments[0]
75- else throw("Attached payment is required")
72+func purchase (item) = {
73+ let pmt = i.payments[0]
7674 if (isDefined(pmt.assetId))
7775 then throw("can use WAVES only at the moment")
7876 else {
79- let customerAddress = toBase58String(i.caller.bytes)
80- let price = match getInteger(this, (("item_" + accountName) + "_coupon_price")) {
81- case a: Int =>
82- a
83- case _ =>
84- 0
85- }
77+ let userAddress = toBase58String(i.caller.bytes)
78+ let price = getValueItemPrice(item)
79+ let supplierAddress = getValueItemSupplier(item)
8680 if ((price > pmt.amount))
8781 then throw("purchase amount cannot be less than item price")
8882 else if ((pmt.amount > price))
8983 then throw("purchase amount cannot be higher than item price")
90- else $Tuple2([StringEntry(((("status:purchase_item_" + accountName) + "_customer_") + customerAddress), "confirmed"), IntegerEntry(((("price:purchase_item_" + accountName) + "_customer_") + customerAddress), price)], unit)
84+ else if ((supplierAddress == NONE))
85+ then throw("supplier does not exist")
86+ else $Tuple2([IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))], unit)
9187 }
9288 }
9389
9490

github/deemru/w8io/026f985 
22.61 ms