tx · 7WWjGkD3nNkb79mPUneKXDVjZbWyj2yMMeRzHEVXxMJ1

3Muyzdmm3UXRnExyAHEtqcWcaUn8VLhT8TE:  -0.01400000 Waves

2019.11.02 00:24 [746328] smart account 3Muyzdmm3UXRnExyAHEtqcWcaUn8VLhT8TE > SELF 0.00000000 Waves

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

github/deemru/w8io/3ef1775 
86.19 ms