1 | 1 | | {-# STDLIB_VERSION 6 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 4 | | let separator = "__" |
---|
5 | 5 | | |
---|
6 | 6 | | let maxDepthDefault = 10 |
---|
7 | 7 | | |
---|
8 | 8 | | func asInt (val) = match val { |
---|
9 | 9 | | case valInt: Int => |
---|
10 | 10 | | valInt |
---|
11 | 11 | | case _ => |
---|
12 | 12 | | throw("Failed to cast into Integer") |
---|
13 | 13 | | } |
---|
14 | 14 | | |
---|
15 | 15 | | |
---|
16 | 16 | | func asBool (val) = match val { |
---|
17 | 17 | | case valBool: Boolean => |
---|
18 | 18 | | valBool |
---|
19 | 19 | | case _ => |
---|
20 | 20 | | throw("Failed to cast into Boolean") |
---|
21 | 21 | | } |
---|
22 | 22 | | |
---|
23 | 23 | | |
---|
24 | 24 | | let keyFeeAmount = makeString(["%s", "fee"], separator) |
---|
25 | 25 | | |
---|
26 | 26 | | let keyWxAssetId = makeString(["%s", "wxAssetId"], separator) |
---|
27 | 27 | | |
---|
28 | 28 | | let keyVotingThreshold = makeString(["%s", "votingThreshold"], separator) |
---|
29 | 29 | | |
---|
30 | 30 | | let keyVotingDuration = makeString(["%s", "epochLength"], separator) |
---|
31 | 31 | | |
---|
32 | 32 | | let keyVoteBeforeElimination = makeString(["%s", "voteBeforeElimination"], separator) |
---|
33 | 33 | | |
---|
34 | 34 | | let keyStartHeight = makeString(["%s", "currentVotingHeightStart"], separator) |
---|
35 | 35 | | |
---|
36 | 36 | | let keyCurrentPeriod = makeString(["%s", "currentEpoch"], separator) |
---|
37 | 37 | | |
---|
38 | 38 | | let keyBoostingContract = makeString(["%s", "boostingContract"], separator) |
---|
39 | 39 | | |
---|
40 | 40 | | let keyEmissionContract = makeString(["%s", "emissionContract"], separator) |
---|
41 | 41 | | |
---|
42 | 42 | | let keyAssetsStoreContract = makeString(["%s", "assetsStoreContract"], separator) |
---|
43 | 43 | | |
---|
44 | 44 | | let keyLatestProcessedAsset = makeString(["%s", "latestProcessedAsset"], separator) |
---|
45 | 45 | | |
---|
46 | 46 | | let keyLatestProcessedUser = makeString(["%s", "latestProcessedUser"], separator) |
---|
47 | 47 | | |
---|
48 | 48 | | let keyLatestProcessedUserRemove = makeString(["%s", "latestProcessedUserRemove"], separator) |
---|
49 | 49 | | |
---|
50 | 50 | | let keyLatestProcessedAssetTransfer = makeString(["%s", "latestProcessedAssetTransfer"], separator) |
---|
51 | 51 | | |
---|
52 | 52 | | let keyLatestProcessedUserTransfer = makeString(["%s", "latestProcessedUserTransfer"], separator) |
---|
53 | 53 | | |
---|
54 | 54 | | let keyLatestProcessedUserRemoveTransfer = makeString(["%s", "latestProcessedUserRemoveTransfer"], separator) |
---|
55 | 55 | | |
---|
56 | 56 | | let keyMaxDepth = makeString(["%s", "maxDepth"], separator) |
---|
57 | 57 | | |
---|
58 | 58 | | func keyVotesTransferFinishedByPeriod (period) = makeString(["%s", "votesTransferFinished", toString(period)], separator) |
---|
59 | 59 | | |
---|
60 | 60 | | |
---|
61 | 61 | | let assetsListName = "__assets" |
---|
62 | 62 | | |
---|
63 | 63 | | func getVotesListName (assetId) = ("%s__votes__" + assetId) |
---|
64 | 64 | | |
---|
65 | 65 | | |
---|
66 | 66 | | func keyListHead (listName) = makeString([("%s%s" + listName), "head"], separator) |
---|
67 | 67 | | |
---|
68 | 68 | | |
---|
69 | 69 | | func keyListSize (listName) = makeString([("%s%s" + listName), "size"], separator) |
---|
70 | 70 | | |
---|
71 | 71 | | |
---|
72 | 72 | | func keyListPrev (listName,id) = makeString([("%s%s%s" + listName), id, "prev"], separator) |
---|
73 | 73 | | |
---|
74 | 74 | | |
---|
75 | 75 | | func keyListNext (listName,id) = makeString([("%s%s%s" + listName), id, "next"], separator) |
---|
76 | 76 | | |
---|
77 | 77 | | |
---|
78 | 78 | | func keyAssetVerifiedByPeriod (assetId,period) = makeString(["%s%d%s", "verifiedAt", toString(period), assetId], separator) |
---|
79 | 79 | | |
---|
80 | 80 | | |
---|
81 | 81 | | func keyAssetVerified (assetId) = makeString(["%s%s", "verified", assetId], separator) |
---|
82 | 82 | | |
---|
83 | 83 | | |
---|
84 | 84 | | func keyAssetWasEliminated (assetId,period) = makeString(["%s%s%d", "eliminated", assetId, toString(period)], separator) |
---|
85 | 85 | | |
---|
86 | 86 | | |
---|
87 | 87 | | func keyVoteResultByPeriod (assetId,period) = makeString(["%s%d%s", "votingResultAtAsset", toString(period), assetId], separator) |
---|
88 | 88 | | |
---|
89 | 89 | | |
---|
90 | 90 | | func formatVoteResult (totalYes,totalNo,verified) = makeString(["%d%d%s", toString(totalYes), toString(totalNo), toString(verified)], separator) |
---|
91 | 91 | | |
---|
92 | 92 | | |
---|
93 | 93 | | func parseVoteResult (input) = { |
---|
94 | 94 | | let parts = split(input, separator) |
---|
95 | 95 | | let totalYesIdx = 1 |
---|
96 | 96 | | let totalNoIdx = 2 |
---|
97 | 97 | | let verifiedIdx = 3 |
---|
98 | 98 | | let totalYes = parseIntValue(parts[totalYesIdx]) |
---|
99 | 99 | | let totalNo = parseIntValue(parts[totalNoIdx]) |
---|
100 | 100 | | let verified = if ((size(parts) == 4)) |
---|
101 | 101 | | then (parts[verifiedIdx] == "true") |
---|
102 | 102 | | else false |
---|
103 | 103 | | $Tuple3(totalYes, totalNo, verified) |
---|
104 | 104 | | } |
---|
105 | 105 | | |
---|
106 | 106 | | |
---|
107 | 107 | | func keyUserVoteByPeriod (userAddress,assetId,period) = makeString(["%s%d%s%s", "vru", toString(period), assetId, userAddress], separator) |
---|
108 | 108 | | |
---|
109 | 109 | | |
---|
110 | 110 | | func formatUserVote (total,inFavor) = { |
---|
111 | 111 | | let totalYes = if (inFavor) |
---|
112 | 112 | | then total |
---|
113 | 113 | | else 0 |
---|
114 | 114 | | let totalNo = if (inFavor) |
---|
115 | 115 | | then 0 |
---|
116 | 116 | | else total |
---|
117 | 117 | | makeString(["%d%d", toString(totalYes), toString(totalNo)], separator) |
---|
118 | 118 | | } |
---|
119 | 119 | | |
---|
120 | 120 | | |
---|
121 | 121 | | func parseUserVote (input) = { |
---|
122 | 122 | | let parts = split(input, separator) |
---|
123 | 123 | | let totalYesIdx = 1 |
---|
124 | 124 | | let totalNoIdx = 2 |
---|
125 | 125 | | let totalYes = parseIntValue(parts[totalYesIdx]) |
---|
126 | 126 | | let totalNo = parseIntValue(parts[totalNoIdx]) |
---|
127 | 127 | | let inFavor = if ((totalYes > 0)) |
---|
128 | 128 | | then (totalNo == 0) |
---|
129 | 129 | | else false |
---|
130 | 130 | | let against = if ((totalYes == 0)) |
---|
131 | 131 | | then (totalNo > 0) |
---|
132 | 132 | | else false |
---|
133 | 133 | | let checkTotals = if (if (inFavor) |
---|
134 | 134 | | then true |
---|
135 | 135 | | else against) |
---|
136 | 136 | | then true |
---|
137 | 137 | | else throw("Invalid user vote value") |
---|
138 | 138 | | if ((checkTotals == checkTotals)) |
---|
139 | 139 | | then { |
---|
140 | 140 | | let total = if (inFavor) |
---|
141 | 141 | | then totalYes |
---|
142 | 142 | | else totalNo |
---|
143 | 143 | | $Tuple2(total, inFavor) |
---|
144 | 144 | | } |
---|
145 | 145 | | else throw("Strict value is not equal to itself.") |
---|
146 | 146 | | } |
---|
147 | 147 | | |
---|
148 | 148 | | |
---|
149 | 149 | | func keyUserVoteHistory (type,userAddress,assetId,txId,period) = makeString(["%s%s%s%s%s%d", "history", type, assetId, userAddress, txId, toString(period)], separator) |
---|
150 | 150 | | |
---|
151 | 151 | | |
---|
152 | 152 | | func keyManagerVaultAddress () = "%s__managerVaultAddress" |
---|
153 | 153 | | |
---|
154 | 154 | | |
---|
155 | 155 | | func keyManagerPublicKey () = "%s__managerPublicKey" |
---|
156 | 156 | | |
---|
157 | 157 | | |
---|
158 | 158 | | func thisOnly (i) = if ((i.caller == this)) |
---|
159 | 159 | | then true |
---|
160 | 160 | | else throw("Permission denied") |
---|
161 | 161 | | |
---|
162 | 162 | | |
---|
163 | 163 | | func getIntegerOrZero (key) = valueOrElse(getInteger(this, key), 0) |
---|
164 | 164 | | |
---|
165 | 165 | | |
---|
166 | 166 | | func getIntegerOrFail (key) = valueOrErrorMessage(getInteger(this, key), (key + " is not defined")) |
---|
167 | 167 | | |
---|
168 | 168 | | |
---|
169 | 169 | | func getStringOrEmpty (key) = valueOrElse(getString(this, key), "") |
---|
170 | 170 | | |
---|
171 | 171 | | |
---|
172 | 172 | | func getStringOrFail (key) = valueOrErrorMessage(getString(this, key), (key + " is not defined")) |
---|
173 | 173 | | |
---|
174 | 174 | | |
---|
175 | 175 | | let feeAmount = getIntegerOrFail(keyFeeAmount) |
---|
176 | 176 | | |
---|
177 | 177 | | let wxAssetId = fromBase58String(getStringOrFail(keyWxAssetId)) |
---|
178 | 178 | | |
---|
179 | 179 | | let votingThreshold = getIntegerOrFail(keyVotingThreshold) |
---|
180 | 180 | | |
---|
181 | 181 | | let votingDuration = getIntegerOrFail(keyVotingDuration) |
---|
182 | 182 | | |
---|
183 | 183 | | let voteBeforeElimination = getIntegerOrFail(keyVoteBeforeElimination) |
---|
184 | 184 | | |
---|
185 | 185 | | let startHeight = getIntegerOrFail(keyStartHeight) |
---|
186 | 186 | | |
---|
187 | 187 | | let currentPeriod = getIntegerOrFail(keyCurrentPeriod) |
---|
188 | 188 | | |
---|
189 | 189 | | let boostingContract = addressFromStringValue(getStringOrFail(keyBoostingContract)) |
---|
190 | 190 | | |
---|
191 | 191 | | let emissionContract = addressFromStringValue(getStringOrFail(keyEmissionContract)) |
---|
192 | 192 | | |
---|
193 | 193 | | let assetsStoreContract = addressFromStringValue(getStringOrFail(keyAssetsStoreContract)) |
---|
194 | 194 | | |
---|
195 | 195 | | let maxDepth = valueOrElse(getInteger(keyMaxDepth), maxDepthDefault) |
---|
196 | 196 | | |
---|
197 | 197 | | let endHeight = (startHeight + votingDuration) |
---|
198 | 198 | | |
---|
199 | 199 | | func getManagerVaultAddressOrThis () = match getString(keyManagerVaultAddress()) { |
---|
200 | 200 | | case s: String => |
---|
201 | 201 | | addressFromStringValue(s) |
---|
202 | 202 | | case _ => |
---|
203 | 203 | | this |
---|
204 | 204 | | } |
---|
205 | 205 | | |
---|
206 | 206 | | |
---|
207 | 207 | | func managerPublicKeyOrUnit () = { |
---|
208 | 208 | | let managerVaultAddress = getManagerVaultAddressOrThis() |
---|
209 | 209 | | match getString(managerVaultAddress, keyManagerPublicKey()) { |
---|
210 | 210 | | case s: String => |
---|
211 | 211 | | fromBase58String(s) |
---|
212 | 212 | | case _: Unit => |
---|
213 | 213 | | unit |
---|
214 | 214 | | case _ => |
---|
215 | 215 | | throw("Match error") |
---|
216 | 216 | | } |
---|
217 | 217 | | } |
---|
218 | 218 | | |
---|
219 | 219 | | |
---|
220 | 220 | | func isManager (i) = match managerPublicKeyOrUnit() { |
---|
221 | 221 | | case pk: ByteVector => |
---|
222 | 222 | | (i.callerPublicKey == pk) |
---|
223 | 223 | | case _: Unit => |
---|
224 | 224 | | (i.caller == this) |
---|
225 | 225 | | case _ => |
---|
226 | 226 | | throw("Match error") |
---|
227 | 227 | | } |
---|
228 | 228 | | |
---|
229 | 229 | | |
---|
230 | 230 | | func mustManager (i) = if (isManager(i)) |
---|
231 | 231 | | then true |
---|
232 | 232 | | else throw("permission denied") |
---|
233 | 233 | | |
---|
234 | 234 | | |
---|
235 | 235 | | func getUserGwxAmountAtHeight (userAddress,targetHeight) = { |
---|
236 | 236 | | let gwxAmount = invoke(boostingContract, "getUserGwxAmountAtHeightREADONLY", [userAddress, targetHeight], nil) |
---|
237 | 237 | | asInt(gwxAmount) |
---|
238 | 238 | | } |
---|
239 | 239 | | |
---|
240 | 240 | | |
---|
241 | 241 | | func getVoteResultAction (assetId,total,inFavor,period,verified) = { |
---|
242 | 242 | | let voteResultKey = keyVoteResultByPeriod(assetId, period) |
---|
243 | 243 | | let $t069157218 = match getString(voteResultKey) { |
---|
244 | 244 | | case s: String => |
---|
245 | 245 | | parseVoteResult(s) |
---|
246 | 246 | | case _: Unit => |
---|
247 | 247 | | match getString(keyVoteResultByPeriod(assetId, (period - 1))) { |
---|
248 | 248 | | case s: String => |
---|
249 | 249 | | $Tuple3(0, 0, parseVoteResult(s)._3) |
---|
250 | 250 | | case _: Unit => |
---|
251 | 251 | | $Tuple3(0, 0, false) |
---|
252 | 252 | | case _ => |
---|
253 | 253 | | throw("Match error") |
---|
254 | 254 | | } |
---|
255 | 255 | | case _ => |
---|
256 | 256 | | throw("Match error") |
---|
257 | 257 | | } |
---|
258 | 258 | | let oldTotalYes = $t069157218._1 |
---|
259 | 259 | | let oldTotalNo = $t069157218._2 |
---|
260 | 260 | | let oldVerified = $t069157218._3 |
---|
261 | 261 | | StringEntry(voteResultKey, formatVoteResult((oldTotalYes + (if (inFavor) |
---|
262 | 262 | | then total |
---|
263 | 263 | | else 0)), (oldTotalNo + (if (inFavor) |
---|
264 | 264 | | then 0 |
---|
265 | 265 | | else total)), if ((verified == unit)) |
---|
266 | 266 | | then oldVerified |
---|
267 | 267 | | else value(verified))) |
---|
268 | 268 | | } |
---|
269 | 269 | | |
---|
270 | 270 | | |
---|
271 | 271 | | func containsNode (listName,id) = { |
---|
272 | 272 | | let head = getString(this, keyListHead(listName)) |
---|
273 | 273 | | let prev = getString(this, keyListPrev(listName, id)) |
---|
274 | 274 | | let next = getString(this, keyListNext(listName, id)) |
---|
275 | 275 | | if (if ((id == head)) |
---|
276 | 276 | | then true |
---|
277 | 277 | | else (prev != unit)) |
---|
278 | 278 | | then true |
---|
279 | 279 | | else (next != unit) |
---|
280 | 280 | | } |
---|
281 | 281 | | |
---|
282 | 282 | | |
---|
283 | 283 | | func insertNode (listName,id) = { |
---|
284 | 284 | | let head = getString(this, keyListHead(listName)) |
---|
285 | 285 | | let listSize = valueOrElse(getInteger(this, keyListSize(listName)), 0) |
---|
286 | 286 | | let checkNode = if (!(containsNode(listName, id))) |
---|
287 | 287 | | then true |
---|
288 | 288 | | else throw("Node exists") |
---|
289 | 289 | | if ((checkNode == checkNode)) |
---|
290 | 290 | | then (([IntegerEntry(keyListSize(listName), (listSize + 1))] ++ (if (isDefined(head)) |
---|
291 | 291 | | then [StringEntry(keyListNext(listName, id), value(head)), StringEntry(keyListPrev(listName, value(head)), id)] |
---|
292 | 292 | | else nil)) ++ [StringEntry(keyListHead(listName), id)]) |
---|
293 | 293 | | else throw("Strict value is not equal to itself.") |
---|
294 | 294 | | } |
---|
295 | 295 | | |
---|
296 | 296 | | |
---|
297 | 297 | | func deleteNode (listName,id) = { |
---|
298 | 298 | | let head = getString(this, keyListHead(listName)) |
---|
299 | 299 | | let listSize = valueOrElse(getInteger(this, keyListSize(listName)), 0) |
---|
300 | 300 | | let prev = getString(this, keyListPrev(listName, id)) |
---|
301 | 301 | | let next = getString(this, keyListNext(listName, id)) |
---|
302 | 302 | | ([IntegerEntry(keyListSize(listName), (listSize - 1))] ++ (if (if (isDefined(prev)) |
---|
303 | 303 | | then isDefined(next) |
---|
304 | 304 | | else false) |
---|
305 | 305 | | then [StringEntry(keyListNext(listName, value(prev)), value(next)), StringEntry(keyListPrev(listName, value(next)), value(prev)), DeleteEntry(keyListPrev(listName, id)), DeleteEntry(keyListNext(listName, id))] |
---|
306 | 306 | | else if (isDefined(next)) |
---|
307 | 307 | | then [StringEntry(keyListHead(listName), value(next)), DeleteEntry(keyListNext(listName, id)), DeleteEntry(keyListPrev(listName, value(next)))] |
---|
308 | 308 | | else if (isDefined(prev)) |
---|
309 | 309 | | then [DeleteEntry(keyListPrev(listName, id)), DeleteEntry(keyListNext(listName, value(prev)))] |
---|
310 | 310 | | else if ((id == head)) |
---|
311 | 311 | | then [DeleteEntry(keyListHead(listName))] |
---|
312 | 312 | | else throw("Invalid node"))) |
---|
313 | 313 | | } |
---|
314 | 314 | | |
---|
315 | 315 | | |
---|
316 | 316 | | func processVote (assetId,userAddressOrUnit,latestProcessedAssetKey,latestProcessedUserKey,latestProcessedUserRemoveKey) = { |
---|
317 | 317 | | let updateLatestProcessedAssetAction = StringEntry(latestProcessedAssetKey, assetId) |
---|
318 | 318 | | let deleteLatestProcessedUserAction = DeleteEntry(latestProcessedUserKey) |
---|
319 | 319 | | if ((userAddressOrUnit == unit)) |
---|
320 | 320 | | then [updateLatestProcessedAssetAction, deleteLatestProcessedUserAction] |
---|
321 | 321 | | else { |
---|
322 | 322 | | let userAddress = value(userAddressOrUnit) |
---|
323 | 323 | | let updateLatestProcessedUserAction = StringEntry(latestProcessedUserKey, userAddress) |
---|
324 | 324 | | let userVoteKey = keyUserVoteByPeriod(userAddress, assetId, currentPeriod) |
---|
325 | 325 | | let userVoteOrUnit = getString(userVoteKey) |
---|
326 | 326 | | let voteActions = if ((userVoteOrUnit == unit)) |
---|
327 | 327 | | then { |
---|
328 | 328 | | let userGwxAmountAtEndHeight = getUserGwxAmountAtHeight(userAddress, endHeight) |
---|
329 | 329 | | if ((userGwxAmountAtEndHeight == 0)) |
---|
330 | 330 | | then [BooleanEntry(latestProcessedUserRemoveKey, true)] |
---|
331 | 331 | | else { |
---|
332 | 332 | | let previousPeriod = (currentPeriod - 1) |
---|
333 | 333 | | let assetWasEliminated = valueOrElse(getBoolean(keyAssetWasEliminated(assetId, previousPeriod)), false) |
---|
334 | 334 | | let userPreviousVoteOrUnit = if (assetWasEliminated) |
---|
335 | 335 | | then unit |
---|
336 | 336 | | else getString(keyUserVoteByPeriod(userAddress, assetId, previousPeriod)) |
---|
337 | 337 | | if ((userPreviousVoteOrUnit == unit)) |
---|
338 | 338 | | then nil |
---|
339 | 339 | | else { |
---|
340 | 340 | | let $t01132911402 = parseUserVote(value(userPreviousVoteOrUnit)) |
---|
341 | 341 | | let prevTotal = $t01132911402._1 |
---|
342 | 342 | | let inFavor = $t01132911402._2 |
---|
343 | 343 | | let total = min([prevTotal, userGwxAmountAtEndHeight]) |
---|
344 | 344 | | [StringEntry(userVoteKey, formatUserVote(total, inFavor)), getVoteResultAction(assetId, total, inFavor, currentPeriod, unit)] |
---|
345 | 345 | | } |
---|
346 | 346 | | } |
---|
347 | 347 | | } |
---|
348 | 348 | | else nil |
---|
349 | 349 | | ((voteActions :+ updateLatestProcessedAssetAction) :+ updateLatestProcessedUserAction) |
---|
350 | 350 | | } |
---|
351 | 351 | | } |
---|
352 | 352 | | |
---|
353 | 353 | | |
---|
354 | 354 | | func assetShouldBeEliminated (assetId,period) = !(valueOrElse(getBoolean(keyAssetVerifiedByPeriod(assetId, period)), true)) |
---|
355 | 355 | | |
---|
356 | 356 | | |
---|
357 | 357 | | func eliminationCheck (assetId) = if (if (assetShouldBeEliminated(assetId, (currentPeriod - 1))) |
---|
358 | 358 | | then assetShouldBeEliminated(assetId, (currentPeriod - 2)) |
---|
359 | 359 | | else false) |
---|
360 | 360 | | then assetShouldBeEliminated(assetId, (currentPeriod - 3)) |
---|
361 | 361 | | else false |
---|
362 | 362 | | |
---|
363 | 363 | | |
---|
364 | 364 | | @Callable(i) |
---|
365 | 365 | | func constructor (boostingContractPrm,emissionContractPrm,assetsStoreContractPrm,feeAmountPrm,wxAssetIdPrm,votingThresholdPrm,votingDurationPrm,voteBeforeEliminationPrm,startHeightPrm,maxDepthPrm) = { |
---|
366 | 366 | | let checks = [mustManager(i), if (isDefined(addressFromString(boostingContractPrm))) |
---|
367 | 367 | | then true |
---|
368 | 368 | | else throw("Invalid boosting contract address"), if (isDefined(addressFromString(emissionContractPrm))) |
---|
369 | 369 | | then true |
---|
370 | 370 | | else throw("Invalid emission contract address"), if (isDefined(addressFromString(assetsStoreContractPrm))) |
---|
371 | 371 | | then true |
---|
372 | 372 | | else throw("Invalid asset_store contract address"), if ((feeAmountPrm >= 0)) |
---|
373 | 373 | | then true |
---|
374 | 374 | | else throw("Invalid fee amount"), if (isDefined(assetInfo(fromBase58String(wxAssetIdPrm)))) |
---|
375 | 375 | | then true |
---|
376 | 376 | | else throw("Invalid WX asset ID"), if ((votingThresholdPrm >= 0)) |
---|
377 | 377 | | then true |
---|
378 | 378 | | else throw("Invalid voting threshold"), if ((votingDurationPrm > 0)) |
---|
379 | 379 | | then true |
---|
380 | 380 | | else throw("Invalid voting duration"), if (((startHeightPrm + votingDurationPrm) > height)) |
---|
381 | 381 | | then true |
---|
382 | 382 | | else throw("Invalid start height")] |
---|
383 | 383 | | if ((checks == checks)) |
---|
384 | 384 | | then $Tuple2([StringEntry(keyBoostingContract, boostingContractPrm), StringEntry(keyEmissionContract, emissionContractPrm), StringEntry(keyAssetsStoreContract, assetsStoreContractPrm), IntegerEntry(keyFeeAmount, feeAmountPrm), StringEntry(keyWxAssetId, wxAssetIdPrm), IntegerEntry(keyVotingThreshold, votingThresholdPrm), IntegerEntry(keyVotingDuration, votingDurationPrm), IntegerEntry(keyVoteBeforeElimination, voteBeforeEliminationPrm), IntegerEntry(keyStartHeight, startHeightPrm), IntegerEntry(keyCurrentPeriod, 0), IntegerEntry(keyMaxDepth, maxDepthPrm)], unit) |
---|
385 | 385 | | else throw("Strict value is not equal to itself.") |
---|
386 | 386 | | } |
---|
387 | 387 | | |
---|
388 | 388 | | |
---|
389 | 389 | | |
---|
390 | 390 | | @Callable(i) |
---|
391 | 391 | | func suggest (assetId,assetImage) = { |
---|
392 | 392 | | let info = valueOrErrorMessage(assetInfo(fromBase58String(assetId)), "Invalid asset ID") |
---|
393 | 393 | | if ((info == info)) |
---|
394 | 394 | | then { |
---|
395 | 395 | | let payment = value(i.payments[0]) |
---|
396 | 396 | | let isThis = (i.caller == this) |
---|
397 | 397 | | let checks = [if (if (isThis) |
---|
398 | 398 | | then true |
---|
399 | 399 | | else (value(payment.assetId) == wxAssetId)) |
---|
400 | 400 | | then true |
---|
401 | 401 | | else throw("Invalid fee asset"), if (if (isThis) |
---|
402 | 402 | | then true |
---|
403 | 403 | | else (payment.amount == feeAmount)) |
---|
404 | 404 | | then true |
---|
405 | 405 | | else throw("Invalid fee amount")] |
---|
406 | 406 | | if ((checks == checks)) |
---|
407 | 407 | | then { |
---|
408 | 408 | | let assetsStoreCreateOrUpdateInv = invoke(assetsStoreContract, "createOrUpdate", [assetId, assetImage, false], nil) |
---|
409 | 409 | | if ((assetsStoreCreateOrUpdateInv == assetsStoreCreateOrUpdateInv)) |
---|
410 | 410 | | then { |
---|
411 | 411 | | let burnFeeInv = if (isThis) |
---|
412 | 412 | | then unit |
---|
413 | 413 | | else invoke(emissionContract, "burn", nil, [AttachedPayment(payment.assetId, payment.amount)]) |
---|
414 | 414 | | if ((burnFeeInv == burnFeeInv)) |
---|
415 | 415 | | then { |
---|
416 | 416 | | let addAssetActions = insertNode(assetsListName, assetId) |
---|
417 | 417 | | let nextPeriod = (currentPeriod + 1) |
---|
418 | 418 | | let targetPeriod = if ((endHeight > height)) |
---|
419 | 419 | | then currentPeriod |
---|
420 | 420 | | else nextPeriod |
---|
421 | 421 | | $Tuple2((addAssetActions :+ getVoteResultAction(assetId, 0, true, targetPeriod, false)), unit) |
---|
422 | 422 | | } |
---|
423 | 423 | | else throw("Strict value is not equal to itself.") |
---|
424 | 424 | | } |
---|
425 | 425 | | else throw("Strict value is not equal to itself.") |
---|
426 | 426 | | } |
---|
427 | 427 | | else throw("Strict value is not equal to itself.") |
---|
428 | 428 | | } |
---|
429 | 429 | | else throw("Strict value is not equal to itself.") |
---|
430 | 430 | | } |
---|
431 | 431 | | |
---|
432 | 432 | | |
---|
433 | 433 | | |
---|
434 | 434 | | @Callable(i) |
---|
435 | 435 | | func vote (assetId,inFavor) = { |
---|
436 | 436 | | let checkAsset = if (containsNode(assetsListName, assetId)) |
---|
437 | 437 | | then true |
---|
438 | 438 | | else throw("Invalid asset") |
---|
439 | 439 | | if ((checkAsset == checkAsset)) |
---|
440 | 440 | | then { |
---|
441 | 441 | | let checkHeight = if ((endHeight > height)) |
---|
442 | 442 | | then true |
---|
443 | 443 | | else throw("Current voting is over but results are not finalized") |
---|
444 | 444 | | if ((checkHeight == checkHeight)) |
---|
445 | 445 | | then { |
---|
446 | 446 | | let userAddress = toString(i.caller) |
---|
447 | 447 | | let gwxAmountAtEnd = getUserGwxAmountAtHeight(userAddress, endHeight) |
---|
448 | 448 | | let checkGwxAmountAtEnd = if ((gwxAmountAtEnd > 0)) |
---|
449 | 449 | | then true |
---|
450 | 450 | | else throw("You'll not have gWX at the end of voting") |
---|
451 | 451 | | if ((checkGwxAmountAtEnd == checkGwxAmountAtEnd)) |
---|
452 | 452 | | then { |
---|
453 | 453 | | let votesListName = getVotesListName(assetId) |
---|
454 | 454 | | let userVoteKey = keyUserVoteByPeriod(userAddress, assetId, currentPeriod) |
---|
455 | 455 | | let userVoteOrUnit = getString(userVoteKey) |
---|
456 | 456 | | let cancelVoteInv = if ((userVoteOrUnit == unit)) |
---|
457 | 457 | | then unit |
---|
458 | 458 | | else invoke(this, "cancelVote", [assetId], nil) |
---|
459 | 459 | | if ((cancelVoteInv == cancelVoteInv)) |
---|
460 | 460 | | then { |
---|
461 | 461 | | let userVoteActions = [StringEntry(userVoteKey, formatUserVote(gwxAmountAtEnd, inFavor)), StringEntry(keyUserVoteHistory("vote", userAddress, assetId, toBase58String(i.transactionId), currentPeriod), formatUserVote(gwxAmountAtEnd, inFavor)), getVoteResultAction(assetId, gwxAmountAtEnd, inFavor, currentPeriod, unit)] |
---|
462 | 462 | | let votesListActions = if (containsNode(votesListName, userAddress)) |
---|
463 | 463 | | then nil |
---|
464 | 464 | | else insertNode(votesListName, userAddress) |
---|
465 | 465 | | $Tuple2((votesListActions ++ userVoteActions), unit) |
---|
466 | 466 | | } |
---|
467 | 467 | | else throw("Strict value is not equal to itself.") |
---|
468 | 468 | | } |
---|
469 | 469 | | else throw("Strict value is not equal to itself.") |
---|
470 | 470 | | } |
---|
471 | 471 | | else throw("Strict value is not equal to itself.") |
---|
472 | 472 | | } |
---|
473 | 473 | | else throw("Strict value is not equal to itself.") |
---|
474 | 474 | | } |
---|
475 | 475 | | |
---|
476 | 476 | | |
---|
477 | 477 | | |
---|
478 | 478 | | @Callable(i) |
---|
479 | 479 | | func cancelVote (assetId) = { |
---|
480 | 480 | | let userAddress = if ((i.caller == this)) |
---|
481 | 481 | | then toString(i.originCaller) |
---|
482 | 482 | | else toString(i.caller) |
---|
483 | 483 | | let votesListName = getVotesListName(assetId) |
---|
484 | 484 | | let userVoteKey = keyUserVoteByPeriod(userAddress, assetId, currentPeriod) |
---|
485 | 485 | | let userVoteOrUnit = getString(userVoteKey) |
---|
486 | 486 | | let $t01672816822 = parseUserVote(valueOrErrorMessage(userVoteOrUnit, "Nothing to cancel")) |
---|
487 | 487 | | let total = $t01672816822._1 |
---|
488 | 488 | | let inFavor = $t01672816822._2 |
---|
489 | 489 | | let votesListActions = deleteNode(votesListName, userAddress) |
---|
490 | 490 | | let userVoteActions = [DeleteEntry(userVoteKey), StringEntry(keyUserVoteHistory("cancelVote", userAddress, assetId, toBase58String(i.transactionId), currentPeriod), formatUserVote(0, true)), getVoteResultAction(assetId, -(total), inFavor, currentPeriod, unit)] |
---|
491 | 491 | | $Tuple2((votesListActions ++ userVoteActions), unit) |
---|
492 | 492 | | } |
---|
493 | 493 | | |
---|
494 | 494 | | |
---|
495 | 495 | | |
---|
496 | 496 | | @Callable(i) |
---|
497 | 497 | | func finalizeAssetINTERNAL (assetId,period) = { |
---|
498 | 498 | | let checkCaller = thisOnly(i) |
---|
499 | 499 | | if ((checkCaller == checkCaller)) |
---|
500 | 500 | | then { |
---|
501 | 501 | | let voteResultKey = keyVoteResultByPeriod(assetId, period) |
---|
502 | 502 | | let $t01745317626 = match getString(voteResultKey) { |
---|
503 | 503 | | case s: String => |
---|
504 | 504 | | let r = parseVoteResult(s) |
---|
505 | 505 | | $Tuple2(r._1, r._2) |
---|
506 | 506 | | case _: Unit => |
---|
507 | 507 | | $Tuple2(0, 0) |
---|
508 | 508 | | case _ => |
---|
509 | 509 | | throw("Match error") |
---|
510 | 510 | | } |
---|
511 | 511 | | let totalYes = $t01745317626._1 |
---|
512 | 512 | | let totalNo = $t01745317626._2 |
---|
513 | 513 | | let total = (totalYes + totalNo) |
---|
514 | 514 | | let verified = if ((total >= votingThreshold)) |
---|
515 | 515 | | then (totalYes > totalNo) |
---|
516 | 516 | | else false |
---|
517 | 517 | | let assetVerifiedActions = [BooleanEntry(keyAssetVerifiedByPeriod(assetId, period), verified), if (verified) |
---|
518 | 518 | | then BooleanEntry(keyAssetVerified(assetId), true) |
---|
519 | 519 | | else DeleteEntry(keyAssetVerified(assetId))] |
---|
520 | 520 | | let assetsStoreSetVerifiedInv = invoke(assetsStoreContract, "setVerified", [assetId, verified], nil) |
---|
521 | 521 | | if ((assetsStoreSetVerifiedInv == assetsStoreSetVerifiedInv)) |
---|
522 | 522 | | then { |
---|
523 | 523 | | let eliminate = if (verified) |
---|
524 | 524 | | then false |
---|
525 | 525 | | else eliminationCheck(assetId) |
---|
526 | 526 | | let assetWasEliminatedActions = if (eliminate) |
---|
527 | 527 | | then [BooleanEntry(keyAssetWasEliminated(assetId, currentPeriod), true)] |
---|
528 | 528 | | else nil |
---|
529 | 529 | | let voteResultActions = if (eliminate) |
---|
530 | 530 | | then nil |
---|
531 | 531 | | else [getVoteResultAction(assetId, 0, true, (currentPeriod + 1), verified)] |
---|
532 | 532 | | let votesListActions = if (eliminate) |
---|
533 | 533 | | then deleteNode(assetsListName, assetId) |
---|
534 | 534 | | else nil |
---|
535 | 535 | | let onEliminationInv = if (eliminate) |
---|
536 | 536 | | then invoke(assetsStoreContract, "onEliminate", [assetId], nil) |
---|
537 | 537 | | else unit |
---|
538 | 538 | | if ((onEliminationInv == onEliminationInv)) |
---|
539 | 539 | | then $Tuple2(((votesListActions ++ voteResultActions) ++ assetVerifiedActions), unit) |
---|
540 | 540 | | else throw("Strict value is not equal to itself.") |
---|
541 | 541 | | } |
---|
542 | 542 | | else throw("Strict value is not equal to itself.") |
---|
543 | 543 | | } |
---|
544 | 544 | | else throw("Strict value is not equal to itself.") |
---|
545 | 545 | | } |
---|
546 | 546 | | |
---|
547 | 547 | | |
---|
548 | 548 | | |
---|
549 | 549 | | @Callable(i) |
---|
550 | 550 | | func deleteUserNodeINTERNAL (assetId,userAddress,latestProcessedUserRemoveKey) = { |
---|
554 | 552 | | if ((checkCaller == checkCaller)) |
---|
555 | 553 | | then $Tuple2((deleteNode(getVotesListName(assetId), userAddress) :+ DeleteEntry(latestProcessedUserRemoveKey)), unit) |
---|
556 | 554 | | else throw("Strict value is not equal to itself.") |
---|
557 | 555 | | } |
---|
558 | 556 | | |
---|
559 | 557 | | |
---|
560 | 558 | | |
---|
561 | 559 | | @Callable(i) |
---|
562 | 560 | | func finalizeVotingHelper () = if ((endHeight > height)) |
---|
563 | 561 | | then $Tuple2(nil, false) |
---|
564 | 562 | | else { |
---|
565 | 563 | | let latestProcessedAssetOrUnit = getString(keyLatestProcessedAsset) |
---|
566 | 564 | | let latestProcessedUserOrUnit = getString(keyLatestProcessedUser) |
---|
567 | 565 | | let nextPeriodDelay = 0 |
---|
568 | 566 | | let finish = $Tuple2([IntegerEntry(keyStartHeight, (height + nextPeriodDelay)), IntegerEntry(keyCurrentPeriod, (currentPeriod + 1)), DeleteEntry(keyLatestProcessedAsset), DeleteEntry(keyLatestProcessedUser), DeleteEntry(keyLatestProcessedAssetTransfer), DeleteEntry(keyLatestProcessedUserTransfer)], true) |
---|
569 | 567 | | if ((latestProcessedAssetOrUnit == unit)) |
---|
570 | 568 | | then { |
---|
571 | 569 | | let assetsHeadOrUnit = getString(keyListHead(assetsListName)) |
---|
572 | 570 | | if ((assetsHeadOrUnit == unit)) |
---|
573 | 571 | | then finish |
---|
574 | 572 | | else { |
---|
575 | 573 | | let asset = value(assetsHeadOrUnit) |
---|
576 | 574 | | let userAddressOrUnit = getString(keyListHead(getVotesListName(asset))) |
---|
577 | 575 | | let processVoteActions = processVote(asset, userAddressOrUnit, keyLatestProcessedAsset, keyLatestProcessedUser, keyLatestProcessedUserRemove) |
---|
578 | 576 | | $Tuple2(processVoteActions, true) |
---|
579 | 577 | | } |
---|
580 | 578 | | } |
---|
581 | 579 | | else { |
---|
582 | 580 | | let latestProcessedAsset = value(latestProcessedAssetOrUnit) |
---|
583 | 581 | | if ((latestProcessedUserOrUnit == unit)) |
---|
584 | 582 | | then { |
---|
585 | 583 | | let assetOrUnit = getString(keyListNext(assetsListName, latestProcessedAsset)) |
---|
586 | 584 | | if ((assetOrUnit == assetOrUnit)) |
---|
587 | 585 | | then { |
---|
588 | 586 | | let finalizeAssetInv = invoke(this, "finalizeAssetINTERNAL", [latestProcessedAsset, currentPeriod], nil) |
---|
589 | 587 | | if ((finalizeAssetInv == finalizeAssetInv)) |
---|
590 | 588 | | then if ((assetOrUnit == unit)) |
---|
591 | 589 | | then finish |
---|
592 | 590 | | else { |
---|
593 | 591 | | let asset = value(assetOrUnit) |
---|
594 | 592 | | let userAddressOrUnit = getString(keyListHead(getVotesListName(asset))) |
---|
595 | 593 | | let processVoteActions = processVote(asset, userAddressOrUnit, keyLatestProcessedAsset, keyLatestProcessedUser, keyLatestProcessedUserRemove) |
---|
596 | 594 | | $Tuple2(processVoteActions, true) |
---|
597 | 595 | | } |
---|
598 | 596 | | else throw("Strict value is not equal to itself.") |
---|
599 | 597 | | } |
---|
600 | 598 | | else throw("Strict value is not equal to itself.") |
---|
601 | 599 | | } |
---|
602 | 600 | | else { |
---|
603 | 601 | | let latestProcessedUser = value(latestProcessedUserOrUnit) |
---|
604 | 602 | | let userAddressOrUnit = getString(keyListNext(getVotesListName(latestProcessedAsset), latestProcessedUser)) |
---|
605 | 603 | | if ((userAddressOrUnit == userAddressOrUnit)) |
---|
606 | 604 | | then { |
---|
607 | 605 | | let removeLatestUser = valueOrElse(getBoolean(keyLatestProcessedUserRemove), false) |
---|
608 | 606 | | let deleteUserInv = if (removeLatestUser) |
---|
609 | 607 | | then invoke(this, "deleteUserNodeINTERNAL", [latestProcessedAsset, latestProcessedUser, keyLatestProcessedUserRemove], nil) |
---|
610 | 608 | | else unit |
---|
611 | 609 | | if ((deleteUserInv == deleteUserInv)) |
---|
612 | 610 | | then { |
---|
613 | 611 | | let processVoteActions = processVote(latestProcessedAsset, userAddressOrUnit, keyLatestProcessedAsset, keyLatestProcessedUser, keyLatestProcessedUserRemove) |
---|
614 | 612 | | $Tuple2(processVoteActions, true) |
---|
615 | 613 | | } |
---|
616 | 614 | | else throw("Strict value is not equal to itself.") |
---|
617 | 615 | | } |
---|
618 | 616 | | else throw("Strict value is not equal to itself.") |
---|
619 | 617 | | } |
---|
620 | 618 | | } |
---|
621 | 619 | | } |
---|
622 | 620 | | |
---|
623 | 621 | | |
---|
624 | 622 | | |
---|
625 | 623 | | @Callable(i) |
---|
626 | 624 | | func finalizeVotingWrapper (counter) = { |
---|
627 | 625 | | let result = asBool(invoke(this, "finalizeVotingHelper", nil, nil)) |
---|
628 | 626 | | if ((result == result)) |
---|
629 | 627 | | then if (!(result)) |
---|
630 | 628 | | then if ((counter == 0)) |
---|
631 | 629 | | then throw("Current voting is not over yet") |
---|
632 | 630 | | else $Tuple2(nil, unit) |
---|
633 | 631 | | else if ((maxDepth > counter)) |
---|
634 | 632 | | then { |
---|
635 | 633 | | let inv = invoke(this, "finalizeVotingWrapper", [(counter + 1)], nil) |
---|
636 | 634 | | if ((inv == inv)) |
---|
637 | 635 | | then $Tuple2(nil, unit) |
---|
638 | 636 | | else throw("Strict value is not equal to itself.") |
---|
639 | 637 | | } |
---|
640 | 638 | | else $Tuple2(nil, unit) |
---|
641 | 639 | | else throw("Strict value is not equal to itself.") |
---|
642 | 640 | | } |
---|
643 | 641 | | |
---|
644 | 642 | | |
---|
645 | 643 | | |
---|
646 | 644 | | @Callable(i) |
---|
647 | 645 | | func finalizeVoting () = { |
---|
648 | 646 | | let inv = invoke(this, "finalizeVotingWrapper", [0], nil) |
---|
649 | 647 | | if ((inv == inv)) |
---|
650 | 648 | | then $Tuple2(nil, unit) |
---|
651 | 649 | | else throw("Strict value is not equal to itself.") |
---|
652 | 650 | | } |
---|
653 | 651 | | |
---|
654 | 652 | | |
---|
655 | 653 | | |
---|
656 | 654 | | @Callable(i) |
---|
657 | 655 | | func transferVotesHelper () = { |
---|
658 | 656 | | let votesTransferFinishedKey = keyVotesTransferFinishedByPeriod(currentPeriod) |
---|
659 | 657 | | let votesTransferFinished = valueOrElse(getBoolean(votesTransferFinishedKey), false) |
---|
660 | 658 | | if (if (if ((startHeight > height)) |
---|
661 | 659 | | then true |
---|
662 | 660 | | else (height >= endHeight)) |
---|
663 | 661 | | then true |
---|
664 | 662 | | else votesTransferFinished) |
---|
665 | 663 | | then $Tuple2(nil, false) |
---|
666 | 664 | | else { |
---|
667 | 665 | | let latestProcessedAssetOrUnit = getString(keyLatestProcessedAssetTransfer) |
---|
668 | 666 | | let latestProcessedUserOrUnit = getString(keyLatestProcessedUserTransfer) |
---|
669 | 667 | | let finish = $Tuple2([BooleanEntry(votesTransferFinishedKey, true), DeleteEntry(keyLatestProcessedAssetTransfer), DeleteEntry(keyLatestProcessedUserTransfer)], true) |
---|
670 | 668 | | if ((latestProcessedAssetOrUnit == unit)) |
---|
671 | 669 | | then { |
---|
672 | 670 | | let assetsHeadOrUnit = getString(keyListHead(assetsListName)) |
---|
673 | 671 | | if ((assetsHeadOrUnit == unit)) |
---|
674 | 672 | | then finish |
---|
675 | 673 | | else { |
---|
676 | 674 | | let asset = value(assetsHeadOrUnit) |
---|
677 | 675 | | let userAddressOrUnit = getString(keyListHead(getVotesListName(asset))) |
---|
678 | 676 | | let processVoteActions = processVote(asset, userAddressOrUnit, keyLatestProcessedAssetTransfer, keyLatestProcessedUserTransfer, keyLatestProcessedUserRemoveTransfer) |
---|
679 | 677 | | $Tuple2(processVoteActions, true) |
---|
680 | 678 | | } |
---|
681 | 679 | | } |
---|
682 | 680 | | else { |
---|
683 | 681 | | let latestProcessedAsset = value(latestProcessedAssetOrUnit) |
---|
684 | 682 | | if ((latestProcessedUserOrUnit == unit)) |
---|
685 | 683 | | then { |
---|
686 | 684 | | let assetOrUnit = getString(keyListNext(assetsListName, latestProcessedAsset)) |
---|
687 | 685 | | if ((assetOrUnit == unit)) |
---|
688 | 686 | | then finish |
---|
689 | 687 | | else { |
---|
690 | 688 | | let asset = value(assetOrUnit) |
---|
691 | 689 | | let userAddressOrUnit = getString(keyListHead(getVotesListName(asset))) |
---|
692 | 690 | | let processVoteActions = processVote(asset, userAddressOrUnit, keyLatestProcessedAssetTransfer, keyLatestProcessedUserTransfer, keyLatestProcessedUserRemoveTransfer) |
---|
693 | 691 | | $Tuple2(processVoteActions, true) |
---|
694 | 692 | | } |
---|
695 | 693 | | } |
---|
696 | 694 | | else { |
---|
697 | 695 | | let latestProcessedUser = value(latestProcessedUserOrUnit) |
---|
698 | 696 | | let userAddressOrUnit = getString(keyListNext(getVotesListName(latestProcessedAsset), latestProcessedUser)) |
---|
699 | 697 | | if ((userAddressOrUnit == userAddressOrUnit)) |
---|
700 | 698 | | then { |
---|
701 | 699 | | let removeLatestUser = valueOrElse(getBoolean(keyLatestProcessedUserRemoveTransfer), false) |
---|
702 | 700 | | let deleteUserInv = if (removeLatestUser) |
---|
703 | 701 | | then invoke(this, "deleteUserNodeINTERNAL", [latestProcessedAsset, latestProcessedUser, keyLatestProcessedUserRemoveTransfer], nil) |
---|
704 | 702 | | else unit |
---|
705 | 703 | | if ((deleteUserInv == deleteUserInv)) |
---|
706 | 704 | | then { |
---|
707 | 705 | | let processVoteActions = processVote(latestProcessedAsset, userAddressOrUnit, keyLatestProcessedAssetTransfer, keyLatestProcessedUserTransfer, keyLatestProcessedUserRemoveTransfer) |
---|
708 | 706 | | $Tuple2(processVoteActions, true) |
---|
709 | 707 | | } |
---|
710 | 708 | | else throw("Strict value is not equal to itself.") |
---|
711 | 709 | | } |
---|
712 | 710 | | else throw("Strict value is not equal to itself.") |
---|
713 | 711 | | } |
---|
714 | 712 | | } |
---|
715 | 713 | | } |
---|
716 | 714 | | } |
---|
717 | 715 | | |
---|
718 | 716 | | |
---|
719 | 717 | | |
---|
720 | 718 | | @Callable(i) |
---|
721 | 719 | | func transferVotesWrapper (counter) = { |
---|
722 | 720 | | let result = asBool(invoke(this, "transferVotesHelper", nil, nil)) |
---|
723 | 721 | | if ((result == result)) |
---|
724 | 722 | | then if (!(result)) |
---|
725 | 723 | | then if ((counter == 0)) |
---|
726 | 724 | | then throw("Voting is not started yet") |
---|
727 | 725 | | else $Tuple2(nil, unit) |
---|
728 | 726 | | else if ((maxDepth > counter)) |
---|
729 | 727 | | then { |
---|
730 | 728 | | let inv = invoke(this, "transferVotesWrapper", [(counter + 1)], nil) |
---|
731 | 729 | | if ((inv == inv)) |
---|
732 | 730 | | then $Tuple2(nil, unit) |
---|
733 | 731 | | else throw("Strict value is not equal to itself.") |
---|
734 | 732 | | } |
---|
735 | 733 | | else $Tuple2(nil, unit) |
---|
736 | 734 | | else throw("Strict value is not equal to itself.") |
---|
737 | 735 | | } |
---|
738 | 736 | | |
---|
739 | 737 | | |
---|
740 | 738 | | |
---|
741 | 739 | | @Callable(i) |
---|
742 | 740 | | func transferVotes () = { |
---|
743 | 741 | | let inv = invoke(this, "transferVotesWrapper", [0], nil) |
---|
744 | 742 | | if ((inv == inv)) |
---|
745 | 743 | | then $Tuple2(nil, unit) |
---|
746 | 744 | | else throw("Strict value is not equal to itself.") |
---|
747 | 745 | | } |
---|
748 | 746 | | |
---|
749 | 747 | | |
---|
750 | 748 | | |
---|
751 | 749 | | @Callable(i) |
---|
752 | 750 | | func setVotingThreshold (newThreshold) = { |
---|
753 | 751 | | let checkCaller = mustManager(i) |
---|
754 | 752 | | if ((checkCaller == checkCaller)) |
---|
755 | 753 | | then $Tuple2([IntegerEntry(keyVotingThreshold, newThreshold)], unit) |
---|
756 | 754 | | else throw("Strict value is not equal to itself.") |
---|
757 | 755 | | } |
---|
758 | 756 | | |
---|
759 | 757 | | |
---|
760 | 758 | | |
---|
761 | 759 | | @Callable(i) |
---|
762 | 760 | | func setFee (newFee) = { |
---|
763 | 761 | | let checkCaller = mustManager(i) |
---|
764 | 762 | | if ((checkCaller == checkCaller)) |
---|
765 | 763 | | then $Tuple2([IntegerEntry(keyFeeAmount, newFee)], unit) |
---|
766 | 764 | | else throw("Strict value is not equal to itself.") |
---|
767 | 765 | | } |
---|
768 | 766 | | |
---|
769 | 767 | | |
---|
770 | 768 | | |
---|
771 | 769 | | @Callable(i) |
---|
772 | 770 | | func gwxAvailableForVoteREADONLY (userAddress) = { |
---|
773 | 771 | | let gwxAmountAtEnd = getUserGwxAmountAtHeight(userAddress, endHeight) |
---|
774 | 772 | | $Tuple2(nil, gwxAmountAtEnd) |
---|
775 | 773 | | } |
---|
776 | 774 | | |
---|
777 | 775 | | |
---|
778 | 776 | | @Verifier(tx) |
---|
779 | 777 | | func verify () = { |
---|
780 | 778 | | let targetPublicKey = match managerPublicKeyOrUnit() { |
---|
781 | 779 | | case pk: ByteVector => |
---|
782 | 780 | | pk |
---|
783 | 781 | | case _: Unit => |
---|
784 | 782 | | tx.senderPublicKey |
---|
785 | 783 | | case _ => |
---|
786 | 784 | | throw("Match error") |
---|
787 | 785 | | } |
---|
788 | 786 | | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) |
---|
789 | 787 | | } |
---|
790 | 788 | | |
---|