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:AAIFAAAAAAAAAcQIAhIDCgEIGgoKAmExEgROT05FGhQKAmEyEg5nZXROdW1iZXJCeUtleRoJCgJhMxIDa2V5GgkKAmE0EgNudW0aDQoCYTUSByRtYXRjaDAaBwoCYTYSAWEaEQoCYTcSC2dldFN0ckJ5S2V5GgkKAmE4EgNzdHIaFQoCYTkSD2dldEtleUl0ZW1QcmljZRoKCgJiMRIEaXRlbRoXCgJiMhIRZ2V0VmFsdWVJdGVtUHJpY2UaGwoCYjMSFWdldEtleVVzZXJJdGVtQ291bnRlchoKCgJiNBIEdXNlchodCgJiNRIXZ2V0VmFsdWVVc2VySXRlbUNvdW50ZXIaGAoCYjYSEmdldEtleUl0ZW1TdXBwbGllchoaCgJiNxIUZ2V0VmFsdWVJdGVtU3VwcGxpZXIaGwoCYjgSFWdldEtleUJhbGFuY2VTdXBwbGllchoNCgJiORIHYWNjb3VudBodCgJjMRIXZ2V0VmFsdWVCYWxhbmNlU3VwcGxpZXIaBwoCYzISAWkaCQoCYzMSA3BtdBoRCgJjNBILdXNlckFkZHJlc3MaCwoCYzUSBXByaWNlGhQKAmM2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gAAAB5XQVZFUyB0b2tlbiBvbmx5IGF0IHRoZSBtb21lbnQEAAAAAmM0CQACWAAAAAEICAUAAAACYzIAAAAGY2FsbGVyAAAABWJ5dGVzBAAAAAJjNQkBAAAAAmIyAAAAAQUAAAACYjEEAAAAAmM2CQEAAAACYjcAAAABBQAAAAJiMQMJAABmAAAAAgUAAAACYzUIBQAAAAJjMwAAAAZhbW91bnQJAAACAAAAAQIAAAAtcHVyY2hhc2UgYW11bnQgY2Fubm90IGJlIGxlc3MgdGhhbiBpdGVtIHByaWNlAwkAAGYAAAACCAUAAAACYzMAAAAGYW1vdW50BQAAAAJjNQkAAAIAAAABAgAAADBwdXJjaGFzZSBhbW91bnQgY2Fubm90IGJlIGhpZ2hlciB0aGFuIGl0ZW0gcHJpY2UDCQAAAAAAAAIFAAAAAmM2BQAAAAJhMQkAAAIAAAABAgAAAB5TdXBwbGllciBhZGRyZXNzIGRvZXNuJ3QgZXhpc3QJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAAAJiMwAAAAIFAAAAAmM0BQAAAAJiMQkAAGQAAAACCQEAAAACYjUAAAACBQAAAAJjNAUAAAACYjEAAAAAAAAAAAEJAARMAAAAAgkBAAAADEludGVnZXJFbnRyeQAAAAIJAQAAAAJiOAAAAAEFAAAAAmM2CQAAZAAAAAIJAQAAAAJjMQAAAAEFAAAAAmM2CAUAAAACYzMAAAAGYW1vdW50BQAAAANuaWwAAAAAT0GD2g==", "height": 1603064, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 8d9yAQpheVaENo85ZwCNQ9nhQKMAUqLtw6sgCfEDMxsd Next: vWcCUP2hmEfqY76RapkjBHy55S5VTDW3F2UzJYY9q2P Diff:
Old | New | Differences | |
---|---|---|---|
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | 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 | + | ||
5 | 16 | ||
6 | 17 | func getStrByKey (key) = { | |
7 | 18 | let str = match getString(this, key) { | |
17 | 28 | func getKeyItemPrice (item) = (item + "_price") | |
18 | 29 | ||
19 | 30 | ||
20 | - | func | |
31 | + | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
21 | 32 | ||
22 | 33 | ||
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)) | |
24 | 38 | ||
25 | 39 | ||
26 | 40 | func getKeyItemSupplier (item) = (item + "_data") | |
29 | 43 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
30 | 44 | ||
31 | 45 | ||
46 | + | func getKeyBalanceSupplier (account) = (account + "_balance") | |
47 | + | ||
48 | + | ||
49 | + | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
50 | + | ||
51 | + | ||
32 | 52 | @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 | + | } | |
41 | 69 | } | |
42 | 70 | ||
43 | 71 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 5 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | 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 | + | ||
5 | 16 | ||
6 | 17 | func getStrByKey (key) = { | |
7 | 18 | let str = match getString(this, key) { | |
8 | 19 | case a: String => | |
9 | 20 | a | |
10 | 21 | case _ => | |
11 | 22 | NONE | |
12 | 23 | } | |
13 | 24 | str | |
14 | 25 | } | |
15 | 26 | ||
16 | 27 | ||
17 | 28 | func getKeyItemPrice (item) = (item + "_price") | |
18 | 29 | ||
19 | 30 | ||
20 | - | func | |
31 | + | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
21 | 32 | ||
22 | 33 | ||
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)) | |
24 | 38 | ||
25 | 39 | ||
26 | 40 | func getKeyItemSupplier (item) = (item + "_data") | |
27 | 41 | ||
28 | 42 | ||
29 | 43 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
30 | 44 | ||
31 | 45 | ||
46 | + | func getKeyBalanceSupplier (account) = (account + "_balance") | |
47 | + | ||
48 | + | ||
49 | + | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
50 | + | ||
51 | + | ||
32 | 52 | @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 | + | } | |
41 | 69 | } | |
42 | 70 | ||
43 | 71 |
github/deemru/w8io/026f985 31.90 ms ◑