tx · AbtkQm8W1J1KqtXfv4YUf9vu1dz1DKbCXkGRJEktJZwW

3Mx6Fhgx2b7Vrcg5cPwmcGx2UTrCsGy16hX:  -0.05000000 Waves

2019.08.21 16:41 [640954] smart account 3Mx6Fhgx2b7Vrcg5cPwmcGx2UTrCsGy16hX > SELF 0.00000000 Waves

{ "type": 13, "id": "AbtkQm8W1J1KqtXfv4YUf9vu1dz1DKbCXkGRJEktJZwW", "fee": 5000000, "feeAssetId": null, "timestamp": 1566394687371, "version": 1, "sender": "3Mx6Fhgx2b7Vrcg5cPwmcGx2UTrCsGy16hX", "senderPublicKey": "rbQBcP925Nu3mB58D4Zw36LLDks2LgrcbshyaiSJSHy", "proofs": [ "2UoQ2tFA5C92xRxUqLDUXJV66fXxwLPwjsmTaf3xTyQ3uRt9tNCEodoJEAvtaaXWEGvicYs3iUiZNwkGxVv2acfd" ], "script": "base64:AAIDAAAAAAAAAAAAAAAdAAAAAAZWT1RFUlMAAAAAAAAAAAMAAAAABlFVT1JVTQAAAAAAAAAAAgAAAAAGVk9USU5HAgAAAAZ2b3RpbmcAAAAABlJFVkVBTAIAAAAGcmV2ZWFsAAAAAAhGRUFUVVJFRAIAAAAIZmVhdHVyZWQAAAAACERFTElTVEVEAgAAAAhkZWxpc3RlZAAAAAAETk9ORQIAAAAEbm9uZQEAAAAOZ2V0TnVtYmVyQnlLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABBoAAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAAA0ludAQAAAABbgUAAAAHJG1hdGNoMAUAAAABbgAAAAAAAAAAAAEAAAALZ2V0U3RyQnlLZXkAAAABAAAAA2tleQQAAAAHJG1hdGNoMAkABB0AAAACBQAAAAR0aGlzBQAAAANrZXkDCQAAAQAAAAIFAAAAByRtYXRjaDACAAAABlN0cmluZwQAAAABcwUAAAAHJG1hdGNoMAUAAAABcwUAAAAETk9ORQEAAAAKZ2V0S2V5SXRlbQA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lCQEAAAAIV3JpdGVTZXQAAAABCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACCQEAAAAMZ2V0S2V5UmV2ZWFsAAAAAgUAAAAEaXRlbQUAAAALdXNlckFkZHJlc3MFAAAABHZvdGUJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAAA9nZXRLZXlWb3RlQ291bnQAAAACBQAAAARpdGVtBQAAAAR2b3RlBQAAAAxuZXdWb3RlQ291bnQJAARMAAAAAgkBAAAACURhdGFFbnRyeQAAAAIJAQAAABBnZXRLZXlJdGVtU3RhdHVzAAAAAQUAAAAEaXRlbQMJAABnAAAAAgUAAAAMbmV3Vm90ZUNvdW50BQAAAAZRVU9SVU0FAAAABHZvdGUFAAAABlJFVkVBTAUAAAADbmlsAAAAACryN54=", "chainId": 84, "height": 640954, "spentComplexity": 0 } View: original | compacted Prev: BDpFoTbsQqGXSdNdUDrDPAvhKWzr6YCYJbJt13pZS5qX Next: none Diff:
OldNewDifferences
157157 }
158158
159159
160+
161+@Callable(i)
162+func voteReveal (item,vote,salt) = {
163+ let userAddress = toBase58String(i.caller.bytes)
164+ let status = getValueItemStatus(item)
165+ let newVoteCount = (getValueVoteCount(item, vote) + 1)
166+ if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, userAddress)))
167+ then throw("reveal data is not valid")
168+ else if ((VOTERS > getValueCommitsCount(item)))
169+ then throw("cannot reveal, some user hasn't voted yet")
170+ else if ((getValueReveal(item, userAddress) != NONE))
171+ then throw("user commit is already revealed")
172+ else if (if ((vote != FEATURED))
173+ then (vote != DELISTED)
174+ else false)
175+ then throw("wrong vote")
176+ else if (if ((status == FEATURED))
177+ then true
178+ else (status == DELISTED))
179+ then throw("vote has finished")
180+ else if (if ((status != VOTING))
181+ then (status != REVEAL)
182+ else false)
183+ then throw("wrong state")
184+ else WriteSet([DataEntry(getKeyReveal(item, userAddress), vote), DataEntry(getKeyVoteCount(item, vote), newVoteCount), DataEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM))
185+ then vote
186+ else REVEAL)])
187+ }
188+
189+
Full:
OldNewDifferences
11 {-# STDLIB_VERSION 3 #-}
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) = match getInteger(this, key) {
1919 case n: Int =>
2020 n
2121 case _ =>
2222 0
2323 }
2424
2525
2626 func getStrByKey (key) = match getString(this, key) {
2727 case s: String =>
2828 s
2929 case _ =>
3030 NONE
3131 }
3232
3333
3434 func getKeyItem (supplier,title) = ("item_" + toBase58String(sha256(toBytes((supplier + title)))))
3535
3636
3737 func getKeyItemSupplier (item) = (item + "_owner")
3838
3939
4040 func getKeyItemPrice (item) = (item + "_price")
4141
4242
4343 func getKeyItemData (item) = (item + "_data")
4444
4545
4646 func getKeyUserItemCounter (user,item) = (((item + "_") + user) + "_cnt")
4747
4848
4949 func getKeyBalanceSupplier (account) = (account + "_account")
5050
5151
5252 func getValueItemPrice (item) = getNumberByKey(getKeyItemPrice(item))
5353
5454
5555 func getValueUserItemCounter (user,item) = getNumberByKey(getKeyUserItemCounter(user, item))
5656
5757
5858 func getValueItemSupplier (item) = getStrByKey(getKeyItemSupplier(item))
5959
6060
6161 func getValueBalanceSupplier (account) = getNumberByKey(getKeyBalanceSupplier(account))
6262
6363
6464 func getKeyCommit (item,user) = (((item + "_") + user) + "_commit")
6565
6666
6767 func getValueCommit (item,user) = getStrByKey(getKeyCommit(item, user))
6868
6969
7070 func getKeyCommitsCount (item) = (item + "_comcnt")
7171
7272
7373 func getValueCommitsCount (item) = getNumberByKey(getKeyCommitsCount(item))
7474
7575
7676 func getKeyReveal (item,user) = (((item + "_") + user) + "_reveal")
7777
7878
7979 func getValueReveal (item,user) = getStrByKey(getKeyReveal(item, user))
8080
8181
8282 func getKeyItemStatus (item) = (item + "_status")
8383
8484
8585 func getValueItemStatus (item) = getStrByKey(getKeyItemStatus(item))
8686
8787
8888 func getKeyVoteCount (item,vote) = ((item + "_res:") + vote)
8989
9090
9191 func getValueVoteCount (item,vote) = getNumberByKey(getKeyVoteCount(item, vote))
9292
9393
9494 @Callable(i)
9595 func addItem (title,price,data) = {
9696 let supplierAddress = toBase58String(i.caller.bytes)
9797 let item = getKeyItem(supplierAddress, title)
9898 if ((0 >= price))
9999 then throw("purchase amount cannot be ess than item price")
100100 else if ((getValueItemSupplier(item) != NONE))
101101 then throw("an item already exists")
102102 else WriteSet([DataEntry(getKeyItemSupplier(item), supplierAddress), DataEntry(getKeyItemPrice(item), price), DataEntry(getKeyItemData(item), data)])
103103 }
104104
105105
106106
107107 @Callable(i)
108108 func purchase (item) = {
109109 let payment = extract(i.payment)
110110 if (isDefined(payment.assetId))
111111 then throw("can use only WAVES token at the moment")
112112 else {
113113 let userAddress = toBase58String(i.caller.bytes)
114114 let price = getValueItemPrice(item)
115115 let supplierAddress = getValueItemSupplier(item)
116116 if ((price > payment.amount))
117117 then throw("purchase price cannot be lower than item price")
118118 else if ((price > payment.amount))
119119 then throw("purchase price cannot be higher than item price")
120120 else if ((supplierAddress == NONE))
121121 then throw("supplier does not exist")
122122 else WriteSet([DataEntry(getKeyUserItemCounter(userAddress, item), (getValueUserItemCounter(userAddress, item) + 1)), DataEntry(getKeyBalanceSupplier(supplierAddress), (getValueBalanceSupplier(supplierAddress) + payment.amount))])
123123 }
124124 }
125125
126126
127127
128128 @Callable(i)
129129 func withdraw () = {
130130 let supplierAddress = toBase58String(i.caller.bytes)
131131 let balance = getValueBalanceSupplier(supplierAddress)
132132 if ((0 >= balance))
133133 then throw("insufficient balance")
134134 else ScriptResult(WriteSet([DataEntry(getKeyBalanceSupplier(supplierAddress), 0)]), TransferSet([ScriptTransfer(addressFromStringValue(supplierAddress), getValueBalanceSupplier(supplierAddress), unit)]))
135135 }
136136
137137
138138
139139 @Callable(i)
140140 func voteCommit (item,hash) = {
141141 let userAddress = toBase58String(i.caller.bytes)
142142 let commits = getValueCommitsCount(item)
143143 let status = getValueItemStatus(item)
144144 if ((commits >= VOTERS))
145145 then throw("reached max num of voters")
146146 else if ((getValueCommit(item, userAddress) != NONE))
147147 then throw("user has already voted")
148148 else if ((getKeyItemSupplier(item) == NONE))
149149 then throw("item does not exist")
150150 else if (if ((status != NONE))
151151 then (status != VOTING)
152152 else false)
153153 then throw("voting is not possible")
154154 else WriteSet([DataEntry(getKeyCommit(item, userAddress), hash), DataEntry(getKeyCommitsCount(item), (commits + 1)), DataEntry(getKeyItemStatus(item), if ((commits == VOTERS))
155155 then REVEAL
156156 else VOTING)])
157157 }
158158
159159
160+
161+@Callable(i)
162+func voteReveal (item,vote,salt) = {
163+ let userAddress = toBase58String(i.caller.bytes)
164+ let status = getValueItemStatus(item)
165+ let newVoteCount = (getValueVoteCount(item, vote) + 1)
166+ if ((toBase58String(sha256(toBytes((vote + salt)))) != getValueCommit(item, userAddress)))
167+ then throw("reveal data is not valid")
168+ else if ((VOTERS > getValueCommitsCount(item)))
169+ then throw("cannot reveal, some user hasn't voted yet")
170+ else if ((getValueReveal(item, userAddress) != NONE))
171+ then throw("user commit is already revealed")
172+ else if (if ((vote != FEATURED))
173+ then (vote != DELISTED)
174+ else false)
175+ then throw("wrong vote")
176+ else if (if ((status == FEATURED))
177+ then true
178+ else (status == DELISTED))
179+ then throw("vote has finished")
180+ else if (if ((status != VOTING))
181+ then (status != REVEAL)
182+ else false)
183+ then throw("wrong state")
184+ else WriteSet([DataEntry(getKeyReveal(item, userAddress), vote), DataEntry(getKeyVoteCount(item, vote), newVoteCount), DataEntry(getKeyItemStatus(item), if ((newVoteCount >= QUORUM))
185+ then vote
186+ else REVEAL)])
187+ }
188+
189+

github/deemru/w8io/026f985 
57.41 ms