tx · 6n65p3oWsh2hGNv3JD15TnWpPGCPTHTeKsfXSP5fcA35

3N4UJUg7pEuSuvKS1QL95AEKhnmCajteTMz:  -0.01000000 Waves

2021.07.07 16:38 [1603247] smart account 3N4UJUg7pEuSuvKS1QL95AEKhnmCajteTMz > SELF 0.00000000 Waves

{ "type": 13, "id": "6n65p3oWsh2hGNv3JD15TnWpPGCPTHTeKsfXSP5fcA35", "fee": 1000000, "feeAssetId": null, "timestamp": 1625665138954, "version": 2, "chainId": 84, "sender": "3N4UJUg7pEuSuvKS1QL95AEKhnmCajteTMz", "senderPublicKey": "83P1tbCSGDinJAD4ucJJ5cUiuS8RUPh4yfUBDtt129Yw", "proofs": [ "4PAzHn2tZcCbGcwBeBjGF2BdCsJHwNubGGuyXeQPvFytyjDkjCxcqvb2WKTmfQ2JeeU19bykhjK2pYBGfXUeqrTK" ], "script": "base64:AAIFAAAAAAAAA9QIAhIFCgMIAQgSAwoBCBIAEgQKAggIEgUKAwgICBoMCgJhMRIGVk9URVJTGgwKAmEyEgZRVU9SVU0aDAoCYTMSBlZPVElORxoMCgJhNBIGUkVWRUFMGg4KAmE1EghGRUFUVVJFRBoOCgJhNhIIREVMSVNURUQaCgoCYTcSBE5PTkUaFAoCYTgSDmdldE51bWJlckJ5S2V5GgkKAmE5EgNrZXkaCQoCYjESA251bRoNCgJiMhIHJG1hdGNoMBoHCgJiMxIBYRoRCgJiNBILZ2V0U3RyQnlLZXkaCQoCYjUSA3N0choSCgJiNhIMZ2V0S2V5Q29tbWl0GgoKAmI3EgRpdGVtGgoKAmI4EgR1c2VyGhQKAmI5Eg5nZXRWYWx1ZUNvbW1pdBoYCgJjMRISZ2V0S2V5Q29tbWl0c0NvdW50GhoKAmMyEhRnZXRWYWx1ZUNvbW1pdHNDb3VudBoSCgJjMxIMZ2V0S2V5UmV2ZWFsGhQKAmM0Eg5nZXRWYWx1ZVJldmVhbBoWCgJjNRIQZ2V0S2V5SXRlbVN0YXR1cxoYCgJjNhISZ2V0V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ACCQEAAAACYzcAAAACBQAAAAJiNwUAAAACYzgFAAAAAmY3CQAETAAAAAIJAQAAAAtTdHJpbmdFbnRyeQAAAAIJAQAAAAJjNQAAAAEFAAAAAmI3AwkAAGcAAAACBQAAAAJmNwUAAAACYTIFAAAAAmM4BQAAAAJhNAUAAAADbmlsAAAAAJc86OE=", "height": 1603247, "applicationStatus": "succeeded", "spentComplexity": 0 } View: original | compacted Prev: 8kDphVseWX7PBnkR1vWy6ZGi4j16wjHTdFMd85j35XYa Next: none Diff:
OldNewDifferences
167167 let user = toBase58String(i.caller.bytes)
168168 let status = getValueItemStatus(item)
169169 let newVoteCount = (getValueVoteCount(item, vote) + 1)
170- if ((VOTERS > getValueCommitsCount(item)))
171- then throw("max num of voters hasnt reached yet")
172- else if ((getValueReveal(item, user) != NONE))
173- then throw("user has already participated")
174- else if (if ((status != VOTING))
175- then (status != REVEAL)
176- else false)
177- then throw("wrong status")
178- else if (if ((vote != FEATURED))
179- then (vote != DELISTED)
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)
180178 else false)
181- then throw("wrong vote")
182- else if (if ((status == FEATURED))
183- then true
184- else (status == DELISTED))
185- then throw("vote has finished")
186- else [StringEntry(getKeyReveal(item, user), vote), IntegerEntry(getKeyVoteCount(item, vote), newVoteCount), StringEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM))
187- then vote
188- else REVEAL)]
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)]
189191 }
190192
191193
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 5 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let VOTERS = 3
55
66 let QUORUM = 2
77
88 let VOTING = "voting"
99
1010 let REVEAL = "reveal"
1111
1212 let FEATURED = "featured"
1313
1414 let DELISTED = "delisted"
1515
1616 let NONE = "none"
1717
1818 func getNumberByKey (key) = {
1919 let num = match getInteger(this, key) {
2020 case a: Int =>
2121 a
2222 case _ =>
2323 0
2424 }
2525 num
2626 }
2727
2828
2929 func getStrByKey (key) = {
3030 let str = match getString(this, key) {
3131 case a: String =>
3232 a
3333 case _ =>
3434 NONE
3535 }
3636 str
3737 }
3838
3939
4040 func getKeyCommit (item,user) = (((item + "_") + user) + "_commit")
4141
4242
4343 func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user))
4444
4545
4646 func getKeyCommitsCount (item) = (item + "_comcnt")
4747
4848
4949 func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item))
5050
5151
5252 func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal")
5353
5454
5555 func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user))
5656
5757
5858 func getKeyItemStatus (item) = (item + "_status")
5959
6060
6161 func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item))
6262
6363
6464 func getKeyVoteCount (item,vote) = ((item + "_res") + vote)
6565
6666
6767 func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote))
6868
6969
7070 func getKeyItemPrice (item) = (item + "_price")
7171
7272
7373 func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
7474
7575
7676 func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
7777
7878
7979 func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
8080
8181
8282 func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
8383
8484
8585 func getKeyItemData (item) = (item + "_data")
8686
8787
8888 func getKeyItemSupplier (item) = (item + "_owner")
8989
9090
9191 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
9292
9393
9494 func getKeyBalanceSupplier (account) = (account + "_balance")
9595
9696
9797 func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
9898
9999
100100 @Callable(i)
101101 func addItem (title,price,data) = {
102102 let supplierAddress = toBase58String(i.caller.bytes)
103103 let item = getKeyItem(supplierAddress, title)
104104 if ((0 >= price))
105105 then throw("Purchase amount cannot be less than item price")
106106 else if ((getValueItemSupplier(item) != NONE))
107107 then throw("an item already exists")
108108 else [StringEntry(getKeyItemSupplier(item), supplierAddress), IntegerEntry(getKeyItemPrice(item), price), StringEntry(getKeyItemData(item), data)]
109109 }
110110
111111
112112
113113 @Callable(i)
114114 func purchase (item) = {
115115 let pmt = i.payments[0]
116116 if (isDefined(pmt.assetId))
117117 then throw("WAVES tokens only at moment")
118118 else {
119119 let userAddress = toBase58String(i.caller.bytes)
120120 let price = getValueItemPrice(item)
121121 let supplierAddress = getValueItemSupplier(item)
122122 if ((price > pmt.amount))
123123 then throw("Purchase amount cannot be less than item price")
124124 else if ((supplierAddress == NONE))
125125 then throw("Supplier does not exist")
126126 else [IntegerEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), IntegerEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + pmt.amount))]
127127 }
128128 }
129129
130130
131131
132132 @Callable(i)
133133 func withdraw () = {
134134 let supplierAddress = toBase58String(i.caller.bytes)
135135 let balance = getValueBalanceSupplier(supplierAddress)
136136 if ((0 >= balance))
137137 then throw("insuficient balance")
138138 else [IntegerEntry(getKeyBalanceSupplier(supplierAddress), 0), ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)]
139139 }
140140
141141
142142
143143 @Callable(i)
144144 func voteCommit (item,hash) = {
145145 let user = toBase58String(i.caller.bytes)
146146 let commits = getValueCommitsCount(item)
147147 let status = getValueItemStatus(item)
148148 if ((commits >= VOTERS))
149149 then throw("reached max num of voters")
150150 else if ((getValueCommit(item, user) != NONE))
151151 then throw("user has already participated")
152152 else if ((getKeyItemSupplier(item) == NONE))
153153 then throw("item does not exist")
154154 else if (if ((status != NONE))
155155 then (status != VOTING)
156156 else false)
157157 then throw("voting is not possible")
158158 else [StringEntry(getKeyCommit(item, user), hash), IntegerEntry(getKeyCommitsCount(item), (commits + 1)), StringEntry(getKeyItemStatus(item), if ((commits == VOTERS))
159159 then REVEAL
160160 else VOTING)]
161161 }
162162
163163
164164
165165 @Callable(i)
166166 func voteReveal (item,vote,salt) = {
167167 let user = toBase58String(i.caller.bytes)
168168 let status = getValueItemStatus(item)
169169 let newVoteCount = (getValueVoteCount(item, vote) + 1)
170- if ((VOTERS > getValueCommitsCount(item)))
171- then throw("max num of voters hasnt reached yet")
172- else if ((getValueReveal(item, user) != NONE))
173- then throw("user has already participated")
174- else if (if ((status != VOTING))
175- then (status != REVEAL)
176- else false)
177- then throw("wrong status")
178- else if (if ((vote != FEATURED))
179- then (vote != DELISTED)
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)
180178 else false)
181- then throw("wrong vote")
182- else if (if ((status == FEATURED))
183- then true
184- else (status == DELISTED))
185- then throw("vote has finished")
186- else [StringEntry(getKeyReveal(item, user), vote), IntegerEntry(getKeyVoteCount(item, vote), newVoteCount), StringEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM))
187- then vote
188- else REVEAL)]
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)]
189191 }
190192
191193

github/deemru/w8io/026f985 
27.99 ms