tx · EKC61cF24UvhESRWABKAvwmG1BiZ1EMjb7zDrUh39kdc 3Mzz3QCpMamT89CaFaovqXpnCdiUaKtLZ4D: -0.01400000 Waves 2019.06.22 15:29 [553246] smart account 3Mzz3QCpMamT89CaFaovqXpnCdiUaKtLZ4D > SELF 0.00000000 Waves
{ "type": 13, "id": "EKC61cF24UvhESRWABKAvwmG1BiZ1EMjb7zDrUh39kdc", "fee": 1400000, "feeAssetId": null, "timestamp": 1561206552363, "version": 1, "sender": "3Mzz3QCpMamT89CaFaovqXpnCdiUaKtLZ4D", "senderPublicKey": "BJRaSW2saRv7CcFs3mSYpaVFQSFpZq9rGKnCcRKuKgWv", "proofs": [ "3o7ToWRapbUfLVc9g86oxAHhLp4NdAuWzSAJ23uEm6YHVR1TR1zCPH11AQ4Q1acZFsdeacswSW5rBEc5he2BDm9o" ], "script": "base64:AAIDAAAAAAAAAAAAAAANAAAAAAROT05FAgAAAARub25lAQAAAApnZXRLZXlJdGVtAAAAAgAAAAhzdXBwbGllcgAAAAV0aXRsZQkAASwAAAACAgAAAAVpdGVtXwkAAlgAAAABCQAB9wAAAAEJAAGbAAAAAQkAASwAAAACBQAAAAhzdXBwbGllcgUAAAAFdGl0bGUBAAAAEmdldEtleUl0ZW1TdXBwbGllcgAAAAEAAAAEaXRlbQkAASwAAAACBQAAAARpdGVtAgAAAAZfb3duZXIBAAAAFWdldEtleUJhbGFuY2VTdXBwbGllcgAAAAEAAAAEaXRlbQkAASwAAAACBQAAAARpdGVtAgAAAAhfYmFsYW5jZQEAAAAPZ2V0S2V5SXRlbVByaWNlAAAAAQAAAARpdGVtCQABLAAAAAIFAAAABGl0ZW0CAAAABl9wcmljZQEAAAAOZ2V0S2V5SXRlbURhdGEAAAABAAAABGl0ZW0JAAEsAAAAAgUAAAAEaXRlbQIAAAAFX2RhdGEBAAAAFWdldEtleVVzZXJJdGVtQ291bnRlcgAAAAIAAAAEdXNlcgAAAARpdGVtCQABLAAAAAIJAAEsAAAAAgkAASwAA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AABXByaWNlCQEAAAARZ2V0VmFsdWVJdGVtUHJpY2UAAAABBQAAAARpdGVtBAAAAA9zdXBwbGllckFkZHJlc3MJAQAAABRnZXRWYWx1ZUl0ZW1TdXBwbGllcgAAAAEFAAAABGl0ZW0DCQAAZgAAAAIFAAAABXByaWNlCAUAAAADcG10AAAABmFtb3VudAkAAAIAAAABAgAAAC5wdXJjaGFzZSBhbW91bnQgY2Fubm90IGJlIGxlc3MgdGhhbiBpdGVtIHByaWNlAwkAAGYAAAACCAUAAAADcG10AAAABmFtb3VudAUAAAAFcHJpY2UJAAACAAAAAQIAAAAwcHVyY2hhc2UgYW1vdW50IGNhbm5vdCBiZSBoaWdoZXIgdGhhbiBpdGVtIHByaWNlAwkAAAAAAAACBQAAAA9zdXBwbGllckFkZHJlc3MFAAAABE5PTkUJAAACAAAAAQIAAAAXc3VwcGxpZXIgZG9lcyBub3QgZXhpc3QJAQAAAAhXcml0ZVNldAAAAAEJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAABVnZXRLZXlVc2VySXRlbUNvdW50ZXIAAAACBQAAAAt1c2VyQWRkcmVzcwUAAAAEaXRlbQkAAGQAAAACCQEAAAAXZ2V0VmFsdWVVc2VySXRlbUNvdW50ZXIAAAACBQAAAAt1c2VyQWRkcmVzcwUAAAAEaXRlbQAAAAAAAAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAFWdldEtleUJhbGFuY2VTdXBwbGllcgAAAAEFAAAAD3N1cHBsaWVyQWRkcmVzcwkAAGQAAAACCQEAAAAXZ2V0VmFsdWVCYWxhbmNlU3VwcGxpZXIAAAABBQAAAA9zdXBwbGllckFkZHJlc3MIBQAAAANwbXQAAAAGYW1vdW50BQAAAANuaWwAAAAA+3FiKg==", "chainId": 84, "height": 553246, "spentComplexity": 0 } View: original | compacted Prev: 8UbejayJi9LVB82mvqJxikTYhtgoJ7D5vNPWLksotApM Next: 5Aoq76tGWqzsEqxcGnjCgH7a69CvCm7jyV6jF6KXGYGa Diff:
Old | New | Differences | |
---|---|---|---|
9 | 9 | func getKeyItemSupplier (item) = (item + "_owner") | |
10 | 10 | ||
11 | 11 | ||
12 | + | func getKeyBalanceSupplier (item) = (item + "_balance") | |
13 | + | ||
14 | + | ||
12 | 15 | func getKeyItemPrice (item) = (item + "_price") | |
13 | 16 | ||
14 | 17 | ||
15 | 18 | func getKeyItemData (item) = (item + "_data") | |
19 | + | ||
20 | + | ||
21 | + | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
16 | 22 | ||
17 | 23 | ||
18 | 24 | func getStrByKey (key) = { | |
26 | 32 | } | |
27 | 33 | ||
28 | 34 | ||
35 | + | func getNumberByKey (key) = { | |
36 | + | let num = match getInteger(this, key) { | |
37 | + | case a: Int => | |
38 | + | a | |
39 | + | case _ => | |
40 | + | 0 | |
41 | + | } | |
42 | + | num | |
43 | + | } | |
44 | + | ||
45 | + | ||
29 | 46 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
30 | 47 | ||
31 | 48 | ||
49 | + | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
50 | + | ||
51 | + | ||
52 | + | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
53 | + | ||
54 | + | ||
55 | + | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
56 | + | ||
57 | + | ||
32 | 58 | @Callable(i) | |
33 | - | func | |
59 | + | func purchaseOld (type) = { | |
34 | 60 | let pmt = extract(i.payment) | |
35 | 61 | if (isDefined(pmt.assetId)) | |
36 | 62 | then throw("can use WAVES only at the moment") | |
64 | 90 | } | |
65 | 91 | ||
66 | 92 | ||
93 | + | ||
94 | + | @Callable(i) | |
95 | + | func purchase (item) = { | |
96 | + | let pmt = extract(i.payment) | |
97 | + | if (isDefined(pmt.assetId)) | |
98 | + | then throw("WAVES tokens only at the moment") | |
99 | + | else { | |
100 | + | let userAddress = toBase58String(i.caller.bytes) | |
101 | + | let price = getValueItemPrice(item) | |
102 | + | let supplierAddress = getValueItemSupplier(item) | |
103 | + | if ((price > pmt.amount)) | |
104 | + | then throw("purchase amount cannot be less than item price") | |
105 | + | else if ((pmt.amount > price)) | |
106 | + | then throw("purchase amount cannot be higher than item price") | |
107 | + | else if ((supplierAddress == NONE)) | |
108 | + | then throw("supplier does not exist") | |
109 | + | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
110 | + | } | |
111 | + | } | |
112 | + | ||
113 | + |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let NONE = "none" | |
5 | 5 | ||
6 | 6 | func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title))))) | |
7 | 7 | ||
8 | 8 | ||
9 | 9 | func getKeyItemSupplier (item) = (item + "_owner") | |
10 | 10 | ||
11 | 11 | ||
12 | + | func getKeyBalanceSupplier (item) = (item + "_balance") | |
13 | + | ||
14 | + | ||
12 | 15 | func getKeyItemPrice (item) = (item + "_price") | |
13 | 16 | ||
14 | 17 | ||
15 | 18 | func getKeyItemData (item) = (item + "_data") | |
19 | + | ||
20 | + | ||
21 | + | func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt") | |
16 | 22 | ||
17 | 23 | ||
18 | 24 | func getStrByKey (key) = { | |
19 | 25 | let str = match getString(this, key) { | |
20 | 26 | case a: String => | |
21 | 27 | a | |
22 | 28 | case _ => | |
23 | 29 | NONE | |
24 | 30 | } | |
25 | 31 | str | |
26 | 32 | } | |
27 | 33 | ||
28 | 34 | ||
35 | + | func getNumberByKey (key) = { | |
36 | + | let num = match getInteger(this, key) { | |
37 | + | case a: Int => | |
38 | + | a | |
39 | + | case _ => | |
40 | + | 0 | |
41 | + | } | |
42 | + | num | |
43 | + | } | |
44 | + | ||
45 | + | ||
29 | 46 | func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item)) | |
30 | 47 | ||
31 | 48 | ||
49 | + | func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item)) | |
50 | + | ||
51 | + | ||
52 | + | func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item)) | |
53 | + | ||
54 | + | ||
55 | + | func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account)) | |
56 | + | ||
57 | + | ||
32 | 58 | @Callable(i) | |
33 | - | func | |
59 | + | func purchaseOld (type) = { | |
34 | 60 | let pmt = extract(i.payment) | |
35 | 61 | if (isDefined(pmt.assetId)) | |
36 | 62 | then throw("can use WAVES only at the moment") | |
37 | 63 | else { | |
38 | 64 | let customerAddress = toBase58String(i.caller.bytes) | |
39 | 65 | let price = match getInteger(this, (("item_" + type) + "_coupon_price")) { | |
40 | 66 | case a: Int => | |
41 | 67 | a | |
42 | 68 | case _ => | |
43 | 69 | 0 | |
44 | 70 | } | |
45 | 71 | if ((price > pmt.amount)) | |
46 | 72 | then throw("purschase amount cannot be less than item price") | |
47 | 73 | else if ((pmt.amount > price)) | |
48 | 74 | then throw("purchase amount cannot be higher than item price") | |
49 | 75 | else WriteSet([DataEntry(((("status:purchase_item_" + type) + "_customer_") + customerAddress), "confirmed"), DataEntry(((("price:purchase_item_" + type) + "_customer_") + customerAddress), price)]) | |
50 | 76 | } | |
51 | 77 | } | |
52 | 78 | ||
53 | 79 | ||
54 | 80 | ||
55 | 81 | @Callable(i) | |
56 | 82 | func addItem (title,price,data) = { | |
57 | 83 | let supplierAddress = toBase58String(i.caller.bytes) | |
58 | 84 | let item = getKeyItem(supplierAddress, title) | |
59 | 85 | if ((0 >= price)) | |
60 | 86 | then throw("purchase amount cannot be less than item price") | |
61 | 87 | else if ((getValueItemSupplier(item) != NONE)) | |
62 | 88 | then throw("an items is already exist") | |
63 | 89 | else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)]) | |
64 | 90 | } | |
65 | 91 | ||
66 | 92 | ||
93 | + | ||
94 | + | @Callable(i) | |
95 | + | func purchase (item) = { | |
96 | + | let pmt = extract(i.payment) | |
97 | + | if (isDefined(pmt.assetId)) | |
98 | + | then throw("WAVES tokens only at the moment") | |
99 | + | else { | |
100 | + | let userAddress = toBase58String(i.caller.bytes) | |
101 | + | let price = getValueItemPrice(item) | |
102 | + | let supplierAddress = getValueItemSupplier(item) | |
103 | + | if ((price > pmt.amount)) | |
104 | + | then throw("purchase amount cannot be less than item price") | |
105 | + | else if ((pmt.amount > price)) | |
106 | + | then throw("purchase amount cannot be higher than item price") | |
107 | + | else if ((supplierAddress == NONE)) | |
108 | + | then throw("supplier does not exist") | |
109 | + | else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]) | |
110 | + | } | |
111 | + | } | |
112 | + | ||
113 | + |
github/deemru/w8io/026f985 34.68 ms ◑