tx · FwfpqDPfs3EvW1znFgeaBgWkz9oSo2YyLTkwEc4xbs2w 3N2tusqAtDctK8iSTXS6F9rimmftmSuwLUX: -0.05000000 Waves 2019.10.29 06:19 [740884] smart account 3N2tusqAtDctK8iSTXS6F9rimmftmSuwLUX > SELF 0.00000000 Waves
{ "type": 13, "id": "FwfpqDPfs3EvW1znFgeaBgWkz9oSo2YyLTkwEc4xbs2w", "fee": 5000000, "feeAssetId": null, "timestamp": 1572319171585, "version": 1, "sender": "3N2tusqAtDctK8iSTXS6F9rimmftmSuwLUX", "senderPublicKey": "ACfUG5PwG2GssMuyEwVEhkYAbbbP1geSHR8XoNxLyu6V", "proofs": [ "5yCX93tbQS74Vv7DJXARH8omvKhypSbEXu4V1vtLDwAUhYnpcno6TcQhdYGMGstLo7eiFWm1fgn6PANT5RsbhCQZ" ], "script": "base64:AAIDAAAAAAAAAAcIARIDCgEIAAAAHQAAAAAJUlNBUFVCTElDCQACWwAAAAECAAABj2Jhc2U2NDpNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQWc0ZEFSNlhiQkRBUzloci9FajNkSnY2RmZjNDY2eC9tT0dNV1UzbHJBQnMzcWE4QkhtdUpHbmtmYnBFZjJ2QXdZVE9XUHZ2emZNMTBPQmJmbG9TeXEzYzlNS3Z5VGUxbHVCTEdxVzR2WlVYSXl2U2d6MWxpeVVWZWZJUXkzZHlGOWpiZVRaYkMwYmJjVC83TzNERUwrMDF6NkErckRDYWNTWjBsR29sU1E2QW5oTHh6SWtWcE9RSmJyQm1DK3grWnVaUENNV3pKeW5kNWFlT243amFqL21rUlZ5eGU2Zy8wT2hXejROaWlaWGV1TVJCKzhtS3kwZldEL1VsSWxaV0hzQVMyWm1ya1hLcWpMcTAvMHdyOElMSmt6bmpTcWRuSTVJYmpnM3VRcmovNEFOK2k5cjI4YVE3My9aa1B0WTVTYncwQU9pQUJCdTdnSG1xOWF5VnhaUUlEQVFBQgAAAAAPR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ZXRBbmREZWZpbmVXaW5BbXQAAAADCAUAAAAHcGF5bWVudAAAAAZhbW91bnQFAAAABnBhQ29pbgUAAAAHcGF5VHlwZQQAAAALZ2FtZURhdGFTdHIJAQAAABFGb3JtYXRHYW1lRGF0YVN0cgAAAAgFAAAADlNUQVRFU1VCTUlUVEVEBQAAAAZwYUNvaW4FAAAAD3BsYXllckFQdWJLZXk1OAUAAAAHcGF5VHlwZQgFAAAAB3BheW1lbnQAAAAGYW1vdW50BQAAAAZ3aW5BbXQCAAAAAAIAAAAACQEAAAAMU2NyaXB0UmVzdWx0AAAAAgkBAAAACFdyaXRlU2V0AAAAAQkABEwAAAACCQEAAAAJRGF0YUVudHJ5AAAAAgUAAAAPR0FNRVNDT1VOVEVSS0VZBQAAAApuZXdHYW1lTnVtCQAETAAAAAIJAQAAAAlEYXRhRW50cnkAAAACBQAAAAZnYW1lSWQFAAAAC2dhbWVEYXRhU3RyBQAAAANuaWwJAQAAAAtUcmFuc2ZlclNldAAAAAEFAAAAA25pbAAAAABNwl2d", "chainId": 84, "height": 740884, "spentComplexity": 0 } View: original | compacted Prev: C7EMUrbJvfo1YZd8n7fR7Lkr2Pw1skyDk2qsFFN93Kwz Next: 7gBhkZkMAsTDKCE6Z8rkRCqo7TFruS5BqVzJmLhcaxde Diff:
Old | New | Differences | |
---|---|---|---|
5 | 5 | ||
6 | 6 | let GAMESCOUNTERKEY = "$GAME_NUM" | |
7 | 7 | ||
8 | - | let RESERVATIONKEY = "$RESERVED_AMOUNT" | |
9 | - | ||
10 | 8 | let WBET = base58'23vgV9p9pD83A7CFbsDEc4zjanep7UeFo4ZRS6oGorhv' | |
11 | - | ||
12 | - | let WAVELET = 100000000 | |
13 | 9 | ||
14 | 10 | let FEEWAVESBET = 4 | |
15 | 11 | ||
16 | 12 | let FEEMCAFEE = 2 | |
17 | 13 | ||
14 | + | let WAVELET = 100000000 | |
15 | + | ||
18 | 16 | let STATESUBMITTED = "SUBMITTED" | |
19 | 17 | ||
20 | - | let | |
18 | + | let STATEACCEPTED = "ACCEPTED" | |
21 | 19 | ||
22 | - | let | |
20 | + | let STATEFINISHED = "FINISHED" | |
23 | 21 | ||
24 | - | let | |
22 | + | let STATECANCELED = "CANCELED" | |
25 | 23 | ||
26 | - | let | |
24 | + | let COINRED = "RED" | |
27 | 25 | ||
28 | - | let | |
26 | + | let COINBLUE = "BLUE" | |
29 | 27 | ||
30 | - | let | |
28 | + | let BETMINWAVES = ((1 * WAVELET) / 2) | |
31 | 29 | ||
32 | - | let PREDICTIONMIN = 1 | |
33 | - | ||
34 | - | let PREDICTIONMAX = 99 | |
30 | + | let BETMINWBET = (100 * WAVELET) | |
35 | 31 | ||
36 | 32 | let IdxGameState = 0 | |
37 | 33 | ||
38 | - | let | |
34 | + | let IdxPlayerACoin = 1 | |
39 | 35 | ||
40 | - | let | |
36 | + | let IdxPlayerAPubKey58 = 2 | |
41 | 37 | ||
42 | - | let | |
38 | + | let IdxPayType = 3 | |
43 | 39 | ||
44 | - | let | |
40 | + | let IdxPayAmt = 4 | |
45 | 41 | ||
46 | - | let IdxRandOrEmpty = 5 | |
42 | + | let IdxWinAmt = 5 | |
43 | + | ||
44 | + | let IdxPlayerBCoin = 6 | |
45 | + | ||
46 | + | let IdxPlayerBPubKey58 = 7 | |
47 | 47 | ||
48 | 48 | func IncrementGameNum () = { | |
49 | 49 | let gameNum = match getInteger(this, GAMESCOUNTERKEY) { | |
56 | 56 | } | |
57 | 57 | ||
58 | 58 | ||
59 | - | func ExtractReservedAmt () = match getInteger(this, RESERVATIONKEY) { | |
60 | - | case a: Int => | |
61 | - | a | |
62 | - | case _ => | |
63 | - | 0 | |
64 | - | } | |
59 | + | func generateNumber (inv,max,min) = { | |
60 | + | let lastPlay = match getBinary(this, "lastPlay") { | |
61 | + | case s: ByteVector => | |
62 | + | s | |
63 | + | case a: Unit => | |
64 | + | base58'2ee4oFDYriWJ9EMeR' | |
65 | + | case _ => | |
66 | + | throw() | |
67 | + | } | |
68 | + | let rand = (((((lastPlay + inv.transactionId) + inv.callerPublicKey) + lastBlock.generationSignature) + toBytes(lastBlock.timestamp)) + toBytes(lastBlock.height)) | |
69 | + | (((toInt(sha256(rand)) % 1000) % ((max - min) + 1)) + 1) | |
70 | + | } | |
65 | 71 | ||
66 | 72 | ||
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 | - | } | |
73 | + | func paymentType (payment) = if ((payment.assetId == WBET)) | |
74 | + | then "WBET" | |
75 | + | else "WAVES" | |
76 | + | ||
77 | + | ||
78 | + | func tokenType (token) = if ((token == "WBET")) | |
79 | + | then WBET | |
80 | + | else unit | |
74 | 81 | ||
75 | 82 | ||
76 | 83 | func FormatGameDataParam (p) = { | |
85 | 92 | } | |
86 | 93 | ||
87 | 94 | ||
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 == "")) | |
95 | + | func FormatGameDataStr (gameState,playerACoin,playerAPubKey58,payType,payAmount,winAmt,playerBCoin,playerBPubKey58) = { | |
96 | + | let fullStateStr = ((((((((((FormatGameDataParam(gameState) + "_") + FormatGameDataParam(playerACoin)) + "_") + FormatGameDataParam(playerAPubKey58)) + "_") + FormatGameDataParam(payType)) + "_") + FormatGameDataParam(toString(payAmount))) + "_") + FormatGameDataParam(toString(winAmt))) | |
97 | + | if (if ((playerBCoin == "")) | |
98 | + | then (playerBPubKey58 == "") | |
99 | + | else false) | |
91 | 100 | then fullStateStr | |
92 | - | else ((fullStateStr + "_") + FormatGameDataParam( | |
101 | + | else ((((fullStateStr + "_") + FormatGameDataParam(playerBCoin)) + "_") + FormatGameDataParam(playerBPubKey58)) | |
93 | 102 | } | |
94 | 103 | ||
95 | 104 | ||
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) | |
105 | + | func ValidateBetAndDefineWinAmt (amount,playerCoin,paymentType) = if (if ((playerCoin != COINRED)) | |
106 | + | then (playerCoin != COINBLUE) | |
159 | 107 | 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) | |
108 | + | then throw("Invalid play, change your bet to RED or BLUE coin. Game aborted.") | |
109 | + | else if (if ((paymentType == "WBET")) | |
110 | + | then (BETMINWBET > amount) | |
580 | 111 | 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 | - | } | |
112 | + | then throw(("The minimum bet on Wbet is " + toString((BETMINWBET / WAVELET)))) | |
113 | + | else if (if ((paymentType == "WAVES")) | |
114 | + | then (BETMINWAVES > amount) | |
115 | + | else false) | |
116 | + | then throw(("The minimum bet on Waves is " + toString((BETMINWAVES / WAVELET)))) | |
117 | + | else (((amount * 2) * WAVELET) * ((100 - (FEEWAVESBET + FEEMCAFEE)) / 100)) | |
590 | 118 | ||
591 | 119 | ||
592 | 120 | @Callable(i) | |
593 | - | func | |
121 | + | func playCoin (paCoin) = { | |
594 | 122 | let gameId = toBase58String(i.transactionId) | |
123 | + | let gameIdUsed = isDefined(getString(this, gameId)) | |
595 | 124 | let payment = extract(i.payment) | |
596 | 125 | 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 ((1000000 > 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(RESERVATIONKEY, ValidateAndIncreaseReservedAmt(winAmt)), DataEntry(GAMESCOUNTERKEY, newGameNum), DataEntry(gameId, gameDataStr)]), TransferSet(nil)) | |
614 | - | } | |
126 | + | if (if ((payment.assetId != assetInfo(base58'WAVES'))) | |
127 | + | then (payment.assetId != WBET) | |
128 | + | else false) | |
129 | + | then throw("Payment should be in Wbet or Waves. Game aborted.") | |
130 | + | else if (feeAssetId) | |
131 | + | then throw("Transaction's fee must be in Waves. Game aborted.") | |
132 | + | else if (gameIdUsed) | |
133 | + | then throw("Passed gameId had been used before. Game aborted.") | |
134 | + | else { | |
135 | + | let newGameNum = IncrementGameNum() | |
136 | + | let playerAPubKey58 = toBase58String(i.callerPublicKey) | |
137 | + | let payType = paymentType(payment) | |
138 | + | let winAmt = ValidateBetAndDefineWinAmt(payment.amount, paCoin, payType) | |
139 | + | let gameDataStr = FormatGameDataStr(STATESUBMITTED, paCoin, playerAPubKey58, payType, payment.amount, winAmt, "", "") | |
140 | + | ScriptResult(WriteSet([DataEntry(GAMESCOUNTERKEY, newGameNum), DataEntry(gameId, gameDataStr)]), TransferSet(nil)) | |
141 | + | } | |
615 | 142 | } | |
616 | 143 | ||
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 _ => | |
655 | - | false | |
656 | - | } | |
657 | - | else false | |
658 | 144 |
Old | New | Differences | |
---|---|---|---|
1 | 1 | {-# STDLIB_VERSION 3 #-} | |
2 | 2 | {-# SCRIPT_TYPE ACCOUNT #-} | |
3 | 3 | {-# CONTENT_TYPE DAPP #-} | |
4 | 4 | let RSAPUBLIC = fromBase64String("base64:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAg4dAR6XbBDAS9hr/Ej3dJv6Ffc466x/mOGMWU3lrABs3qa8BHmuJGnkfbpEf2vAwYTOWPvvzfM10OBbfloSyq3c9MKvyTe1luBLGqW4vZUXIyvSgz1liyUVefIQy3dyF9jbeTZbC0bbcT/7O3DEL+01z6A+rDCacSZ0lGolSQ6AnhLxzIkVpOQJbrBmC+x+ZuZPCMWzJynd5aeOn7jaj/mkRVyxe6g/0OhWz4NiiZXeuMRB+8mKy0fWD/UlIlZWHsAS2ZmrkXKqjLq0/0wr8ILJkznjSqdnI5Ibjg3uQrj/4AN+i9r28aQ73/ZkPtY5Sbw0AOiABBu7gHmq9ayVxZQIDAQAB") | |
5 | 5 | ||
6 | 6 | let GAMESCOUNTERKEY = "$GAME_NUM" | |
7 | 7 | ||
8 | - | let RESERVATIONKEY = "$RESERVED_AMOUNT" | |
9 | - | ||
10 | 8 | let WBET = base58'23vgV9p9pD83A7CFbsDEc4zjanep7UeFo4ZRS6oGorhv' | |
11 | - | ||
12 | - | let WAVELET = 100000000 | |
13 | 9 | ||
14 | 10 | let FEEWAVESBET = 4 | |
15 | 11 | ||
16 | 12 | let FEEMCAFEE = 2 | |
17 | 13 | ||
14 | + | let WAVELET = 100000000 | |
15 | + | ||
18 | 16 | let STATESUBMITTED = "SUBMITTED" | |
19 | 17 | ||
20 | - | let | |
18 | + | let STATEACCEPTED = "ACCEPTED" | |
21 | 19 | ||
22 | - | let | |
20 | + | let STATEFINISHED = "FINISHED" | |
23 | 21 | ||
24 | - | let | |
22 | + | let STATECANCELED = "CANCELED" | |
25 | 23 | ||
26 | - | let | |
24 | + | let COINRED = "RED" | |
27 | 25 | ||
28 | - | let | |
26 | + | let COINBLUE = "BLUE" | |
29 | 27 | ||
30 | - | let | |
28 | + | let BETMINWAVES = ((1 * WAVELET) / 2) | |
31 | 29 | ||
32 | - | let PREDICTIONMIN = 1 | |
33 | - | ||
34 | - | let PREDICTIONMAX = 99 | |
30 | + | let BETMINWBET = (100 * WAVELET) | |
35 | 31 | ||
36 | 32 | let IdxGameState = 0 | |
37 | 33 | ||
38 | - | let | |
34 | + | let IdxPlayerACoin = 1 | |
39 | 35 | ||
40 | - | let | |
36 | + | let IdxPlayerAPubKey58 = 2 | |
41 | 37 | ||
42 | - | let | |
38 | + | let IdxPayType = 3 | |
43 | 39 | ||
44 | - | let | |
40 | + | let IdxPayAmt = 4 | |
45 | 41 | ||
46 | - | let IdxRandOrEmpty = 5 | |
42 | + | let IdxWinAmt = 5 | |
43 | + | ||
44 | + | let IdxPlayerBCoin = 6 | |
45 | + | ||
46 | + | let IdxPlayerBPubKey58 = 7 | |
47 | 47 | ||
48 | 48 | func IncrementGameNum () = { | |
49 | 49 | let gameNum = match getInteger(this, GAMESCOUNTERKEY) { | |
50 | 50 | case num: Int => | |
51 | 51 | num | |
52 | 52 | case _ => | |
53 | 53 | 0 | |
54 | 54 | } | |
55 | 55 | (gameNum + 1) | |
56 | 56 | } | |
57 | 57 | ||
58 | 58 | ||
59 | - | func ExtractReservedAmt () = match getInteger(this, RESERVATIONKEY) { | |
60 | - | case a: Int => | |
61 | - | a | |
62 | - | case _ => | |
63 | - | 0 | |
64 | - | } | |
59 | + | func generateNumber (inv,max,min) = { | |
60 | + | let lastPlay = match getBinary(this, "lastPlay") { | |
61 | + | case s: ByteVector => | |
62 | + | s | |
63 | + | case a: Unit => | |
64 | + | base58'2ee4oFDYriWJ9EMeR' | |
65 | + | case _ => | |
66 | + | throw() | |
67 | + | } | |
68 | + | let rand = (((((lastPlay + inv.transactionId) + inv.callerPublicKey) + lastBlock.generationSignature) + toBytes(lastBlock.timestamp)) + toBytes(lastBlock.height)) | |
69 | + | (((toInt(sha256(rand)) % 1000) % ((max - min) + 1)) + 1) | |
70 | + | } | |
65 | 71 | ||
66 | 72 | ||
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 | - | } | |
73 | + | func paymentType (payment) = if ((payment.assetId == WBET)) | |
74 | + | then "WBET" | |
75 | + | else "WAVES" | |
76 | + | ||
77 | + | ||
78 | + | func tokenType (token) = if ((token == "WBET")) | |
79 | + | then WBET | |
80 | + | else unit | |
74 | 81 | ||
75 | 82 | ||
76 | 83 | func FormatGameDataParam (p) = { | |
77 | 84 | let s = size(p) | |
78 | 85 | if ((s == 0)) | |
79 | 86 | then throw("Parameter size must be greater then 0") | |
80 | 87 | else if ((s > 99)) | |
81 | 88 | then throw("Parameter size must be less then 100") | |
82 | 89 | else if ((10 > s)) | |
83 | 90 | then (("0" + toString(s)) + p) | |
84 | 91 | else (toString(s) + p) | |
85 | 92 | } | |
86 | 93 | ||
87 | 94 | ||
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 == "")) | |
95 | + | func FormatGameDataStr (gameState,playerACoin,playerAPubKey58,payType,payAmount,winAmt,playerBCoin,playerBPubKey58) = { | |
96 | + | let fullStateStr = ((((((((((FormatGameDataParam(gameState) + "_") + FormatGameDataParam(playerACoin)) + "_") + FormatGameDataParam(playerAPubKey58)) + "_") + FormatGameDataParam(payType)) + "_") + FormatGameDataParam(toString(payAmount))) + "_") + FormatGameDataParam(toString(winAmt))) | |
97 | + | if (if ((playerBCoin == "")) | |
98 | + | then (playerBPubKey58 == "") | |
99 | + | else false) | |
91 | 100 | then fullStateStr | |
92 | - | else ((fullStateStr + "_") + FormatGameDataParam( | |
101 | + | else ((((fullStateStr + "_") + FormatGameDataParam(playerBCoin)) + "_") + FormatGameDataParam(playerBPubKey58)) | |
93 | 102 | } | |
94 | 103 | ||
95 | 104 | ||
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) | |
105 | + | func ValidateBetAndDefineWinAmt (amount,playerCoin,paymentType) = if (if ((playerCoin != COINRED)) | |
106 | + | then (playerCoin != COINBLUE) | |
159 | 107 | 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) | |
108 | + | then throw("Invalid play, change your bet to RED or BLUE coin. Game aborted.") | |
109 | + | else if (if ((paymentType == "WBET")) | |
110 | + | then (BETMINWBET > amount) | |
580 | 111 | 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 | - | } | |
112 | + | then throw(("The minimum bet on Wbet is " + toString((BETMINWBET / WAVELET)))) | |
113 | + | else if (if ((paymentType == "WAVES")) | |
114 | + | then (BETMINWAVES > amount) | |
115 | + | else false) | |
116 | + | then throw(("The minimum bet on Waves is " + toString((BETMINWAVES / WAVELET)))) | |
117 | + | else (((amount * 2) * WAVELET) * ((100 - (FEEWAVESBET + FEEMCAFEE)) / 100)) | |
590 | 118 | ||
591 | 119 | ||
592 | 120 | @Callable(i) | |
593 | - | func | |
121 | + | func playCoin (paCoin) = { | |
594 | 122 | let gameId = toBase58String(i.transactionId) | |
123 | + | let gameIdUsed = isDefined(getString(this, gameId)) | |
595 | 124 | let payment = extract(i.payment) | |
596 | 125 | 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 ((1000000 > 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(RESERVATIONKEY, ValidateAndIncreaseReservedAmt(winAmt)), DataEntry(GAMESCOUNTERKEY, newGameNum), DataEntry(gameId, gameDataStr)]), TransferSet(nil)) | |
614 | - | } | |
126 | + | if (if ((payment.assetId != assetInfo(base58'WAVES'))) | |
127 | + | then (payment.assetId != WBET) | |
128 | + | else false) | |
129 | + | then throw("Payment should be in Wbet or Waves. Game aborted.") | |
130 | + | else if (feeAssetId) | |
131 | + | then throw("Transaction's fee must be in Waves. Game aborted.") | |
132 | + | else if (gameIdUsed) | |
133 | + | then throw("Passed gameId had been used before. Game aborted.") | |
134 | + | else { | |
135 | + | let newGameNum = IncrementGameNum() | |
136 | + | let playerAPubKey58 = toBase58String(i.callerPublicKey) | |
137 | + | let payType = paymentType(payment) | |
138 | + | let winAmt = ValidateBetAndDefineWinAmt(payment.amount, paCoin, payType) | |
139 | + | let gameDataStr = FormatGameDataStr(STATESUBMITTED, paCoin, playerAPubKey58, payType, payment.amount, winAmt, "", "") | |
140 | + | ScriptResult(WriteSet([DataEntry(GAMESCOUNTERKEY, newGameNum), DataEntry(gameId, gameDataStr)]), TransferSet(nil)) | |
141 | + | } | |
615 | 142 | } | |
616 | 143 | ||
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 _ => | |
655 | - | false | |
656 | - | } | |
657 | - | else false | |
658 | 144 |
github/deemru/w8io/169f3d6 74.46 ms ◑