tx · HiaxjgkBon59CX7NBhKuMdu6wXGxGEenUYX8JGcE3bsA

3MxS2LBsPnEGA6AetWPqWTZjmQu8zUySd2c:  -0.01000000 Waves

2021.07.06 17:54 [1601899] smart account 3MxS2LBsPnEGA6AetWPqWTZjmQu8zUySd2c > SELF 0.00000000 Waves

{ "type": 13, "id": "HiaxjgkBon59CX7NBhKuMdu6wXGxGEenUYX8JGcE3bsA", "fee": 1000000, "feeAssetId": null, "timestamp": 1625583265127, "version": 2, "chainId": 84, "sender": "3MxS2LBsPnEGA6AetWPqWTZjmQu8zUySd2c", "senderPublicKey": "9dJbLdKrkcPAEacPHvgivaqbGgimy4WN2MRrE6XXWFQu", "proofs": [ "Esps78FgZwXnLBDqFwFh6jPNp9FzmUYsUSgdx23QbwVMbQYXw1mfShkUGrcyz9p5YntAHHZ9qP1RspXpcdAJ9gU" ], "script": "base64:AAIFAAAAAAAAAh0IAhIFCgMIAQgSAwoBCBoKCgJhMRIETk9ORRoUCgJhMhIOZ2V0TnVtYmVyQnlLZXkaCQoCYTMSA2tleRoJCgJhNBIDbnVtGg0KAmE1EgckbWF0Y2gwGgcKAmE2EgFhGhEKAmE3EgtnZXRTdHJCeUtleRoJCgJhOBIDc3RyGhUKAmE5Eg9nZXRLZXlJdGVtUHJpY2UaCgoCYjESBGl0ZW0aFwoCYjISEWdldFZhbHVlSXRlbVByaWNlGhsKAmIzEhVnZXRLZXlVc2VySXRlbUNvdW50ZXIaCgoCYjQSBHVzZXIaHQoCYjUSF2dldFZhbHVlVXNlckl0ZW1Db3VudGVyGhAKAmI2EgpnZXRLZXlJdGVtGg4KAmI3EghzdXBwbGllchoLCgJiOBIFdGl0bGUaFAoCYjkSDmdldEtleUl0ZW1EYXRhGhgKAmMxEhJnZXRLZXlJdGVtU3VwcGxpZXIaGgoCYzISFGdldFZhbHVlSXRlbVN1cHBsaWVyGhsKAmMzEhVnZXRLZXlCYWxhbmNlU3VwcGxpZXIaDQoCYzQSB2FjY291bnQaHQoCYzUS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QAAAAJjNwgFAAAAAmQxAAAABmFtb3VudAkAAAIAAAABAgAAAC5QdXJjaGFzZSBhbW91bnQgY2Fubm90IGJlIGxlc3MgdGhhbiBpdGVtIHByaWNlAwkAAAAAAAACBQAAAAJjOQUAAAACYTEJAAACAAAAAQIAAAAXU3VwcGxpZXIgZG9lcyBub3QgZXhpc3QJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAAAJiMwAAAAIFAAAAAmQyBQAAAAJiMQkAAGQAAAACCQEAAAACYjUAAAACBQAAAAJkMgUAAAACYjEAAAAAAAAAAAEJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAAAJjMwAAAAEFAAAAAmM5CQAAZAAAAAIJAQAAAAJjNQAAAAEFAAAAAmM5CAUAAAACZDEAAAAGYW1vdW50BQAAAANuaWwAAAAARhiIrg==", "height": 1601899, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: BojZK2d3u858GAovt2E22EQS2hqfc8FtnUBKwgPckYTN Next: zwakKpemf7yZ1ytwhjtfUxJLTAeL44dNBzYchFU5MHp Diff:
OldNewDifferences
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let NONE = "none"
5+
6+func getNumberByKey (key) = {
7+ let num = match getInteger(this, key) {
8+ case a: Int =>
9+ a
10+ case _ =>
11+ 0
12+ }
13+ num
14+ }
15+
516
617 func getStrByKey (key) = {
718 let str = match getString(this, key) {
1728 func getKeyItemPrice (item) = (item + "_price")
1829
1930
31+func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
32+
33+
34+func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
35+
36+
37+func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
38+
39+
2040 func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
2141
2242
2747
2848
2949 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
50+
51+
52+func getKeyBalanceSupplier (account) = (account + "_balance")
53+
54+
55+func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
3056
3157
3258 @Callable(i)
4167 }
4268
4369
70+
71+@Callable(i)
72+func purchase (item) = {
73+ let pmt = i.payments[0]
74+ if (isDefined(pmt.assetId))
75+ then throw("WAVES ONLY HHEUAWHEUAS")
76+ else {
77+ let userAddress = toBase58String(i.caller.bytes)
78+ let price = getValueItemPrice(item)
79+ let supplierAddress = getValueItemSupplier(item)
80+ if ((price > pmt.amount))
81+ then throw("Purchase amount cannot be less than item price")
82+ else if ((supplierAddress == NONE))
83+ then throw("Supplier does not exist")
84+ else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]
85+ }
86+ }
87+
88+
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let NONE = "none"
5+
6+func getNumberByKey (key) = {
7+ let num = match getInteger(this, key) {
8+ case a: Int =>
9+ a
10+ case _ =>
11+ 0
12+ }
13+ num
14+ }
15+
516
617 func getStrByKey (key) = {
718 let str = match getString(this, key) {
819 case a: String =>
920 a
1021 case _ =>
1122 NONE
1223 }
1324 str
1425 }
1526
1627
1728 func getKeyItemPrice (item) = (item + "_price")
1829
1930
31+func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
32+
33+
34+func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
35+
36+
37+func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
38+
39+
2040 func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
2141
2242
2343 func getKeyItemData (item) = (item + "_data")
2444
2545
2646 func getKeyItemSupplier (item) = (item + "_owner")
2747
2848
2949 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
50+
51+
52+func getKeyBalanceSupplier (account) = (account + "_balance")
53+
54+
55+func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
3056
3157
3258 @Callable(i)
3359 func addItem (title,price,data) = {
3460 let supplierAddress = toBase58String(i.caller.bytes)
3561 let item = getKeyItem(supplierAddress, title)
3662 if ((0 >= price))
3763 then throw("Purchase amount cannot be less than item price")
3864 else if ((getValueItemSupplier(item) != NONE))
3965 then throw("an item already exists")
4066 else [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)]
4167 }
4268
4369
70+
71+@Callable(i)
72+func purchase (item) = {
73+ let pmt = i.payments[0]
74+ if (isDefined(pmt.assetId))
75+ then throw("WAVES ONLY HHEUAWHEUAS")
76+ else {
77+ let userAddress = toBase58String(i.caller.bytes)
78+ let price = getValueItemPrice(item)
79+ let supplierAddress = getValueItemSupplier(item)
80+ if ((price > pmt.amount))
81+ then throw("Purchase amount cannot be less than item price")
82+ else if ((supplierAddress == NONE))
83+ then throw("Supplier does not exist")
84+ else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]
85+ }
86+ }
87+
88+

github/deemru/w8io/026f985 
37.71 ms