tx · BH8pWegCNZza68T5ffZRFCFWBFNyYy27VvA5VqfE6L6B

3Mz9ndf12uVKYMqYmwUr81wcNLYEgr82ei6:  -0.01400000 Waves

2019.11.15 23:37 [766708] smart account 3Mz9ndf12uVKYMqYmwUr81wcNLYEgr82ei6 > SELF 0.00000000 Waves

{ "type": 13, "id": "BH8pWegCNZza68T5ffZRFCFWBFNyYy27VvA5VqfE6L6B", "fee": 1400000, "feeAssetId": null, "timestamp": 1573850287331, "version": 1, "sender": "3Mz9ndf12uVKYMqYmwUr81wcNLYEgr82ei6", "senderPublicKey": "8bmUdC19peGBa1TGeRZaZfpuDG6yKaGYBd8FQvcBLAXR", "proofs": [ "ZY2fR3CGwE5sWnR5jxH7BV52vGbnpcNDdWxSAh28NNvgzdeUexvGwj6mg9XsGZXWY4H4b13sNspgKtGsaCtX8t1" ], "script": "base64:AAIDAAAAAAAAAAcIARIDCgEIAAAADQAAAAAETk9ORQIAAAAEbm9uZQEAAAAPZ2V0S2V5SXRlbVByaWNlAAAAAQAAAARpdGVtCQABLAAAAAIFAAAABGl0ZW0CAAAABl9wcmljZQEAAAAOZ2V0S2V5SXRlbURhdGEAAAABAAAABGl0ZW0JAAEsAAAAAgUAAAAEaXRlbQIAAAAFX2RhdGEBAAAADmdldEtleUl0ZW1TdXBwAAAAAQAAAARpdGVtCQABLAAAAAIFAAAABGl0ZW0CAAAABl9vd25lcgEAAAALZ2V0U3RyQnlLZXkAAAABAAAAA2tleQQAAAADc3RyBAAAAAckbWF0Y2gwCQAEHQAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAAGU3RyaW5nBAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhBQAAAAROT05FBQAAAANzdHIBAAAACmdldEtleUl0ZW0AAAACAAAABHN1cHAAAAAFdGl0bGUJAAEsAAAAAgIAAAAFaXRlbV8JAAJYAAAAAQkAAfcAAAABCQABmwAAAAEJAAEsAAAAAgUAAAAEc3VwcAU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luZWQAAAABCAUAAAADcG10AAAAB2Fzc2V0SWQJAAACAAAAAQIAAAAKV2F3ZXMgb25seQQAAAAHdXNlckFkcgkAAlgAAAABCAgFAAAAAWkAAAAGY2FsbGVyAAAABWJ5dGVzBAAAAAVwcmljZQkBAAAAEWdldFZhbHVlSXRlbVByaWNlAAAAAQUAAAAEaXRlbQQAAAAHc3VwcEFkcgkBAAAAEGdldFZhbHVlSXRlbVN1cHAAAAABBQAAAARpdGVtAwkAAGYAAAACBQAAAAVwcmljZQgFAAAAA3BtdAAAAAZhbW91bnQJAAACAAAAAQIAAAAXcHVyY2hhc2UgYW1vdW50IDwgcHJpY2UDCQAAZgAAAAIIBQAAAANwbXQAAAAGYW1vdW50BQAAAAVwcmljZQkAAAIAAAABAgAAABdwdXJjaGFzZSBhbW91bnQgPiBwcmljZQMJAAAAAAAAAgUAAAAHc3VwcEFkcgUAAAAETk9ORQkAAAIAAAABAgAAAA5zdXBwIG5vdCBleGlzdAkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAFWdldEtleVVzZXJJdGVtQ291bnRlcgAAAAIFAAAAB3VzZXJBZHIFAAAABGl0ZW0JAABkAAAAAgkBAAAAF2dldFZhbHVlVXNlckl0ZW1Db3VudGVyAAAAAgUAAAAHdXNlckFkcgUAAAAEaXRlbQAAAAAAAAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAEWdldEtleVN1cHBCYWxhbmNlAAAAAQUAAAAHc3VwcEFkcgkAAGQAAAACCQEAAAATZ2V0VmFsdWVTdXBwQmFsYW5jZQAAAAEFAAAAB3N1cHBBZHIIBQAAAANwbXQAAAAGYW1vdW50BQAAAANuaWwAAAAA84rMFA==", "chainId": 84, "height": 766708, "spentComplexity": 0 } View: original | compacted Prev: GPJEegx1E5uYGcgt5ufMgXKCyAzE842gLekm7bGM9bSV Next: 8H87rDQzUsSNTodPrT7ncKhVdCAo1oPipf2QqqTny7k2 Diff:
OldNewDifferences
2929 func getValueItemSupp (item) = getStrByKey(getKeyItemSupp(item))
3030
3131
32+func getNumberByKey (key) = {
33+ let num = match getInteger(this, key) {
34+ case a: Int =>
35+ a
36+ case _ =>
37+ 0
38+ }
39+ num
40+ }
41+
42+
43+func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
44+
45+
46+func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
47+
48+
49+func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
50+
51+
52+func getKeySuppBalance (supp) = (supp + "_balance")
53+
54+
55+func getValueSuppBalance (supp) = getNumberByKey(getKeySuppBalance(supp))
56+
57+
3258 @Callable(i)
33-func addItem (title,price,data) = {
34- let suppAdr = toBase58String(i.caller.bytes)
35- let item = getKeyItem(suppAdr, title)
36- if ((0 >= price))
37- then throw("purchase amount can not be less than price")
38- else if ((getValueItemSupp(item) != NONE))
39- then throw("an item is already exist")
40- else WriteSet([DataEntry(getKeyItemSupp(item), suppAdr), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)])
59+func purchase (item) = {
60+ let pmt = extract(i.payment)
61+ if (isDefined(pmt.assetId))
62+ then throw("Wawes only")
63+ else {
64+ let userAdr = toBase58String(i.caller.bytes)
65+ let price = getValueItemPrice(item)
66+ let suppAdr = getValueItemSupp(item)
67+ if ((price > pmt.amount))
68+ then throw("purchase amount < price")
69+ else if ((pmt.amount > price))
70+ then throw("purchase amount > price")
71+ else if ((suppAdr == NONE))
72+ then throw("supp not exist")
73+ else WriteSet([DataEntry(getKeyUserItemCounter(userAdr, item), (getValueUserItemCounter(userAdr, item) + 1)), DataEntry(getKeySuppBalance(suppAdr), (getValueSuppBalance(suppAdr) + pmt.amount))])
74+ }
4175 }
4276
4377
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let NONE = "none"
55
66 func getKeyItemPrice (item) = (item + "_price")
77
88
99 func getKeyItemData (item) = (item + "_data")
1010
1111
1212 func getKeyItemSupp (item) = (item + "_owner")
1313
1414
1515 func getStrByKey (key) = {
1616 let str = match getString(this, key) {
1717 case a: String =>
1818 a
1919 case _ =>
2020 NONE
2121 }
2222 str
2323 }
2424
2525
2626 func getKeyItem (supp,title) = ("item_" + toBase58String(sha256(toBytes((supp + title)))))
2727
2828
2929 func getValueItemSupp (item) = getStrByKey(getKeyItemSupp(item))
3030
3131
32+func getNumberByKey (key) = {
33+ let num = match getInteger(this, key) {
34+ case a: Int =>
35+ a
36+ case _ =>
37+ 0
38+ }
39+ num
40+ }
41+
42+
43+func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
44+
45+
46+func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
47+
48+
49+func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
50+
51+
52+func getKeySuppBalance (supp) = (supp + "_balance")
53+
54+
55+func getValueSuppBalance (supp) = getNumberByKey(getKeySuppBalance(supp))
56+
57+
3258 @Callable(i)
33-func addItem (title,price,data) = {
34- let suppAdr = toBase58String(i.caller.bytes)
35- let item = getKeyItem(suppAdr, title)
36- if ((0 >= price))
37- then throw("purchase amount can not be less than price")
38- else if ((getValueItemSupp(item) != NONE))
39- then throw("an item is already exist")
40- else WriteSet([DataEntry(getKeyItemSupp(item), suppAdr), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)])
59+func purchase (item) = {
60+ let pmt = extract(i.payment)
61+ if (isDefined(pmt.assetId))
62+ then throw("Wawes only")
63+ else {
64+ let userAdr = toBase58String(i.caller.bytes)
65+ let price = getValueItemPrice(item)
66+ let suppAdr = getValueItemSupp(item)
67+ if ((price > pmt.amount))
68+ then throw("purchase amount < price")
69+ else if ((pmt.amount > price))
70+ then throw("purchase amount > price")
71+ else if ((suppAdr == NONE))
72+ then throw("supp not exist")
73+ else WriteSet([DataEntry(getKeyUserItemCounter(userAdr, item), (getValueUserItemCounter(userAdr, item) + 1)), DataEntry(getKeySuppBalance(suppAdr), (getValueSuppBalance(suppAdr) + pmt.amount))])
74+ }
4175 }
4276
4377

github/deemru/w8io/169f3d6 
40.62 ms