tx · 8eP6mHWecBPbeTfkeMpKTWCUnK5veAg1z2j1HzbTrFiH

3Mrik3RqY2jPfkkG7R7UiHLBXGGa3jfMpyT:  -0.01400000 Waves

2019.08.28 00:44 [650160] smart account 3Mrik3RqY2jPfkkG7R7UiHLBXGGa3jfMpyT > SELF 0.00000000 Waves

{ "type": 13, "id": "8eP6mHWecBPbeTfkeMpKTWCUnK5veAg1z2j1HzbTrFiH", "fee": 1400000, "feeAssetId": null, "timestamp": 1566942274371, "version": 1, "sender": "3Mrik3RqY2jPfkkG7R7UiHLBXGGa3jfMpyT", "senderPublicKey": "Di8Ucr8vDr6jZNa27iAQxGMYEW9WSuF6MCBaM3fe9coP", "proofs": [ "53KdETWunxWNrYn1f5fUiBrbh2yntnf2ptk72rdjxKsiuVq7rJixaMr4k3DMMNgJ7ZfnME52vxUqaMa4w4gR8NUz" ], "script": "base64:AAIDAAAAAAAAAAAAAAAdAAAAAAROT05FAgAAAARub25lAAAAAAZWT1RFUlMAAAAAAAAAAAMAAAAABlFVT1JVTQAAAAAAAAAAAgAAAAAGVk9USU5HAgAAAAZ2b3RpbmcAAAAABlJFVkVBTAIAAAAGcmV2ZWFsAAAAAAhGRUFUVVJFRAIAAAAIZmVhdHVyZWQAAAAACERFTElTVEVEAgAAAAhkZWxpc3RlZAEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAADbnVtBAAAAAckbWF0Y2gwCQAEGgAAAAIFAAAABHRoaXMFAAAAA2tleQMJAAABAAAAAgUAAAAHJG1hdGNoMAIAAAADSW50BAAAAAFhBQAAAAckbWF0Y2gwBQAAAAFhAAAAAAAAAAAABQAAAANudW0BAAAAC2dldFN0ckJ5S2V5AAAAAQAAAANrZXkEAAAAA3N0cgQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABYQUAAAAHJG1hdGNoMAUAAAABYQUAAAAETk9ORQ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AAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAAMZ2V0S2V5UmV2ZWFsAAAAAgUAAAAEaXRlbQUAAAAEdXNlcgUAAAAEdm90ZQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAD2dldEtleVZvdGVDb3VudAAAAAIFAAAABGl0ZW0FAAAABHZvdGUFAAAADG5ld1ZvdGVDb3VudAkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgkBAAAAEGdldEtleUl0ZW1TdGF0dXMAAAABBQAAAARpdGVtAwkAAGcAAAACBQAAAAxuZXdWb3RlQ291bnQFAAAABlFVT1JVTQUAAAAEdm90ZQUAAAAGUkVWRUFMBQAAAANuaWwAAAAAjMZYEQ==", "chainId": 84, "height": 650160, "spentComplexity": 0 } View: original | compacted Prev: 5E3iA3mmGDQhoFLTmV5ChfParNXddyYRwFcU8ji6Pi8K Next: none Diff:
OldNewDifferences
163163 }
164164
165165
166+
167+@Callable(i)
168+func voteReveal (item,vote,salt) = {
169+ let user = toBase58String(i.caller.bytes)
170+ let status = getValueItemStatus(item)
171+ let newVoteCount = (getValueVoteCount(item, vote) + 1)
172+ if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, user)))
173+ then throw("reveal data is not valid")
174+ else if ((VOTERS > getValueCommitCount(item)))
175+ then throw("max number of voters is not reached yet")
176+ else if ((getValueReveal(item, user) != NONE))
177+ then throw("user has participated already")
178+ else if (if ((status != VOTING))
179+ then (status != REVEAL)
180+ else false)
181+ then throw(("wrong status - " + status))
182+ else if (if ((vote != FEATURED))
183+ then (vote != DELISTED)
184+ else false)
185+ then throw(("wrong vote - " + vote))
186+ else if (if ((status == FEATURED))
187+ then true
188+ else (status == DELISTED))
189+ then throw("voting has finished already")
190+ else WriteSet([DataEntry(getKeyReveal(item, user), vote), DataEntry(getKeyVoteCount(item, vote), newVoteCount), DataEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM))
191+ then vote
192+ else REVEAL)])
193+ }
194+
195+
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
22 {-# SCRIPT_TYPE ACCOUNT #-}
33 {-# CONTENT_TYPE DAPP #-}
44 let NONE = "none"
55
66 let VOTERS = 3
77
88 let QUORUM = 2
99
1010 let VOTING = "voting"
1111
1212 let REVEAL = "reveal"
1313
1414 let FEATURED = "featured"
1515
1616 let DELISTED = "delisted"
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 getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
4141
4242
4343 func getKeyItemPrice (item) = (item + "_price")
4444
4545
4646 func getKeyItemData (item) = (item + "_data")
4747
4848
4949 func getKeyItemSupplier (item) = (item + "_owner")
5050
5151
5252 func getKeySupplierBalance (account) = (account + "_balance")
5353
5454
5555 func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
5656
5757
5858 func getKeyCommit (item,user) = (((item + "_") + user) + "_commit")
5959
6060
6161 func getKeyCommitCount (item) = (item + "_comcnt")
6262
6363
6464 func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal")
6565
6666
6767 func getKeyItemStatus (item) = (item + "_status")
6868
6969
7070 func getKeyVoteCount (item,vote) = ((item + "_res:") + vote)
7171
7272
7373 func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
7474
7575
7676 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
7777
7878
7979 func getValueSupplierBalance (account) = getNumberByKey(getKeySupplierBalance(account))
8080
8181
8282 func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
8383
8484
8585 func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user))
8686
8787
8888 func getValueCommitCount (item) = getNumberByKey(getKeyCommitCount(item))
8989
9090
9191 func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user))
9292
9393
9494 func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item))
9595
9696
9797 func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote))
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 or equal 0")
106106 else if ((getValueItemSupplier(item) != NONE))
107107 then throw("Item exists already")
108108 else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)])
109109 }
110110
111111
112112
113113 @Callable(i)
114114 func purchase (item) = {
115115 let pmt = extract(i.payment)
116116 if (isDefined(pmt.assetId))
117117 then throw("WAVES only at the 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 ((pmt.amount > price))
125125 then throw("purchase amount cannot be higher than item price")
126126 else if ((supplierAddress == NONE))
127127 then throw("supplier doesn't exists")
128128 else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeySupplierBalance(supplierAddress), (getValueSupplierBalance(supplierAddress) + pmt.amount))])
129129 }
130130 }
131131
132132
133133
134134 @Callable(i)
135135 func withdraw () = {
136136 let supplierAddress = toBase58String(i.caller.bytes)
137137 let balance = getValueSupplierBalance(supplierAddress)
138138 if ((0 >= balance))
139139 then throw("insufficient funds")
140140 else ScriptResult(WriteSet([DataEntry(getKeySupplierBalance(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), balance, unit)]))
141141 }
142142
143143
144144
145145 @Callable(i)
146146 func voteCommit (item,hash) = {
147147 let user = toBase58String(i.caller.bytes)
148148 let commits = getValueCommitCount(item)
149149 let status = getValueItemStatus(item)
150150 if ((commits == VOTERS))
151151 then throw("reached max number of voters")
152152 else if ((getValueCommit(item, user) != NONE))
153153 then throw("user has participated already")
154154 else if ((getKeyItemSupplier(item) == NONE))
155155 then throw("item doesn't exists")
156156 else if (if ((status != NONE))
157157 then (status != VOTING)
158158 else false)
159159 then throw("voting is not possible")
160160 else WriteSet([DataEntry(getKeyCommit(item, user), hash), DataEntry(getKeyCommitCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == (VOTERS - 1)))
161161 then REVEAL
162162 else VOTING)])
163163 }
164164
165165
166+
167+@Callable(i)
168+func voteReveal (item,vote,salt) = {
169+ let user = toBase58String(i.caller.bytes)
170+ let status = getValueItemStatus(item)
171+ let newVoteCount = (getValueVoteCount(item, vote) + 1)
172+ if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, user)))
173+ then throw("reveal data is not valid")
174+ else if ((VOTERS > getValueCommitCount(item)))
175+ then throw("max number of voters is not reached yet")
176+ else if ((getValueReveal(item, user) != NONE))
177+ then throw("user has participated already")
178+ else if (if ((status != VOTING))
179+ then (status != REVEAL)
180+ else false)
181+ then throw(("wrong status - " + status))
182+ else if (if ((vote != FEATURED))
183+ then (vote != DELISTED)
184+ else false)
185+ then throw(("wrong vote - " + vote))
186+ else if (if ((status == FEATURED))
187+ then true
188+ else (status == DELISTED))
189+ then throw("voting has finished already")
190+ else WriteSet([DataEntry(getKeyReveal(item, user), vote), DataEntry(getKeyVoteCount(item, vote), newVoteCount), DataEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM))
191+ then vote
192+ else REVEAL)])
193+ }
194+
195+

github/deemru/w8io/026f985 
29.32 ms