59 | | - | func ExtractReservedAmt () = match getInteger(this, RESERVATIONKEY) { |
---|
60 | | - | case a: Int => |
---|
61 | | - | a |
---|
62 | | - | case _ => |
---|
63 | | - | 0 |
---|
64 | | - | } |
---|
65 | | - | |
---|
66 | | - | |
---|
67 | | - | func ValidateAndIncreaseReservedAmt (winAmt) = { |
---|
68 | | - | let newReservedAmount = (ExtractReservedAmt() + winAmt) |
---|
69 | | - | let balance = assetBalance(this, WBET) |
---|
70 | | - | if ((newReservedAmount > balance)) |
---|
71 | | - | then throw("Insufficient funds on Wavesbet Dice account. Transaction was rejected for your safety.") |
---|
72 | | - | else newReservedAmount |
---|
73 | | - | } |
---|
74 | | - | |
---|
75 | | - | |
---|
76 | | - | func FormatGameDataParam (p) = { |
---|
77 | | - | let s = size(p) |
---|
78 | | - | if ((s == 0)) |
---|
79 | | - | then throw("Parameter size must be greater then 0") |
---|
80 | | - | else if ((s > 99)) |
---|
81 | | - | then throw("Parameter size must be less then 100") |
---|
82 | | - | else if ((10 > s)) |
---|
83 | | - | then (("0" + toString(s)) + p) |
---|
84 | | - | else (toString(s) + p) |
---|
85 | | - | } |
---|
86 | | - | |
---|
87 | | - | |
---|
88 | | - | func FormatGameDataStr (gameState,prediction,typeRoll,playerPubKey58,winAmt,randOrEmpty) = { |
---|
89 | | - | let fullStateStr = ((((((((FormatGameDataParam(gameState) + "_") + FormatGameDataParam(toString(prediction))) + "_") + FormatGameDataParam(typeRoll)) + "_") + FormatGameDataParam(playerPubKey58)) + "_") + FormatGameDataParam(toString(winAmt))) |
---|
90 | | - | if ((randOrEmpty == "")) |
---|
91 | | - | then fullStateStr |
---|
92 | | - | else ((fullStateStr + "_") + FormatGameDataParam(randOrEmpty)) |
---|
93 | | - | } |
---|
94 | | - | |
---|
95 | | - | |
---|
96 | | - | func RemoveUnderscoreIfPresent (remaining) = if ((size(remaining) > 0)) |
---|
97 | | - | then drop(remaining, 1) |
---|
98 | | - | else remaining |
---|
99 | | - | |
---|
100 | | - | |
---|
101 | | - | func ParseNextAttribute (remaining) = { |
---|
102 | | - | let s = size(remaining) |
---|
103 | | - | if ((s > 0)) |
---|
104 | | - | then { |
---|
105 | | - | let nn = parseIntValue(take(remaining, 2)) |
---|
106 | | - | let v = take(drop(remaining, 2), nn) |
---|
107 | | - | let tmpRemaining = drop(remaining, (nn + 2)) |
---|
108 | | - | let remainingState = RemoveUnderscoreIfPresent(tmpRemaining) |
---|
109 | | - | [v, remainingState] |
---|
110 | | - | } |
---|
111 | | - | else throw("Empty string was passed into parseNextAttribute func") |
---|
112 | | - | } |
---|
113 | | - | |
---|
114 | | - | |
---|
115 | | - | func ParseGameRawDataStr (rawStateStr) = { |
---|
116 | | - | let gameState = ParseNextAttribute(rawStateStr) |
---|
117 | | - | let prediction = ParseNextAttribute(gameState[1]) |
---|
118 | | - | let rollType = ParseNextAttribute(prediction[1]) |
---|
119 | | - | let playerPubKey58 = ParseNextAttribute(rollType[1]) |
---|
120 | | - | let winAmt = ParseNextAttribute(playerPubKey58[1]) |
---|
121 | | - | [gameState[0], prediction[0], rollType[0], playerPubKey58[0], winAmt[0]] |
---|
122 | | - | } |
---|
123 | | - | |
---|
124 | | - | |
---|
125 | | - | func ExtractGameDataList (gameId) = { |
---|
126 | | - | let rawDataStr = match getString(this, gameId) { |
---|
127 | | - | case str: String => |
---|
128 | | - | str |
---|
129 | | - | case _ => |
---|
130 | | - | throw(("Couldn't find game by " + gameId)) |
---|
131 | | - | } |
---|
132 | | - | ParseGameRawDataStr(rawDataStr) |
---|
133 | | - | } |
---|
134 | | - | |
---|
135 | | - | |
---|
136 | | - | func DecreaseReservedAmt (gameId,winAmt) = { |
---|
137 | | - | let newReservedAmount = (ExtractReservedAmt() - winAmt) |
---|
138 | | - | if ((0 > newReservedAmount)) |
---|
139 | | - | then throw("Invalid Dice Roller account state - reserved amount is less than 0") |
---|
140 | | - | else DataEntry(RESERVATIONKEY, newReservedAmount) |
---|
141 | | - | } |
---|
142 | | - | |
---|
143 | | - | |
---|
144 | | - | func GenerateRandInt (gameId,rsaSign) = { |
---|
145 | | - | let rsaSigValid = rsaVerify(SHA256, toBytes(gameId), rsaSign, RSAPUBLIC) |
---|
146 | | - | if (rsaSigValid) |
---|
147 | | - | then { |
---|
148 | | - | let rand = (toInt(sha256(rsaSign)) % 100) |
---|
149 | | - | if ((0 > rand)) |
---|
150 | | - | then ((-1 * rand) + 1) |
---|
151 | | - | else (rand + 1) |
---|
152 | | - | } |
---|
153 | | - | else throw("Invalid RSA signature") |
---|
154 | | - | } |
---|
155 | | - | |
---|
156 | | - | |
---|
157 | | - | func RandToStr (r) = if (if ((r >= 1)) |
---|
158 | | - | then (100 >= r) |
---|
159 | | - | else false) |
---|
160 | | - | then toString(r) |
---|
161 | | - | else throw(("Unsupported r parameter passed: expected=[1,...,100] actual=" + toString(r))) |
---|
162 | | - | |
---|
163 | | - | |
---|
164 | | - | func WinScriptSet (gameId,playerAddress,winAmt,newGameDataStr,decreasedReserves) = { |
---|
165 | | - | let wSetCommonData = [decreasedReserves] |
---|
166 | | - | let tSetCommonData = [ScriptTransfer(playerAddress, winAmt, WBET)] |
---|
167 | | - | let gameData = DataEntry(gameId, newGameDataStr) |
---|
168 | | - | ScriptResult(WriteSet(gameData :: wSetCommonData), TransferSet(tSetCommonData)) |
---|
169 | | - | } |
---|
170 | | - | |
---|
171 | | - | |
---|
172 | | - | func Multiplier (prediction,rollType) = if ((rollType == ROLLUNDER)) |
---|
173 | | - | then if ((prediction == 1)) |
---|
174 | | - | then 9850000 |
---|
175 | | - | else if ((prediction == 2)) |
---|
176 | | - | then 4925000 |
---|
177 | | - | else if ((prediction == 3)) |
---|
178 | | - | then 3283330 |
---|
179 | | - | else if ((prediction == 4)) |
---|
180 | | - | then 2462500 |
---|
181 | | - | else if ((prediction == 5)) |
---|
182 | | - | then 1970000 |
---|
183 | | - | else if ((prediction == 6)) |
---|
184 | | - | then 1641660 |
---|
185 | | - | else if ((prediction == 7)) |
---|
186 | | - | then 1407140 |
---|
187 | | - | else if ((prediction == 8)) |
---|
188 | | - | then 1231250 |
---|
189 | | - | else if ((prediction == 9)) |
---|
190 | | - | then 1094440 |
---|
191 | | - | else if ((prediction == 10)) |
---|
192 | | - | then 985000 |
---|
193 | | - | else if ((prediction == 11)) |
---|
194 | | - | then 895450 |
---|
195 | | - | else if ((prediction == 12)) |
---|
196 | | - | then 820830 |
---|
197 | | - | else if ((prediction == 13)) |
---|
198 | | - | then 757690 |
---|
199 | | - | else if ((prediction == 14)) |
---|
200 | | - | then 703570 |
---|
201 | | - | else if ((prediction == 15)) |
---|
202 | | - | then 656660 |
---|
203 | | - | else if ((prediction == 16)) |
---|
204 | | - | then 615620 |
---|
205 | | - | else if ((prediction == 17)) |
---|
206 | | - | then 579410 |
---|
207 | | - | else if ((prediction == 18)) |
---|
208 | | - | then 547220 |
---|
209 | | - | else if ((prediction == 19)) |
---|
210 | | - | then 518420 |
---|
211 | | - | else if ((prediction == 20)) |
---|
212 | | - | then 492500 |
---|
213 | | - | else if ((prediction == 21)) |
---|
214 | | - | then 469040 |
---|
215 | | - | else if ((prediction == 22)) |
---|
216 | | - | then 447720 |
---|
217 | | - | else if ((prediction == 23)) |
---|
218 | | - | then 428260 |
---|
219 | | - | else if ((prediction == 24)) |
---|
220 | | - | then 410410 |
---|
221 | | - | else if ((prediction == 25)) |
---|
222 | | - | then 394000 |
---|
223 | | - | else if ((prediction == 26)) |
---|
224 | | - | then 378840 |
---|
225 | | - | else if ((prediction == 27)) |
---|
226 | | - | then 364810 |
---|
227 | | - | else if ((prediction == 28)) |
---|
228 | | - | then 351780 |
---|
229 | | - | else if ((prediction == 29)) |
---|
230 | | - | then 339650 |
---|
231 | | - | else if ((prediction == 30)) |
---|
232 | | - | then 328330 |
---|
233 | | - | else if ((prediction == 31)) |
---|
234 | | - | then 317740 |
---|
235 | | - | else if ((prediction == 32)) |
---|
236 | | - | then 307810 |
---|
237 | | - | else if ((prediction == 33)) |
---|
238 | | - | then 298480 |
---|
239 | | - | else if ((prediction == 34)) |
---|
240 | | - | then 289700 |
---|
241 | | - | else if ((prediction == 35)) |
---|
242 | | - | then 281420 |
---|
243 | | - | else if ((prediction == 36)) |
---|
244 | | - | then 273610 |
---|
245 | | - | else if ((prediction == 37)) |
---|
246 | | - | then 259210 |
---|
247 | | - | else if ((prediction == 38)) |
---|
248 | | - | then 259210 |
---|
249 | | - | else if ((prediction == 39)) |
---|
250 | | - | then 252560 |
---|
251 | | - | else if ((prediction == 40)) |
---|
252 | | - | then 246250 |
---|
253 | | - | else if ((prediction == 41)) |
---|
254 | | - | then 240240 |
---|
255 | | - | else if ((prediction == 42)) |
---|
256 | | - | then 234520 |
---|
257 | | - | else if ((prediction == 43)) |
---|
258 | | - | then 229060 |
---|
259 | | - | else if ((prediction == 44)) |
---|
260 | | - | then 223860 |
---|
261 | | - | else if ((prediction == 45)) |
---|
262 | | - | then 218880 |
---|
263 | | - | else if ((prediction == 46)) |
---|
264 | | - | then 214130 |
---|
265 | | - | else if ((prediction == 47)) |
---|
266 | | - | then 209570 |
---|
267 | | - | else if ((prediction == 48)) |
---|
268 | | - | then 205200 |
---|
269 | | - | else if ((prediction == 49)) |
---|
270 | | - | then 201020 |
---|
271 | | - | else if ((prediction == 50)) |
---|
272 | | - | then 197000 |
---|
273 | | - | else if ((prediction == 51)) |
---|
274 | | - | then 193130 |
---|
275 | | - | else if ((prediction == 52)) |
---|
276 | | - | then 189420 |
---|
277 | | - | else if ((prediction == 53)) |
---|
278 | | - | then 185840 |
---|
279 | | - | else if ((prediction == 54)) |
---|
280 | | - | then 182400 |
---|
281 | | - | else if ((prediction == 55)) |
---|
282 | | - | then 179090 |
---|
283 | | - | else if ((prediction == 56)) |
---|
284 | | - | then 175890 |
---|
285 | | - | else if ((prediction == 57)) |
---|
286 | | - | then 172800 |
---|
287 | | - | else if ((prediction == 58)) |
---|
288 | | - | then 169820 |
---|
289 | | - | else if ((prediction == 59)) |
---|
290 | | - | then 166940 |
---|
291 | | - | else if ((prediction == 60)) |
---|
292 | | - | then 164160 |
---|
293 | | - | else if ((prediction == 61)) |
---|
294 | | - | then 161470 |
---|
295 | | - | else if ((prediction == 62)) |
---|
296 | | - | then 158870 |
---|
297 | | - | else if ((prediction == 63)) |
---|
298 | | - | then 156340 |
---|
299 | | - | else if ((prediction == 64)) |
---|
300 | | - | then 153900 |
---|
301 | | - | else if ((prediction == 65)) |
---|
302 | | - | then 151530 |
---|
303 | | - | else if ((prediction == 66)) |
---|
304 | | - | then 149240 |
---|
305 | | - | else if ((prediction == 67)) |
---|
306 | | - | then 147010 |
---|
307 | | - | else if ((prediction == 68)) |
---|
308 | | - | then 144850 |
---|
309 | | - | else if ((prediction == 69)) |
---|
310 | | - | then 142750 |
---|
311 | | - | else if ((prediction == 70)) |
---|
312 | | - | then 140710 |
---|
313 | | - | else if ((prediction == 71)) |
---|
314 | | - | then 138730 |
---|
315 | | - | else if ((prediction == 72)) |
---|
316 | | - | then 136800 |
---|
317 | | - | else if ((prediction == 73)) |
---|
318 | | - | then 134930 |
---|
319 | | - | else if ((prediction == 74)) |
---|
320 | | - | then 133100 |
---|
321 | | - | else if ((prediction == 75)) |
---|
322 | | - | then 131330 |
---|
323 | | - | else if ((prediction == 76)) |
---|
324 | | - | then 129600 |
---|
325 | | - | else if ((prediction == 77)) |
---|
326 | | - | then 127920 |
---|
327 | | - | else if ((prediction == 78)) |
---|
328 | | - | then 126280 |
---|
329 | | - | else if ((prediction == 79)) |
---|
330 | | - | then 124680 |
---|
331 | | - | else if ((prediction == 80)) |
---|
332 | | - | then 123120 |
---|
333 | | - | else if ((prediction == 81)) |
---|
334 | | - | then 121600 |
---|
335 | | - | else if ((prediction == 82)) |
---|
336 | | - | then 120120 |
---|
337 | | - | else if ((prediction == 83)) |
---|
338 | | - | then 118670 |
---|
339 | | - | else if ((prediction == 84)) |
---|
340 | | - | then 117260 |
---|
341 | | - | else if ((prediction == 85)) |
---|
342 | | - | then 115880 |
---|
343 | | - | else if ((prediction == 86)) |
---|
344 | | - | then 114530 |
---|
345 | | - | else if ((prediction == 87)) |
---|
346 | | - | then 113210 |
---|
347 | | - | else if ((prediction == 88)) |
---|
348 | | - | then 111930 |
---|
349 | | - | else if ((prediction == 89)) |
---|
350 | | - | then 110670 |
---|
351 | | - | else if ((prediction == 90)) |
---|
352 | | - | then 109440 |
---|
353 | | - | else if ((prediction == 91)) |
---|
354 | | - | then 108240 |
---|
355 | | - | else if ((prediction == 92)) |
---|
356 | | - | then 107060 |
---|
357 | | - | else if ((prediction == 93)) |
---|
358 | | - | then 105910 |
---|
359 | | - | else if ((prediction == 94)) |
---|
360 | | - | then 104780 |
---|
361 | | - | else if ((prediction == 95)) |
---|
362 | | - | then 103680 |
---|
363 | | - | else if ((prediction == 96)) |
---|
364 | | - | then 103680 |
---|
365 | | - | else 100000 |
---|
366 | | - | else if ((rollType == ROLLOVER)) |
---|
367 | | - | then if ((prediction == 4)) |
---|
368 | | - | then 103680 |
---|
369 | | - | else if ((prediction == 5)) |
---|
370 | | - | then 103680 |
---|
371 | | - | else if ((prediction == 6)) |
---|
372 | | - | then 104780 |
---|
373 | | - | else if ((prediction == 7)) |
---|
374 | | - | then 105910 |
---|
375 | | - | else if ((prediction == 8)) |
---|
376 | | - | then 107060 |
---|
377 | | - | else if ((prediction == 9)) |
---|
378 | | - | then 108240 |
---|
379 | | - | else if ((prediction == 10)) |
---|
380 | | - | then 109440 |
---|
381 | | - | else if ((prediction == 11)) |
---|
382 | | - | then 110670 |
---|
383 | | - | else if ((prediction == 12)) |
---|
384 | | - | then 111930 |
---|
385 | | - | else if ((prediction == 13)) |
---|
386 | | - | then 113210 |
---|
387 | | - | else if ((prediction == 14)) |
---|
388 | | - | then 114530 |
---|
389 | | - | else if ((prediction == 15)) |
---|
390 | | - | then 115880 |
---|
391 | | - | else if ((prediction == 16)) |
---|
392 | | - | then 117260 |
---|
393 | | - | else if ((prediction == 17)) |
---|
394 | | - | then 118670 |
---|
395 | | - | else if ((prediction == 18)) |
---|
396 | | - | then 120120 |
---|
397 | | - | else if ((prediction == 19)) |
---|
398 | | - | then 121600 |
---|
399 | | - | else if ((prediction == 20)) |
---|
400 | | - | then 123120 |
---|
401 | | - | else if ((prediction == 21)) |
---|
402 | | - | then 124680 |
---|
403 | | - | else if ((prediction == 22)) |
---|
404 | | - | then 126280 |
---|
405 | | - | else if ((prediction == 23)) |
---|
406 | | - | then 127920 |
---|
407 | | - | else if ((prediction == 24)) |
---|
408 | | - | then 129600 |
---|
409 | | - | else if ((prediction == 25)) |
---|
410 | | - | then 131330 |
---|
411 | | - | else if ((prediction == 26)) |
---|
412 | | - | then 133100 |
---|
413 | | - | else if ((prediction == 27)) |
---|
414 | | - | then 134930 |
---|
415 | | - | else if ((prediction == 28)) |
---|
416 | | - | then 136800 |
---|
417 | | - | else if ((prediction == 29)) |
---|
418 | | - | then 138730 |
---|
419 | | - | else if ((prediction == 30)) |
---|
420 | | - | then 140710 |
---|
421 | | - | else if ((prediction == 31)) |
---|
422 | | - | then 142750 |
---|
423 | | - | else if ((prediction == 32)) |
---|
424 | | - | then 144850 |
---|
425 | | - | else if ((prediction == 33)) |
---|
426 | | - | then 147010 |
---|
427 | | - | else if ((prediction == 34)) |
---|
428 | | - | then 149240 |
---|
429 | | - | else if ((prediction == 35)) |
---|
430 | | - | then 151530 |
---|
431 | | - | else if ((prediction == 36)) |
---|
432 | | - | then 153900 |
---|
433 | | - | else if ((prediction == 37)) |
---|
434 | | - | then 156340 |
---|
435 | | - | else if ((prediction == 38)) |
---|
436 | | - | then 158870 |
---|
437 | | - | else if ((prediction == 39)) |
---|
438 | | - | then 161470 |
---|
439 | | - | else if ((prediction == 40)) |
---|
440 | | - | then 164160 |
---|
441 | | - | else if ((prediction == 41)) |
---|
442 | | - | then 166940 |
---|
443 | | - | else if ((prediction == 42)) |
---|
444 | | - | then 169820 |
---|
445 | | - | else if ((prediction == 43)) |
---|
446 | | - | then 172800 |
---|
447 | | - | else if ((prediction == 44)) |
---|
448 | | - | then 175890 |
---|
449 | | - | else if ((prediction == 45)) |
---|
450 | | - | then 179090 |
---|
451 | | - | else if ((prediction == 46)) |
---|
452 | | - | then 185840 |
---|
453 | | - | else if ((prediction == 47)) |
---|
454 | | - | then 185840 |
---|
455 | | - | else if ((prediction == 48)) |
---|
456 | | - | then 189420 |
---|
457 | | - | else if ((prediction == 49)) |
---|
458 | | - | then 193130 |
---|
459 | | - | else if ((prediction == 50)) |
---|
460 | | - | then 197000 |
---|
461 | | - | else if ((prediction == 51)) |
---|
462 | | - | then 201020 |
---|
463 | | - | else if ((prediction == 52)) |
---|
464 | | - | then 205200 |
---|
465 | | - | else if ((prediction == 53)) |
---|
466 | | - | then 209570 |
---|
467 | | - | else if ((prediction == 54)) |
---|
468 | | - | then 214130 |
---|
469 | | - | else if ((prediction == 55)) |
---|
470 | | - | then 218880 |
---|
471 | | - | else if ((prediction == 56)) |
---|
472 | | - | then 223860 |
---|
473 | | - | else if ((prediction == 57)) |
---|
474 | | - | then 229060 |
---|
475 | | - | else if ((prediction == 58)) |
---|
476 | | - | then 234520 |
---|
477 | | - | else if ((prediction == 59)) |
---|
478 | | - | then 240240 |
---|
479 | | - | else if ((prediction == 60)) |
---|
480 | | - | then 246250 |
---|
481 | | - | else if ((prediction == 61)) |
---|
482 | | - | then 252560 |
---|
483 | | - | else if ((prediction == 62)) |
---|
484 | | - | then 259210 |
---|
485 | | - | else if ((prediction == 63)) |
---|
486 | | - | then 259210 |
---|
487 | | - | else if ((prediction == 64)) |
---|
488 | | - | then 273610 |
---|
489 | | - | else if ((prediction == 65)) |
---|
490 | | - | then 281420 |
---|
491 | | - | else if ((prediction == 66)) |
---|
492 | | - | then 289700 |
---|
493 | | - | else if ((prediction == 67)) |
---|
494 | | - | then 298480 |
---|
495 | | - | else if ((prediction == 68)) |
---|
496 | | - | then 307810 |
---|
497 | | - | else if ((prediction == 69)) |
---|
498 | | - | then 317740 |
---|
499 | | - | else if ((prediction == 70)) |
---|
500 | | - | then 328330 |
---|
501 | | - | else if ((prediction == 71)) |
---|
502 | | - | then 339650 |
---|
503 | | - | else if ((prediction == 72)) |
---|
504 | | - | then 351780 |
---|
505 | | - | else if ((prediction == 73)) |
---|
506 | | - | then 364810 |
---|
507 | | - | else if ((prediction == 74)) |
---|
508 | | - | then 378840 |
---|
509 | | - | else if ((prediction == 75)) |
---|
510 | | - | then 394000 |
---|
511 | | - | else if ((prediction == 76)) |
---|
512 | | - | then 410410 |
---|
513 | | - | else if ((prediction == 77)) |
---|
514 | | - | then 428260 |
---|
515 | | - | else if ((prediction == 78)) |
---|
516 | | - | then 447720 |
---|
517 | | - | else if ((prediction == 79)) |
---|
518 | | - | then 469040 |
---|
519 | | - | else if ((prediction == 80)) |
---|
520 | | - | then 492500 |
---|
521 | | - | else if ((prediction == 81)) |
---|
522 | | - | then 518420 |
---|
523 | | - | else if ((prediction == 82)) |
---|
524 | | - | then 547220 |
---|
525 | | - | else if ((prediction == 83)) |
---|
526 | | - | then 579410 |
---|
527 | | - | else if ((prediction == 84)) |
---|
528 | | - | then 615620 |
---|
529 | | - | else if ((prediction == 85)) |
---|
530 | | - | then 656660 |
---|
531 | | - | else if ((prediction == 86)) |
---|
532 | | - | then 703570 |
---|
533 | | - | else if ((prediction == 87)) |
---|
534 | | - | then 757690 |
---|
535 | | - | else if ((prediction == 88)) |
---|
536 | | - | then 820830 |
---|
537 | | - | else if ((prediction == 89)) |
---|
538 | | - | then 895450 |
---|
539 | | - | else if ((prediction == 90)) |
---|
540 | | - | then 985000 |
---|
541 | | - | else if ((prediction == 91)) |
---|
542 | | - | then 1094440 |
---|
543 | | - | else if ((prediction == 92)) |
---|
544 | | - | then 1231250 |
---|
545 | | - | else if ((prediction == 93)) |
---|
546 | | - | then 1407140 |
---|
547 | | - | else if ((prediction == 94)) |
---|
548 | | - | then 1641660 |
---|
549 | | - | else if ((prediction == 95)) |
---|
550 | | - | then 1970000 |
---|
551 | | - | else if ((prediction == 96)) |
---|
552 | | - | then 2462500 |
---|
553 | | - | else if ((prediction == 97)) |
---|
554 | | - | then 3283330 |
---|
555 | | - | else if ((prediction == 98)) |
---|
556 | | - | then 4925000 |
---|
557 | | - | else if ((prediction == 99)) |
---|
558 | | - | then 9850000 |
---|
559 | | - | else 100000 |
---|
560 | | - | else 100000 |
---|
561 | | - | |
---|
562 | | - | |
---|
563 | | - | func diceWin (type,prediction,number) = if ((type == ROLLUNDER)) |
---|
564 | | - | then if ((prediction >= number)) |
---|
565 | | - | then true |
---|
566 | | - | else false |
---|
567 | | - | else if ((type == ROLLOVER)) |
---|
568 | | - | then if ((number >= prediction)) |
---|
569 | | - | then true |
---|
570 | | - | else false |
---|
571 | | - | else false |
---|
572 | | - | |
---|
573 | | - | |
---|
574 | | - | func ValidateBetAndDefineWinAmt (amount,prediction,rollType) = if (if ((BETMIN > amount)) |
---|
575 | | - | then true |
---|
576 | | - | else (amount > BETMAX)) |
---|
577 | | - | then throw(((("Bet amount is not in range: minBet=" + toString((BETMIN / WAVELET))) + " maxBet=") + toString((BETMAX / WAVELET)))) |
---|
578 | | - | else if (if ((rollType != ROLLUNDER)) |
---|
579 | | - | then (rollType != ROLLOVER) |
---|
580 | | - | else false) |
---|
581 | | - | then throw("Invalid Roll type, try with OVER or UNDER") |
---|
582 | | - | else if (if ((PREDICTIONMIN > prediction)) |
---|
583 | | - | then true |
---|
584 | | - | else (prediction > PREDICTIONMAX)) |
---|
585 | | - | then throw(((("Prediction is out of the range: " + toString(PREDICTIONMIN)) + " <= prediction <= ") + toString(PREDICTIONMAX))) |
---|
586 | | - | else { |
---|
587 | | - | let multi = Multiplier(prediction, rollType) |
---|
588 | | - | ((((amount * multi) / 100000) * (100 - (FEEWAVESBET + FEEMCAFEE))) / 100) |
---|
589 | | - | } |
---|
590 | | - | |
---|
591 | | - | |
---|
592 | | - | @Callable(i) |
---|
593 | | - | func playDice (rollType,prediction) = { |
---|
594 | | - | let gameId = toBase58String(i.transactionId) |
---|
595 | | - | let payment = extract(i.payment) |
---|
596 | | - | let feeAssetId = isDefined(i.feeAssetId) |
---|
597 | | - | let multi = Multiplier(prediction, rollType) |
---|
598 | | - | let winAmt = ValidateBetAndDefineWinAmt(payment.amount, prediction, rollType) |
---|
599 | | - | let playerBalance = wavesBalance(i.caller) |
---|
600 | | - | let gameIdUsed = isDefined(getString(this, gameId)) |
---|
601 | | - | if ((payment.assetId != WBET)) |
---|
602 | | - | then throw("Payment should be in Wavesbet") |
---|
603 | | - | else if ((100000 > playerBalance)) |
---|
604 | | - | then throw("There are not enough waves, it takes 0.01 Waves to bet. Game aborted.") |
---|
605 | | - | else if (feeAssetId) |
---|
606 | | - | then throw("Transaction's fee must be in Waves. Game aborted.") |
---|
607 | | - | else if (gameIdUsed) |
---|
608 | | - | then throw("Passed gameId had been used before. Game aborted.") |
---|
609 | | - | else { |
---|
610 | | - | let newGameNum = IncrementGameNum() |
---|
611 | | - | let playerPubKey58 = toBase58String(i.callerPublicKey) |
---|
612 | | - | let gameDataStr = FormatGameDataStr(STATESUBMITTED, prediction, rollType, playerPubKey58, winAmt, "") |
---|
613 | | - | ScriptResult(WriteSet([DataEntry(GAMESCOUNTERKEY, newGameNum), DataEntry(gameId, gameDataStr)]), TransferSet(nil)) |
---|
614 | | - | } |
---|
615 | | - | } |
---|
616 | | - | |
---|
617 | | - | |
---|
618 | | - | |
---|
619 | | - | @Callable(i) |
---|
620 | | - | func withdraw (gameId,rsaSig) = { |
---|
621 | | - | let gameDataList = ExtractGameDataList(gameId) |
---|
622 | | - | let gameState = gameDataList[IdxGameState] |
---|
623 | | - | let prediction = parseIntValue(gameDataList[IdxPrediction]) |
---|
624 | | - | let rollType = gameDataList[IdxType] |
---|
625 | | - | let winAmt = parseIntValue(gameDataList[IdxWinAmt]) |
---|
626 | | - | let playerPubKey58 = gameDataList[IdxPlayerPubKey58] |
---|
627 | | - | let playerAddress = addressFromPublicKey(fromBase58String(playerPubKey58)) |
---|
628 | | - | let decreasedReserves = DecreaseReservedAmt(gameId, winAmt) |
---|
629 | | - | if ((gameState != STATESUBMITTED)) |
---|
630 | | - | then throw("Invalid game state for passed gameId. Game aborted.") |
---|
631 | | - | else { |
---|
632 | | - | let rand = GenerateRandInt(gameId, rsaSig) |
---|
633 | | - | let randStr = RandToStr(rand) |
---|
634 | | - | if (diceWin(rollType, prediction, rand)) |
---|
635 | | - | then { |
---|
636 | | - | let newGameDataStr = FormatGameDataStr(STATEWON, prediction, rollType, playerPubKey58, winAmt, randStr) |
---|
637 | | - | WinScriptSet(gameId, playerAddress, winAmt, newGameDataStr, decreasedReserves) |
---|
638 | | - | } |
---|
639 | | - | else { |
---|
640 | | - | let newGameDataStr = FormatGameDataStr(STATELOST, prediction, rollType, playerPubKey58, winAmt, randStr) |
---|
641 | | - | WriteSet([DataEntry(gameId, newGameDataStr), decreasedReserves]) |
---|
642 | | - | } |
---|
643 | | - | } |
---|
644 | | - | } |
---|
645 | | - | |
---|
646 | | - | |
---|
647 | | - | @Verifier(tx) |
---|
648 | | - | func verify () = if (sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)) |
---|
649 | | - | then match tx { |
---|
650 | | - | case ttx: TransferTransaction => |
---|
651 | | - | ((assetBalance(this, WBET) - ttx.amount) >= ExtractReservedAmt()) |
---|
652 | | - | case stx: SetScriptTransaction => |
---|
653 | | - | true |
---|
654 | | - | case itx: InvokeScriptTransaction => |
---|
655 | | - | if ((itx.function == "withdraw")) |
---|
656 | | - | then true |
---|
657 | | - | else false |
---|
658 | | - | case _ => |
---|
659 | | - | false |
---|
660 | | - | } |
---|
661 | | - | else false |
---|