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:
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 | - | ||
16 | 5 | ||
17 | 6 | func getStrByKey (key) = { | |
18 | 7 | let str = match getString(this, key) { | |
28 | 17 | func getKeyItemPrice (item) = (item + "_price") | |
29 | 18 | ||
30 | 19 | ||
31 | - | func | |
20 | + | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
32 | 21 | ||
33 | 22 | ||
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") | |
38 | 24 | ||
39 | 25 | ||
40 | 26 | func getKeyItemSupplier (item) = (item + "_data") | |
43 | 29 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
44 | 30 | ||
45 | 31 | ||
46 | - | func getKeyBalanceSupplier (account) = (account + "_balance") | |
47 | - | ||
48 | - | ||
49 | - | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
50 | - | ||
51 | - | ||
52 | 32 | @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)] | |
69 | 41 | } | |
70 | 42 | ||
71 | 43 |
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 | - | ||
16 | 5 | ||
17 | 6 | func getStrByKey (key) = { | |
18 | 7 | let str = match getString(this, key) { | |
19 | 8 | case a: String => | |
20 | 9 | a | |
21 | 10 | case _ => | |
22 | 11 | NONE | |
23 | 12 | } | |
24 | 13 | str | |
25 | 14 | } | |
26 | 15 | ||
27 | 16 | ||
28 | 17 | func getKeyItemPrice (item) = (item + "_price") | |
29 | 18 | ||
30 | 19 | ||
31 | - | func | |
20 | + | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
32 | 21 | ||
33 | 22 | ||
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") | |
38 | 24 | ||
39 | 25 | ||
40 | 26 | func getKeyItemSupplier (item) = (item + "_data") | |
41 | 27 | ||
42 | 28 | ||
43 | 29 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
44 | 30 | ||
45 | 31 | ||
46 | - | func getKeyBalanceSupplier (account) = (account + "_balance") | |
47 | - | ||
48 | - | ||
49 | - | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
50 | - | ||
51 | - | ||
52 | 32 | @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)] | |
69 | 41 | } | |
70 | 42 | ||
71 | 43 |
github/deemru/w8io/873ac7e 26.12 ms ◑