187 | | - | else throw("fail to cast into List[Any]") |
---|
188 | | - | } |
---|
189 | | - | |
---|
190 | | - | |
---|
191 | | - | func aN (aK) = { |
---|
192 | | - | let aL = aK |
---|
193 | | - | if ($isInstanceOf(aL, "Int")) |
---|
194 | | - | then { |
---|
195 | | - | let aO = aL |
---|
196 | | - | aO |
---|
197 | | - | } |
---|
198 | | - | else throw("fail to cast into Int") |
---|
199 | | - | } |
---|
200 | | - | |
---|
201 | | - | |
---|
202 | | - | func aP (aQ,aR,aS,aT,aU,aV,aW) = makeString(["%b%d%d%d%b%d%b", toString(aQ), toString(aR), toString(aS), toString(aT), toString(aU), toString(aV), toString(aW)], b) |
---|
203 | | - | |
---|
204 | | - | |
---|
205 | | - | func aX (aY,aj,aZ,ba,bb,bc,bd,be,bf,bg,bh) = makeString(["%s%s%s%s%s%d%d%d%s%d%s", aY, aj, aZ, ba, bb, toString(bc), toString(bd), toString(be), bf, toString(bg), bh], b) |
---|
206 | | - | |
---|
207 | | - | |
---|
208 | | - | func bi (bj) = if ((size(bj) > 20)) |
---|
209 | | - | then throw(("Too many transactions: " + toString(size(bj)))) |
---|
210 | | - | else { |
---|
211 | | - | func bk (bl,bm) = if ((size(fromBase58String(bm)) != 32)) |
---|
212 | | - | then throw(("Wrong txId: " + bm)) |
---|
213 | | - | else if ((bl == "")) |
---|
214 | | - | then bm |
---|
215 | | - | else ((bl + c) + bm) |
---|
216 | | - | |
---|
217 | | - | let bn = bj |
---|
218 | | - | let bo = size(bn) |
---|
219 | | - | let bp = "" |
---|
220 | | - | func bq (br,bs) = if ((bs >= bo)) |
---|
221 | | - | then br |
---|
222 | | - | else bk(br, bn[bs]) |
---|
223 | | - | |
---|
224 | | - | func bt (br,bs) = if ((bs >= bo)) |
---|
225 | | - | then br |
---|
226 | | - | else throw("List size exceeds 20") |
---|
227 | | - | |
---|
228 | | - | bt(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bp, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) |
---|
229 | | - | } |
---|
230 | | - | |
---|
231 | | - | |
---|
232 | | - | let bu = 0 |
---|
233 | | - | |
---|
234 | | - | let bv = 1 |
---|
235 | | - | |
---|
236 | | - | func bw (bx) = { |
---|
237 | | - | let by = aJ(invoke(ah, "gnsbtInfoSYSREADONLY", [bx, 0, 0], nil)) |
---|
238 | | - | let bz = aJ(by[2]) |
---|
239 | | - | let bA = aN(bz[2]) |
---|
240 | | - | let bB = aN(bz[3]) |
---|
241 | | - | let bC = aN(by[9]) |
---|
242 | | - | let bD = aN(by[6]) |
---|
243 | | - | [(bB + bD), (bA + bC)] |
---|
244 | | - | } |
---|
245 | | - | |
---|
246 | | - | |
---|
247 | | - | func bE (bF) = if ((value(indexOf(bF, e)) != 0)) |
---|
248 | | - | then throw("Invalid url") |
---|
249 | | - | else if ((size(bF) > g)) |
---|
250 | | - | then throw("Url too long!") |
---|
251 | | - | else { |
---|
252 | | - | let az = valueOrErrorMessage(parseInt(drop(bF, (value(lastIndexOf(bF, "/")) + 1))), "Wrong topicId") |
---|
253 | | - | let bG = getInteger(ay(az)) |
---|
254 | | - | if (isDefined(bG)) |
---|
255 | | - | then throw(("Voting with such forum link is already registered by id=" + toString(value(bG)))) |
---|
256 | | - | else az |
---|
257 | | - | } |
---|
258 | | - | |
---|
259 | | - | |
---|
260 | | - | func bH (bI,aY,aj,aZ,ba,bb,bd,be,bJ,bj,bK) = if ((bI.assetId != unit)) |
---|
261 | | - | then throw("Allowed WAVES payment only!") |
---|
262 | | - | else { |
---|
263 | | - | let bL = J(ak(), j) |
---|
264 | | - | if ((bL > bI.amount)) |
---|
265 | | - | then throw(("Payment attached should be at least " + toString(bL))) |
---|
266 | | - | else { |
---|
267 | | - | let az = bE(ba) |
---|
268 | | - | if ((bb == "")) |
---|
269 | | - | then throw("Title is empty") |
---|
270 | | - | else if ((size(bb) > f)) |
---|
271 | | - | then throw("Too long title") |
---|
272 | | - | else { |
---|
273 | | - | let bc = lastBlock.timestamp |
---|
274 | | - | if ((bc > bd)) |
---|
275 | | - | then throw(((("votingStartTime=" + toString(bd)) + " < proposalTime=") + toString(bc))) |
---|
276 | | - | else if ((bd > be)) |
---|
277 | | - | then throw(((("votingEndTime=" + toString(be)) + " < votingStartTime=") + toString(bd))) |
---|
278 | | - | else if (((be - bd) > h)) |
---|
279 | | - | then throw(((("Voting period exceeds max: " + toString((be - bd))) + " > ") + toString(h))) |
---|
280 | | - | else { |
---|
281 | | - | let bf = if ((aj == "IDEA")) |
---|
282 | | - | then "" |
---|
283 | | - | else bi(bj) |
---|
284 | | - | if ((1 >= size(bK))) |
---|
285 | | - | then throw("Too few choices to vote") |
---|
286 | | - | else { |
---|
287 | | - | let bM = bw(aZ) |
---|
288 | | - | let bN = bM[bu] |
---|
289 | | - | let bO = bM[bv] |
---|
290 | | - | let bP = J(al(), k) |
---|
291 | | - | if ((bP > bO)) |
---|
292 | | - | then throw((("You need at least " + toString(bP)) + " gNsbt to create voting")) |
---|
293 | | - | else { |
---|
294 | | - | let bQ = invoke(ag, "acceptWaves", nil, [bI]) |
---|
295 | | - | if ((bQ == bQ)) |
---|
296 | | - | then { |
---|
297 | | - | let bR = J(ai(aj), d) |
---|
298 | | - | let bg = fraction(bR, bN, i) |
---|
299 | | - | let aq = (J(am(), 0) + 1) |
---|
300 | | - | let bS = (J(aF(aZ), 0) + 1) |
---|
301 | | - | let bT = (J(aE(), 0) + (if ((bS == 1)) |
---|
302 | | - | then 1 |
---|
303 | | - | else 0)) |
---|
304 | | - | let bU = makeString(bK, c) |
---|
305 | | - | $Tuple2([IntegerEntry(am(), aq), IntegerEntry(ay(az), aq), StringEntry(ap(aq), aP(false, 0, 0, 0, false, 0, false)), StringEntry(ar(aq), aX(aY, aj, aZ, toBase58String(toBytes(ba)), toBase58String(toBytes(bb)), bc, bd, be, bf, bg, bU)), IntegerEntry(aF(aZ), bS), IntegerEntry(aE(), bT)], aY) |
---|
306 | | - | } |
---|
307 | | - | else throw("Strict value is not equal to itself.") |
---|
308 | | - | } |
---|
309 | | - | } |
---|
310 | | - | } |
---|
311 | | - | } |
---|
312 | | - | } |
---|
313 | | - | } |
---|
314 | | - | |
---|
315 | | - | |
---|
316 | | - | func bV (aq,bK,bW,bX,bY,bZ,ca) = { |
---|
317 | | - | func cb (bl,cc) = { |
---|
318 | | - | let ae = value(indexOf(bK, cc)) |
---|
319 | | - | let cd = if (bW) |
---|
320 | | - | then if ((ae == bZ)) |
---|
321 | | - | then ca |
---|
322 | | - | else J(as(aq, ae), 0) |
---|
323 | | - | else if ((ae == value(bX))) |
---|
324 | | - | then bY |
---|
325 | | - | else if ((ae == bZ)) |
---|
326 | | - | then ca |
---|
327 | | - | else J(as(aq, ae), 0) |
---|
328 | | - | if ((bl._2 > cd)) |
---|
329 | | - | then bl |
---|
330 | | - | else $Tuple2(ae, cd) |
---|
331 | | - | } |
---|
332 | | - | |
---|
333 | | - | let bn = bK |
---|
334 | | - | let bo = size(bn) |
---|
335 | | - | let bp = $Tuple2(0, 0) |
---|
336 | | - | func bq (br,bs) = if ((bs >= bo)) |
---|
337 | | - | then br |
---|
338 | | - | else cb(br, bn[bs]) |
---|
339 | | - | |
---|
340 | | - | func bt (br,bs) = if ((bs >= bo)) |
---|
341 | | - | then br |
---|
342 | | - | else throw("List size exceeds 10") |
---|
343 | | - | |
---|
344 | | - | bt(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bp, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10) |
---|
345 | | - | } |
---|
346 | | - | |
---|
347 | | - | |
---|
348 | | - | func ce (cf,cg,ch,ci) = makeString(["%b%d%d%d%b%d%b", toString(cg), toString(ch._1), toString(ch._2), toString(ci), cf[D], cf[E], cf[F]], b) |
---|
349 | | - | |
---|
350 | | - | |
---|
351 | | - | func cj (cf) = makeString(["%b%d%d%d%b%d%b", cf[z], cf[A], cf[B], cf[C], "true", cf[E], cf[F]], b) |
---|
352 | | - | |
---|
353 | | - | |
---|
354 | | - | func ck (cl,bb,bF,aq) = { |
---|
355 | | - | let bN = bw("")[bu] |
---|
356 | | - | let cm = 500000 |
---|
357 | | - | StringEntry(aH(lastBlock.timestamp), makeString(["%d%d%d%s%s%d", toString(cl), toString(bN), toString(cm), bb, bF, toString(aq)], b)) |
---|
358 | | - | } |
---|
359 | | - | |
---|
360 | | - | |
---|
361 | | - | @Callable(aO) |
---|
362 | | - | func constructorV1 (cn,co,cp,cq,cr) = if ((aO.caller != this)) |
---|
363 | | - | then throw("Permission denied") |
---|
364 | | - | else [StringEntry(Y(), cn), IntegerEntry(al(), co), IntegerEntry(ak(), cp), IntegerEntry(ai("IDEA"), cq), IntegerEntry(ai("UPDATE"), cr)] |
---|
365 | | - | |
---|
366 | | - | |
---|
367 | | - | |
---|
368 | | - | @Callable(aO) |
---|
369 | | - | func castVote (aq,cs) = { |
---|
370 | | - | let ct = toString(aO.caller) |
---|
371 | | - | let cu = split(G(this, ap(aq)), b) |
---|
372 | | - | if ((cu[F] == "true")) |
---|
373 | | - | then throw("Voting is canceled by team") |
---|
374 | | - | else { |
---|
375 | | - | let cv = split(G(this, ar(aq)), b) |
---|
376 | | - | let cw = parseIntValue(cv[u]) |
---|
377 | | - | let cx = parseIntValue(cv[v]) |
---|
378 | | - | let cy = lastBlock.timestamp |
---|
379 | | - | if ((cw > cy)) |
---|
380 | | - | then throw("Voting not started yet") |
---|
381 | | - | else if ((cy >= cx)) |
---|
382 | | - | then throw("Voting already finished") |
---|
383 | | - | else { |
---|
384 | | - | let cz = split(cv[y], c) |
---|
385 | | - | let cA = size(cz) |
---|
386 | | - | if ((1 >= cA)) |
---|
387 | | - | then throw("Too few choices to vote") |
---|
388 | | - | else if ((cs >= cA)) |
---|
389 | | - | then throw(("Unknown choice! Must be 0.." + toString((cA - 1)))) |
---|
390 | | - | else { |
---|
391 | | - | let bM = bw(ct) |
---|
392 | | - | let cB = bM[bv] |
---|
393 | | - | if ((0 >= cB)) |
---|
394 | | - | then throw("no gnsbt to vote") |
---|
395 | | - | else { |
---|
396 | | - | let bN = bM[bu] |
---|
397 | | - | let bX = getInteger(aw(aq, ct)) |
---|
398 | | - | let cC = if (!(isDefined(bX))) |
---|
399 | | - | then 0 |
---|
400 | | - | else J(au(aq, ct), 0) |
---|
401 | | - | let cD = if (isDefined(bX)) |
---|
402 | | - | then J(as(aq, value(bX)), 0) |
---|
403 | | - | else 0 |
---|
404 | | - | let cE = J(as(aq, cs), 0) |
---|
405 | | - | let cF = parseIntValue(cu[C]) |
---|
406 | | - | let cG = if (!(isDefined(bX))) |
---|
407 | | - | then 0 |
---|
408 | | - | else ((cD - cC) + (if ((value(bX) == cs)) |
---|
409 | | - | then cB |
---|
410 | | - | else 0)) |
---|
411 | | - | let ca = if (if (isDefined(bX)) |
---|
412 | | - | then (value(bX) == cs) |
---|
413 | | - | else false) |
---|
414 | | - | then cG |
---|
415 | | - | else (cE + cB) |
---|
416 | | - | let cH = ((cF - cC) + cB) |
---|
417 | | - | let cI = (cH >= parseIntValue(cv[x])) |
---|
418 | | - | let cJ = J(aB(aq), 0) |
---|
419 | | - | let cK = J(aC(), 0) |
---|
420 | | - | let cL = ((getIntegerValue(am()) - valueOrElse(getInteger(an()), n)) + 1) |
---|
421 | | - | let cM = if ((cC == 0)) |
---|
422 | | - | then 1 |
---|
423 | | - | else 0 |
---|
424 | | - | let cN = (cK + fraction(cM, i, cL)) |
---|
425 | | - | let cO = J(aD(), 0) |
---|
426 | | - | let cP = (cO + ((cB - cC) / cL)) |
---|
427 | | - | let bW = if (!(isDefined(bX))) |
---|
428 | | - | then true |
---|
429 | | - | else (value(bX) == cs) |
---|
430 | | - | let bY = if (bW) |
---|
431 | | - | then nil |
---|
432 | | - | else [IntegerEntry(as(aq, value(bX)), cG)] |
---|
433 | | - | let cQ = bV(aq, cz, bW, bX, cG, cs, ca) |
---|
434 | | - | let cR = max([cx, J(aA(ct), 0)]) |
---|
435 | | - | $Tuple2(([IntegerEntry(aw(aq, ct), cs), IntegerEntry(au(aq, ct), cB), IntegerEntry(as(aq, cs), ca), IntegerEntry(aB(aq), (cJ + cM)), IntegerEntry(aA(ct), cR), IntegerEntry(aC(), cN), IntegerEntry(aD(), cP), StringEntry(ap(aq), ce(cu, cI, cQ, cH))] ++ bY), unit) |
---|
436 | | - | } |
---|
437 | | - | } |
---|
438 | | - | } |
---|
439 | | - | } |
---|
440 | | - | } |
---|
441 | | - | |
---|
442 | | - | |
---|
443 | | - | |
---|
444 | | - | @Callable(aO) |
---|
445 | | - | func initiateIdeaVoting (ba,bb,bd,be,bK) = if ((size(aO.payments) != 1)) |
---|
446 | | - | then throw("Exactly one payment required") |
---|
447 | | - | else if ((size(bK) != 2)) |
---|
448 | | - | then throw("Exactly 2 option ['NO', 'YES'] are expected") |
---|
449 | | - | else if ((bK[0] != "NO")) |
---|
450 | | - | then throw("Option NO should be the first") |
---|
451 | | - | else if ((bK[1] != "YES")) |
---|
452 | | - | then throw("Option YES should be the second") |
---|
453 | | - | else bH(value(aO.payments[0]), toBase58String(aO.transactionId), "IDEA", toString(aO.caller), ba, bb, bd, be, "PENDING", nil, bK) |
---|
454 | | - | |
---|
455 | | - | |
---|
456 | | - | |
---|
457 | | - | @Callable(aO) |
---|
458 | | - | func initiateUpdateVoting (ba,bb,bd,be,bj) = if ((size(aO.payments) != 1)) |
---|
459 | | - | then throw("Exactly one payment required") |
---|
460 | | - | else if ((1 > size(bj))) |
---|
461 | | - | then throw("Transactions list is empty") |
---|
462 | | - | else bH(value(aO.payments[0]), toBase58String(aO.transactionId), "UPDATE", toString(aO.caller), ba, bb, bd, be, "PENDING", bj, ["NO", "YES"]) |
---|
463 | | - | |
---|
464 | | - | |
---|
465 | | - | |
---|
466 | | - | @Callable(aO) |
---|
467 | | - | func cancelVoting (aq) = if ((aO.caller != this)) |
---|
468 | | - | then throw("not authorized") |
---|
469 | | - | else { |
---|
470 | | - | let cS = G(this, ap(aq)) |
---|
471 | | - | let cT = ((take(cS, value(lastIndexOf(cS, b))) + b) + "true") |
---|
472 | | - | $Tuple2([StringEntry(ap(aq), cT)], unit) |
---|
473 | | - | } |
---|
474 | | - | |
---|
475 | | - | |
---|
476 | | - | |
---|
477 | | - | @Callable(aO) |
---|
478 | | - | func applyUpdate (aq) = { |
---|
479 | | - | let cv = split(G(this, ar(aq)), b) |
---|
480 | | - | let cx = parseIntValue(cv[v]) |
---|
481 | | - | let cy = lastBlock.timestamp |
---|
482 | | - | if ((cx > cy)) |
---|
483 | | - | then throw("Voting is not finished yet") |
---|
484 | | - | else if (("UPDATE" != cv[p])) |
---|
485 | | - | then throw("Only UPDATE type can be applied") |
---|
486 | | - | else { |
---|
487 | | - | let cu = split(G(this, ap(aq)), b) |
---|
488 | | - | if ((cu[F] == "true")) |
---|
489 | | - | then throw("Voting is canceled") |
---|
490 | | - | else if ((cu[z] != "true")) |
---|
491 | | - | then throw("Voting status invalid") |
---|
492 | | - | else if ((cu[A] != "1")) |
---|
493 | | - | then throw("Winner is 'NO' - nothing to apply") |
---|
494 | | - | else if ((cu[D] == "true")) |
---|
495 | | - | then throw("Scripts are already applied") |
---|
496 | | - | else { |
---|
497 | | - | let cU = parseIntValue(cu[E]) |
---|
498 | | - | if (((cy - l) > cU)) |
---|
499 | | - | then throw((("Scripts timestamp=" + toString(cU)) + " is too far in the past, max 2 hrs allowed")) |
---|
500 | | - | else if ((cU > (cy + m))) |
---|
501 | | - | then throw((("Scripts timestamp=" + toString(cU)) + " is too far in the future, max 1.5 hrs allowed")) |
---|
502 | | - | else { |
---|
503 | | - | let cV = J(ax(), -1) |
---|
504 | | - | if ((cV != -1)) |
---|
505 | | - | then throw((("proposalId=" + toString(cV)) + " is already being applied. Finish it first!")) |
---|
506 | | - | else { |
---|
507 | | - | let cW = invoke(af, "callEmergencyShutdown", ["Applying Governance UPDATE"], nil) |
---|
508 | | - | if ((cW == cW)) |
---|
509 | | - | then $Tuple2([IntegerEntry(ax(), aq)], unit) |
---|
510 | | - | else throw("Strict value is not equal to itself.") |
---|
511 | | - | } |
---|
512 | | - | } |
---|
513 | | - | } |
---|
514 | | - | } |
---|
515 | | - | } |
---|
516 | | - | |
---|
517 | | - | |
---|
518 | | - | |
---|
519 | | - | @Callable(aO) |
---|
520 | | - | func finishApply () = { |
---|
521 | | - | let aq = valueOrErrorMessage(getInteger(ax()), "No apply in progress, nothing to finish") |
---|
522 | | - | let cv = split(G(this, ar(aq)), b) |
---|
523 | | - | let bj = split(cv[w], c) |
---|
524 | | - | let cu = split(G(this, ap(aq)), b) |
---|
525 | | - | if ((cu[D] == "true")) |
---|
526 | | - | then throw("Scripts are already applied") |
---|
527 | | - | else { |
---|
528 | | - | func cX (bl,bm) = if (!(isDefined(transactionHeightById(fromBase58String(bm))))) |
---|
529 | | - | then throw(("NOT applied txId: " + bm)) |
---|
530 | | - | else unit |
---|
531 | | - | |
---|
532 | | - | let cY = { |
---|
533 | | - | let bn = bj |
---|
534 | | - | let bo = size(bn) |
---|
535 | | - | let bp = unit |
---|
536 | | - | func bq (br,bs) = if ((bs >= bo)) |
---|
537 | | - | then br |
---|
538 | | - | else cX(br, bn[bs]) |
---|
539 | | - | |
---|
540 | | - | func bt (br,bs) = if ((bs >= bo)) |
---|
541 | | - | then br |
---|
542 | | - | else throw("List size exceeds 20") |
---|
543 | | - | |
---|
544 | | - | bt(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bq(bp, 0), 1), 2), 3), 4), 5), 6), 7), 8), 9), 10), 11), 12), 13), 14), 15), 16), 17), 18), 19), 20) |
---|
545 | | - | } |
---|
546 | | - | let cZ = (J(ao(), 0) + 1) |
---|
547 | | - | $Tuple2([DeleteEntry(ax()), IntegerEntry(ao(), cZ), StringEntry(ap(aq), cj(cu)), ck(cZ, cv[s], cv[r], aq)], cY) |
---|
548 | | - | } |
---|
| 18 | + | else throw("Strict value is not equal to itself.") |
---|