tx · AzAEvBHtfnCsQHcnd61HGPZGaeGjaWBibsxjtDwak3xb

3NA37aEhY3CSPtrXjKUsNibx5i45P7FxuA4:  -0.01000010 Waves

2021.07.07 13:24 [1603064] smart account 3NA37aEhY3CSPtrXjKUsNibx5i45P7FxuA4 > SELF 0.00000000 Waves

{ "type": 13, "id": "AzAEvBHtfnCsQHcnd61HGPZGaeGjaWBibsxjtDwak3xb", "fee": 1000010, "feeAssetId": null, "timestamp": 1625653554112, "version": 2, "chainId": 84, "sender": "3NA37aEhY3CSPtrXjKUsNibx5i45P7FxuA4", "senderPublicKey": "B3Kkg7AgjdZYrAW5kNXeBi1KfWcjdiHpEnu3tsfirQPy", "proofs": [ "2YhbYvP2HhvgfyMH6KgYL21JzRLJxAYV9baymNiy4Sgdm1rXaRqQGpibJoUBr9jdKzpZ5CjtJe7ZErMiSRRDbzGF" ], "script": "base64:AAIFAAAAAAAAAcQIAhIDCgEIGgoKAmExEgROT05FGhQKAmEyEg5nZXROdW1iZXJCeUtleRoJCgJhMxIDa2V5GgkKAmE0EgNudW0aDQoCYTUSByRtYXRjaDAaBwoCYTYSAWEaEQoCYTcSC2dldFN0ckJ5S2V5GgkKAmE4EgNzdHIaFQoCYTkSD2dldEtleUl0ZW1QcmljZRoKCgJiMRIEaXRlbRoXCgJiMhIRZ2V0VmFsdWVJdGVtUHJpY2UaGwoCYjMSFWdldEtleVVzZXJJdGVtQ291bnRlchoKCgJiNBIEdXNlchodCgJiNRIXZ2V0VmFsdWVVc2VySXRlbUNvdW50ZXIaGAoCYjYSEmdldEtleUl0ZW1TdXBwbGllchoaCgJiNxIUZ2V0VmFsdWVJdGVtU3VwcGxpZXIaGwoCYjgSFWdldEtleUJhbGFuY2VTdXBwbGllchoNCgJiORIHYWNjb3VudBodCgJjMRIXZ2V0VmFsdWVCYWxhbmNlU3VwcGxpZXIaBwoCYzISAWkaCQoCYzMSA3BtdBoRCgJjNBILdXNlckFkZHJlc3MaCwoCYzUSBXByaWNlGhQKAmM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AgAAAB5XQVZFUyB0b2tlbiBvbmx5IGF0IHRoZSBtb21lbnQEAAAAAmM0CQACWAAAAAEICAUAAAACYzIAAAAGY2FsbGVyAAAABWJ5dGVzBAAAAAJjNQkBAAAAAmIyAAAAAQUAAAACYjEEAAAAAmM2CQEAAAACYjcAAAABBQAAAAJiMQMJAABmAAAAAgUAAAACYzUIBQAAAAJjMwAAAAZhbW91bnQJAAACAAAAAQIAAAAtcHVyY2hhc2UgYW11bnQgY2Fubm90IGJlIGxlc3MgdGhhbiBpdGVtIHByaWNlAwkAAGYAAAACCAUAAAACYzMAAAAGYW1vdW50BQAAAAJjNQkAAAIAAAABAgAAADBwdXJjaGFzZSBhbW91bnQgY2Fubm90IGJlIGhpZ2hlciB0aGFuIGl0ZW0gcHJpY2UDCQAAAAAAAAIFAAAAAmM2BQAAAAJhMQkAAAIAAAABAgAAAB5TdXBwbGllciBhZGRyZXNzIGRvZXNuJ3QgZXhpc3QJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAAAJiMwAAAAIFAAAAAmM0BQAAAAJiMQkAAGQAAAACCQEAAAACYjUAAAACBQAAAAJjNAUAAAACYjEAAAAAAAAAAAEJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAAAJiOAAAAAEFAAAAAmM2CQAAZAAAAAIJAQAAAAJjMQAAAAEFAAAAAmM2CAUAAAACYzMAAAAGYW1vdW50BQAAAANuaWwAAAAAT0GD2g==", "height": 1603064, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 8d9yAQpheVaENo85ZwCNQ9nhQKMAUqLtw6sgCfEDMxsd Next: vWcCUP2hmEfqY76RapkjBHy55S5VTDW3F2UzJYY9q2P 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
20-func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
31+func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
2132
2233
23-func getKeyItemData (item) = (item + "_data")
34+func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
35+
36+
37+func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
2438
2539
2640 func getKeyItemSupplier (item) = (item + "_data")
2943 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
3044
3145
46+func getKeyBalanceSupplier (account) = (account + "_balance")
47+
48+
49+func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
50+
51+
3252 @Callable(i)
33-func addItem (title,price,data) = {
34- let supplierAddress = toBase58String(i.caller.bytes)
35- let item = getKeyItem(supplierAddress, title)
36- if ((0 >= price))
37- then throw("purchase amount cannot be less than item price")
38- else if ((getValueItemSupplier(item) != NONE))
39- then throw("an item is already exist")
40- else [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)]
53+func purchase (item) = {
54+ let pmt = i.payments[0]
55+ if (isDefined(pmt.assetId))
56+ then throw("WAVES token only at the moment")
57+ else {
58+ let userAddress = toBase58String(i.caller.bytes)
59+ let price = getValueItemPrice(item)
60+ let supplierAddres = getValueItemSupplier(item)
61+ if ((price > pmt.amount))
62+ then throw("purchase amunt cannot be less than item price")
63+ else if ((pmt.amount > price))
64+ then throw("purchase amount cannot be higher than item price")
65+ else if ((supplierAddres == NONE))
66+ then throw("Supplier address doesn't exist")
67+ else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddres), (getValueBalanceSupplier(supplierAddres) + pmt.amount))]
68+ }
4169 }
4270
4371
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
20-func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
31+func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
2132
2233
23-func getKeyItemData (item) = (item + "_data")
34+func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
35+
36+
37+func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
2438
2539
2640 func getKeyItemSupplier (item) = (item + "_data")
2741
2842
2943 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
3044
3145
46+func getKeyBalanceSupplier (account) = (account + "_balance")
47+
48+
49+func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
50+
51+
3252 @Callable(i)
33-func addItem (title,price,data) = {
34- let supplierAddress = toBase58String(i.caller.bytes)
35- let item = getKeyItem(supplierAddress, title)
36- if ((0 >= price))
37- then throw("purchase amount cannot be less than item price")
38- else if ((getValueItemSupplier(item) != NONE))
39- then throw("an item is already exist")
40- else [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)]
53+func purchase (item) = {
54+ let pmt = i.payments[0]
55+ if (isDefined(pmt.assetId))
56+ then throw("WAVES token only at the moment")
57+ else {
58+ let userAddress = toBase58String(i.caller.bytes)
59+ let price = getValueItemPrice(item)
60+ let supplierAddres = getValueItemSupplier(item)
61+ if ((price > pmt.amount))
62+ then throw("purchase amunt cannot be less than item price")
63+ else if ((pmt.amount > price))
64+ then throw("purchase amount cannot be higher than item price")
65+ else if ((supplierAddres == NONE))
66+ then throw("Supplier address doesn't exist")
67+ else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddres), (getValueBalanceSupplier(supplierAddres) + pmt.amount))]
68+ }
4169 }
4270
4371

github/deemru/w8io/026f985 
31.90 ms