tx · EKC61cF24UvhESRWABKAvwmG1BiZ1EMjb7zDrUh39kdc

3Mzz3QCpMamT89CaFaovqXpnCdiUaKtLZ4D:  -0.01400000 Waves

2019.06.22 15:29 [553246] smart account 3Mzz3QCpMamT89CaFaovqXpnCdiUaKtLZ4D > SELF 0.00000000 Waves

{ "type": 13, "id": "EKC61cF24UvhESRWABKAvwmG1BiZ1EMjb7zDrUh39kdc", "fee": 1400000, "feeAssetId": null, "timestamp": 1561206552363, "version": 1, "sender": "3Mzz3QCpMamT89CaFaovqXpnCdiUaKtLZ4D", "senderPublicKey": "BJRaSW2saRv7CcFs3mSYpaVFQSFpZq9rGKnCcRKuKgWv", "proofs": [ "3o7ToWRapbUfLVc9g86oxAHhLp4NdAuWzSAJ23uEm6YHVR1TR1zCPH11AQ4Q1acZFsdeacswSW5rBEc5he2BDm9o" ], "script": "base64:AAIDAAAAAAAAAAAAAAANAAAAAAROT05FAgAAAARub25lAQAAAApnZXRLZXlJdGVtAAAAAgAAAAhzdXBwbGllcgAAAAV0aXRsZQkAASwAAAACAgAAAAVpdGVtXwkAAlgAAAABCQAB9wAAAAEJAAGbAAAAAQkAASwAAAACBQAAAAhzdXBwbGllcgUAAAAFdGl0bGUBAAAAEmdldEtleUl0ZW1TdXBwbGllcgAAAAEAAAAEaXRlbQkAASwAAAACBQAAAARpdGVtAgAAAAZfb3duZXIBAAAAFWdldEtleUJhbGFuY2VTdXBwbGllcgAAAAEAAAAEaXRlbQkAASwAAAACBQAAAARpdGVtAgAAAAhfYmFsYW5jZQEAAAAPZ2V0S2V5SXRlbVByaWNlAAAAAQAAAARpdGVtCQABLAAAAAIFAAAABGl0ZW0CAAAABl9wcmljZQEAAAAOZ2V0S2V5SXRlbURhdGEAAAABAAAABGl0ZW0JAAEsAAAAAgUAAAAEaXRlbQIAAAAFX2RhdGEBAAAAFWdldEtleVVzZXJJdGVtQ291bnRlcgAAAAIAAAAEdXNlcgAAAARpdGVtCQABLAAAAAIJAAEsAAAAAgkAASwA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AAABXByaWNlCQEAAAARZ2V0VmFsdWVJdGVtUHJpY2UAAAABBQAAAARpdGVtBAAAAA9zdXBwbGllckFkZHJlc3MJAQAAABRnZXRWYWx1ZUl0ZW1TdXBwbGllcgAAAAEFAAAABGl0ZW0DCQAAZgAAAAIFAAAABXByaWNlCAUAAAADcG10AAAABmFtb3VudAkAAAIAAAABAgAAAC5wdXJjaGFzZSBhbW91bnQgY2Fubm90IGJlIGxlc3MgdGhhbiBpdGVtIHByaWNlAwkAAGYAAAACCAUAAAADcG10AAAABmFtb3VudAUAAAAFcHJpY2UJAAACAAAAAQIAAAAwcHVyY2hhc2UgYW1vdW50IGNhbm5vdCBiZSBoaWdoZXIgdGhhbiBpdGVtIHByaWNlAwkAAAAAAAACBQAAAA9zdXBwbGllckFkZHJlc3MFAAAABE5PTkUJAAACAAAAAQIAAAAXc3VwcGxpZXIgZG9lcyBub3QgZXhpc3QJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAABVnZXRLZXlVc2VySXRlbUNvdW50ZXIAAAACBQAAAAt1c2VyQWRkcmVzcwUAAAAEaXRlbQkAAGQAAAACCQEAAAAXZ2V0VmFsdWVVc2VySXRlbUNvdW50ZXIAAAACBQAAAAt1c2VyQWRkcmVzcwUAAAAEaXRlbQAAAAAAAAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAFWdldEtleUJhbGFuY2VTdXBwbGllcgAAAAEFAAAAD3N1cHBsaWVyQWRkcmVzcwkAAGQAAAACCQEAAAAXZ2V0VmFsdWVCYWxhbmNlU3VwcGxpZXIAAAABBQAAAA9zdXBwbGllckFkZHJlc3MIBQAAAANwbXQAAAAGYW1vdW50BQAAAANuaWwAAAAA+3FiKg==", "chainId": 84, "height": 553246, "spentComplexity": 0 } View: original | compacted Prev: 8UbejayJi9LVB82mvqJxikTYhtgoJ7D5vNPWLksotApM Next: 5Aoq76tGWqzsEqxcGnjCgH7a69CvCm7jyV6jF6KXGYGa Diff:
OldNewDifferences
99 func getKeyItemSupplier (item) = (item + "_owner")
1010
1111
12+func getKeyBalanceSupplier (item) = (item + "_balance")
13+
14+
1215 func getKeyItemPrice (item) = (item + "_price")
1316
1417
1518 func getKeyItemData (item) = (item + "_data")
19+
20+
21+func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
1622
1723
1824 func getStrByKey (key) = {
2632 }
2733
2834
35+func getNumberByKey (key) = {
36+ let num = match getInteger(this, key) {
37+ case a: Int =>
38+ a
39+ case _ =>
40+ 0
41+ }
42+ num
43+ }
44+
45+
2946 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
3047
3148
49+func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
50+
51+
52+func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
53+
54+
55+func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
56+
57+
3258 @Callable(i)
33-func purchase (type) = {
59+func purchaseOld (type) = {
3460 let pmt = extract(i.payment)
3561 if (isDefined(pmt.assetId))
3662 then throw("can use WAVES only at the moment")
6490 }
6591
6692
93+
94+@Callable(i)
95+func purchase (item) = {
96+ let pmt = extract(i.payment)
97+ if (isDefined(pmt.assetId))
98+ then throw("WAVES tokens only at the moment")
99+ else {
100+ let userAddress = toBase58String(i.caller.bytes)
101+ let price = getValueItemPrice(item)
102+ let supplierAddress = getValueItemSupplier(item)
103+ if ((price > pmt.amount))
104+ then throw("purchase amount cannot be less than item price")
105+ else if ((pmt.amount > price))
106+ then throw("purchase amount cannot be higher than item price")
107+ else if ((supplierAddress == NONE))
108+ then throw("supplier does not exist")
109+ else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))])
110+ }
111+ }
112+
113+
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let NONE = "none"
55
66 func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
77
88
99 func getKeyItemSupplier (item) = (item + "_owner")
1010
1111
12+func getKeyBalanceSupplier (item) = (item + "_balance")
13+
14+
1215 func getKeyItemPrice (item) = (item + "_price")
1316
1417
1518 func getKeyItemData (item) = (item + "_data")
19+
20+
21+func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
1622
1723
1824 func getStrByKey (key) = {
1925 let str = match getString(this, key) {
2026 case a: String =>
2127 a
2228 case _ =>
2329 NONE
2430 }
2531 str
2632 }
2733
2834
35+func getNumberByKey (key) = {
36+ let num = match getInteger(this, key) {
37+ case a: Int =>
38+ a
39+ case _ =>
40+ 0
41+ }
42+ num
43+ }
44+
45+
2946 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
3047
3148
49+func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
50+
51+
52+func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
53+
54+
55+func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
56+
57+
3258 @Callable(i)
33-func purchase (type) = {
59+func purchaseOld (type) = {
3460 let pmt = extract(i.payment)
3561 if (isDefined(pmt.assetId))
3662 then throw("can use WAVES only at the moment")
3763 else {
3864 let customerAddress = toBase58String(i.caller.bytes)
3965 let price = match getInteger(this, (("item_" + type) + "_coupon_price")) {
4066 case a: Int =>
4167 a
4268 case _ =>
4369 0
4470 }
4571 if ((price > pmt.amount))
4672 then throw("purschase amount cannot be less than item price")
4773 else if ((pmt.amount > price))
4874 then throw("purchase amount cannot be higher than item price")
4975 else WriteSet([DataEntry(((("status:purchase_item_" + type) + "_customer_") + customerAddress), "confirmed"), DataEntry(((("price:purchase_item_" + type) + "_customer_") + customerAddress), price)])
5076 }
5177 }
5278
5379
5480
5581 @Callable(i)
5682 func addItem (title,price,data) = {
5783 let supplierAddress = toBase58String(i.caller.bytes)
5884 let item = getKeyItem(supplierAddress, title)
5985 if ((0 >= price))
6086 then throw("purchase amount cannot be less than item price")
6187 else if ((getValueItemSupplier(item) != NONE))
6288 then throw("an items is already exist")
6389 else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)])
6490 }
6591
6692
93+
94+@Callable(i)
95+func purchase (item) = {
96+ let pmt = extract(i.payment)
97+ if (isDefined(pmt.assetId))
98+ then throw("WAVES tokens only at the moment")
99+ else {
100+ let userAddress = toBase58String(i.caller.bytes)
101+ let price = getValueItemPrice(item)
102+ let supplierAddress = getValueItemSupplier(item)
103+ if ((price > pmt.amount))
104+ then throw("purchase amount cannot be less than item price")
105+ else if ((pmt.amount > price))
106+ then throw("purchase amount cannot be higher than item price")
107+ else if ((supplierAddress == NONE))
108+ then throw("supplier does not exist")
109+ else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))])
110+ }
111+ }
112+
113+

github/deemru/w8io/026f985 
34.68 ms