tx · FL51oRmeyNS12WCyMYgKoJL2Jpnk9aVJXpb4Vdx8q8mE

3NA37aEhY3CSPtrXjKUsNibx5i45P7FxuA4:  -0.01000010 Waves

2021.07.07 13:36 [1603075] smart account 3NA37aEhY3CSPtrXjKUsNibx5i45P7FxuA4 > SELF 0.00000000 Waves

{ "type": 13, "id": "FL51oRmeyNS12WCyMYgKoJL2Jpnk9aVJXpb4Vdx8q8mE", "fee": 1000010, "feeAssetId": null, "timestamp": 1625654283564, "version": 2, "chainId": 84, "sender": "3NA37aEhY3CSPtrXjKUsNibx5i45P7FxuA4", "senderPublicKey": "B3Kkg7AgjdZYrAW5kNXeBi1KfWcjdiHpEnu3tsfirQPy", "proofs": [ "XE3JiPYbd2MEtTQ5vMFiKmVWFzPCW4wTSdVv8tavrzisPLrTnR44YVzTayrstj6BSPgabkHpRNzSeviV8Q2kzEh" ], "script": "base64:AAIFAAAAAAAAAS0IAhIFCgMIAQgaCgoCYTESBE5PTkUaEQoCYTISC2dldFN0ckJ5S2V5GgkKAmEzEgNrZXkaCQoCYTQSA3N0choNCgJhNRIHJG1hdGNoMBoHCgJhNhIBYRoVCgJhNxIPZ2V0S2V5SXRlbVByaWNlGgoKAmE4EgRpdGVtGhAKAmE5EgpnZXRLZXlJdGVtGg4KAmIxEghzdXBwbGllchoLCgJiMhIFdGl0bGUaFAoCYjMSDmdldEtleUl0ZW1EYXRhGhgKAmI0EhJnZXRLZXlJdGVtU3VwcGxpZXIaGgoCYjUSFGdldFZhbHVlSXRlbVN1cHBsaWVyGgcKAmI2EgFpGgsKAmI3EgVwcmljZRoKCgJiOBIEZGF0YRoVCgJiORIPc3VwcGxpZXJBZGRyZXNzAAAABwAAAAACYTECAAAABG5vbmUBAAAAAmEyAAAAAQAAAAJhMwQAAAACYTQEAAAAAmE1CQAEHQAAAAIFAAAABHRoaXMFAAAAAmEzAwkAAAEAAAACBQAAAAJhNQIAAAAGU3RyaW5nBAAAAAJhNgUAAAACYTUFAAAAAmE2BQAAAAJhMQUAAAACYTQBAAAAAmE3AAAAAQAAAAJhOAkAASwAAAACBQAAAAJhOAIAAAAGX3ByaWNlAQAAAAJhOQAAAAIAAAACYjEAAAACYjIJAAEsAAAAAgIAAAAFaXRlbV8JAAJYAAAAAQkAAfcAAAABCQABmwAAAAEJAAEsAAAAAgUAAAACYjEFAAAAAmIyAQAAAAJiMwAAAAEAAAACYTgJAAEsAAAAAgUAAAACYTgCAAAABV9kYXRhAQAAAAJiNAAAAAEAAAACYTgJAAEsAAAAAgUAAAACYTgCAAAABV9kYXRhAQAAAAJiNQAAAAEAAAACYTgJAQAAAAJhMgAAAAEJAQAAAAJiNAAAAAEFAAAAAmE4AAAAAQAAAAJiNgEAAAAHYWRkSXRlbQAAAAMAAAACYjIAAAACYjcAAAACYjgEAAAAAmI5CQACWAAAAAEICAUAAAACYjYAAAAGY2FsbGVyAAAABWJ5dGVzBAAAAAJhOAkBAAAAAmE5AAAAAgUAAAACYjkFAAAAAmIyAwkAAGcAAAACAAAAAAAAAAAABQAAAAJiNwkAAAIAAAABAgAAAC5wdXJjaGFzZSBhbW91bnQgY2Fubm90IGJlIGxlc3MgdGhhbiBpdGVtIHByaWNlAwkBAAAAAiE9AAAAAgkBAAAAAmI1AAAAAQUAAAACYTgFAAAAAmExCQAAAgAAAAECAAAAGGFuIGl0ZW0gaXMgYWxyZWFkeSBleGlzdAkABEwAAAACCQEAAAALU3RyaW5nRW50cnkAAAACCQEAAAACYjQAAAABBQAAAAJhOAUAAAACYjkJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAAAJhNwAAAAEFAAAAAmE4BQAAAAJiNwkABEwAAAACCQEAAAALU3RyaW5nRW50cnkAAAACCQEAAAACYjMAAAABBQAAAAJhOAUAAAACYjgFAAAAA25pbAAAAAA4MCqO", "height": 1603075, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: Hzv75npaNZc1rN2vQWxrsm7A3HG7SY6vmMCXnZiWxJxD Next: GZRz4B2y3cZjDa9GHyfrUkyHzppWjGfMzBdT15nMFY86 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-
165
176 func getStrByKey (key) = {
187 let str = match getString(this, key) {
2817 func getKeyItemPrice (item) = (item + "_price")
2918
3019
31-func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
20+func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
3221
3322
34-func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
35-
36-
37-func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
23+func getKeyItemData (item) = (item + "_data")
3824
3925
4026 func getKeyItemSupplier (item) = (item + "_data")
4329 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
4430
4531
46-func getKeyBalanceSupplier (account) = (account + "_balance")
47-
48-
49-func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
50-
51-
5232 @Callable(i)
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- }
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)]
6941 }
7042
7143
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-
165
176 func getStrByKey (key) = {
187 let str = match getString(this, key) {
198 case a: String =>
209 a
2110 case _ =>
2211 NONE
2312 }
2413 str
2514 }
2615
2716
2817 func getKeyItemPrice (item) = (item + "_price")
2918
3019
31-func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
20+func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
3221
3322
34-func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
35-
36-
37-func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
23+func getKeyItemData (item) = (item + "_data")
3824
3925
4026 func getKeyItemSupplier (item) = (item + "_data")
4127
4228
4329 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
4430
4531
46-func getKeyBalanceSupplier (account) = (account + "_balance")
47-
48-
49-func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
50-
51-
5232 @Callable(i)
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- }
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)]
6941 }
7042
7143

github/deemru/w8io/873ac7e 
26.12 ms