tx · 8NzfwXosbiq7Uo6foiJ7DoBBrhkPLAvZP9fN5bouiB23

3Mxc1WtkzRarwxjRG1VSTgoPPynuS3q196Y:  -0.01000000 Waves

2021.07.09 10:09 [1605757] smart account 3Mxc1WtkzRarwxjRG1VSTgoPPynuS3q196Y > SELF 0.00000000 Waves

{ "type": 13, "id": "8NzfwXosbiq7Uo6foiJ7DoBBrhkPLAvZP9fN5bouiB23", "fee": 1000000, "feeAssetId": null, "timestamp": 1625814617116, "version": 2, "chainId": 84, "sender": "3Mxc1WtkzRarwxjRG1VSTgoPPynuS3q196Y", "senderPublicKey": "9DTfiDzKQLuATT7gasgcj1kBn8VLJHjuBKJipCXbUJjr", "proofs": [ "3YP7xC9bJ68UcX1UKNosWiVVWqB6i5GpLo371Z4EiGTHSUsdPqfR1ZmZRdQPe61r26f6x9p988xv7AqreexJYBjT" ], "script": "base64:AAIFAAAAAAAAAGIIAhIDCgEIGgcKAmExEgFpGgkKAmEyEgN2YWwaCQoCYTMSA3BtdBoVCgJhNBIPY3VzdG9tZXJBZGRyZXNzGgsKAmE1EgVwcmljZRoNCgJhNhIHJG1hdGNoMBoHCgJhNxIBYQAAAAAAAAABAAAAAmExAQAAAAhwdXJjaGFzZQAAAAEAAAACYTIEAAAAAmEzCQABkQAAAAIIBQAAAAJhMQAAAAhwYXltZW50cwAAAAAAAAAAAAMJAQAAAAlpc0RlZmluZWQAAAABCAUAAAACYTMAAAAHYXNzZXRJZAkAAAIAAAABAgAAABV3b3JrcyB3aXRoIHdhdmVzIG9ubHkEAAAAAmE0CQACWAAAAAEICAUAAAACYTEAAAAGY2FsbGVyAAAABWJ5dGVzBAAAAAJhNQQAAAACYTYJAAQaAAAAAgUAAAAEdGhpcwkAASwAAAACAgAAAAVpdGVtXwUAAAACYTIDCQAAAQAAAAIFAAAAAmE2AgAAAANJbnQEAAAAAmE3BQAAAAJhNgUAAAACYTcAAAAAAAAAAAADCQAAZgAAAAIIBQAAAAJhMwAAAAZhbW91bnQFAAAAAmE1CQAAAgAAAAECAAAAB3phIGR1em8DCQAAZgAAAAIFAAAAAmE1CAUAAAACYTMAAAAGYW1vdW50CQAAAgAAAAECAAAAB1phIG1hbG8JAARMAAAAAgkBAAAAC1N0cmluZ0VudHJ5AAAAAgkAASwAAAACCQABLAAAAAIJAAEsAAAAAgIAAAAVc3RhdHVzOnB1cmNoYXNlX2l0ZW1fBQAAAAJhMgIAAAAKX2N1c3RvbWVyXwUAAAACYTQCAAAACWNvbmZpcm1lZAkABEwAAAACCQEAAAAMSW50ZWdlckVudHJ5AAAAAgkAASwAAAACCQABLAAAAAIJAAEsAAAAAgIAAAAUcHJpY2U6cHVyY2hhc2VfaXRlbV8FAAAAAmEyAgAAAApfY3VzdG9tZXJfBQAAAAJhNAUAAAACYTUFAAAAA25pbAAAAAC9Iqoi", "height": 1605757, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 9RD6xmkxztbqVzmMLunnJhzq2HXJTdmz6T97RcctUtAu Next: none Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
4-let VOTERS = 3
5-
6-let QUORUM = 2
7-
8-let VOTING = "voting"
9-
10-let REVEAL = "reveal"
11-
12-let FEATURED = "featured"
13-
14-let DELISTED = "delisted"
15-
16-let NONE = "none"
17-
18-func getNumberByKey (key) = {
19- let num = match getInteger(this, key) {
20- case a: Int =>
21- a
22- case _ =>
23- 0
24- }
25- num
26- }
27-
28-
29-func getStrByKey (key) = {
30- let str = match getString(this, key) {
31- case a: String =>
32- a
33- case _ =>
34- NONE
35- }
36- str
37- }
38-
39-
40-func getKeyCommit (item,user) = (((item + "_") + user) + "_commit")
41-
42-
43-func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user))
44-
45-
46-func getKeyCommitsCount (item) = (item + "_comcnt")
47-
48-
49-func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item))
50-
51-
52-func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal")
53-
54-
55-func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user))
56-
57-
58-func getKeyItemStatus (item) = (item + "_status")
59-
60-
61-func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item))
62-
63-
64-func getKeyVoteCount (item,vote) = ((item + "_res") + vote)
65-
66-
67-func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote))
68-
69-
70-func getKeyItemPrice (item) = (item + "_price")
71-
72-
73-func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
74-
75-
76-func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
77-
78-
79-func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
80-
81-
82-func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
83-
84-
85-func getKeyItemData (item) = (item + "_data")
86-
87-
88-func getKeyItemSupplier (item) = (item + "_owner")
89-
90-
91-func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
92-
93-
94-func getKeyBalanceSupplier (account) = (account + "_balance")
95-
96-
97-func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
984
995
1006 @Callable(i)
101-func addItem (title,price,data) = {
102- let supplierAddress = toBase58String(i.caller.bytes)
103- let item = getKeyItem(supplierAddress, title)
104- if ((0 >= price))
105- then throw("Purchase amount cannot be less than item price")
106- else if ((getValueItemSupplier(item) != NONE))
107- then throw("an item already exists")
108- else [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)]
109- }
110-
111-
112-
113-@Callable(i)
114-func purchase (item) = {
7+func purchase (val) = {
1158 let pmt = i.payments[0]
1169 if (isDefined(pmt.assetId))
117- then throw("WAVES tokens only at moment")
10+ then throw("works with waves only")
11811 else {
119- let userAddress = toBase58String(i.caller.bytes)
120- let price = getValueItemPrice(item)
121- let supplierAddress = getValueItemSupplier(item)
122- if ((price > pmt.amount))
123- then throw("Purchase amount cannot be less than item price")
124- else if ((supplierAddress == NONE))
125- then throw("Supplier does not exist")
126- else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]
12+ let customerAddress = toBase58String(i.caller.bytes)
13+ let price = match getInteger(this, ("item_" + val)) {
14+ case a: Int =>
15+ a
16+ case _ =>
17+ 0
12718 }
128- }
129-
130-
131-
132-@Callable(i)
133-func withdraw () = {
134- let supplierAddress = toBase58String(i.caller.bytes)
135- let balance = getValueBalanceSupplier(supplierAddress)
136- if ((0 >= balance))
137- then throw("insuficient balance")
138- else [IntegerEntry(getKeyBalanceSupplier(supplierAddress), 0), ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)]
139- }
140-
141-
142-
143-@Callable(i)
144-func voteCommit (item,hash) = {
145- let user = toBase58String(i.caller.bytes)
146- let commits = getValueCommitsCount(item)
147- let status = getValueItemStatus(item)
148- if ((commits >= VOTERS))
149- then throw("reached max num of voters")
150- else if ((getValueCommit(item, user) != NONE))
151- then throw("user has already participated")
152- else if ((getKeyItemSupplier(item) == NONE))
153- then throw("item does not exist")
154- else if (if ((status != NONE))
155- then (status != VOTING)
156- else false)
157- then throw("voting is not possible")
158- else [StringEntry(getKeyCommit(item, user), hash), IntegerEntry(getKeyCommitsCount(item), (commits + 1)), StringEntry(getKeyItemStatus(item), if ((commits == VOTERS))
159- then REVEAL
160- else VOTING)]
161- }
162-
163-
164-
165-@Callable(i)
166-func voteReveal (item,vote,salt) = {
167- let user = toBase58String(i.caller.bytes)
168- let status = getValueItemStatus(item)
169- let newVoteCount = (getValueVoteCount(item, vote) + 1)
170- if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, user)))
171- then throw("reveal data is not valid")
172- else if ((VOTERS > getValueCommitsCount(item)))
173- then throw("max num of voters hasnt reached yet")
174- else if ((getValueReveal(item, user) != NONE))
175- then throw("user has already participated")
176- else if (if ((status != VOTING))
177- then (status != REVEAL)
178- else false)
179- then throw("wrong status")
180- else if (if ((vote != FEATURED))
181- then (vote != DELISTED)
182- else false)
183- then throw("wrong vote")
184- else if (if ((status == FEATURED))
185- then true
186- else (status == DELISTED))
187- then throw("vote has finished")
188- else [StringEntry(getKeyReveal(item, user), vote), IntegerEntry(getKeyVoteCount(item, vote), newVoteCount), StringEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM))
189- then vote
190- else REVEAL)]
19+ if ((pmt.amount > price))
20+ then throw("za duzo")
21+ else if ((price > pmt.amount))
22+ then throw("Za malo")
23+ else [StringEntry(((("status:purchase_item_" + val) + "_customer_") + customerAddress), "confirmed"), IntegerEntry(((("price:purchase_item_" + val) + "_customer_") + customerAddress), price)]
24+ }
19125 }
19226
19327

github/deemru/w8io/873ac7e 
30.48 ms