From 94ad40bb4b0f006a50a8915ccfd53e509ea1f672 Mon Sep 17 00:00:00 2001 From: shashkevichfrida Date: Wed, 3 Jan 2024 15:29:52 +0300 Subject: [PATCH] fix: craps, slot fixed checks, added logs --- Craps/craps.go | 12 ++++++++++++ SlotMashine/config.json | 2 +- SlotMashine/slot.go | 14 ++++++++++++++ SlotMashine/slot.nef | Bin 645 -> 865 bytes 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Craps/craps.go b/Craps/craps.go index fd2c48e..00b5000 100644 --- a/Craps/craps.go +++ b/Craps/craps.go @@ -33,6 +33,17 @@ func _deploy(data interface{}, isUpdate bool) { func PlayCraps(bet int, firstSum int, secondSum int) { ctx := storage.GetContext() playerOwner := runtime.GetScriptContainer().Sender + + if bet <= 0 { + panic("Invalid bet amount") + } + + zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160) + playerBalance := contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int) + if playerBalance < bet { + panic("Insufficient funds") + } + isWin := isWinner(firstSum, secondSum) if (isWin){ changePlayerBalance(ctx, playerOwner, bet) @@ -49,6 +60,7 @@ func isWinner(firstSum int, secondSum int) bool { sum := 0 for i:=0; i<2; i++ { crap := (runtime.GetRandom() % 6) + 1 + runtime.Log("Crup number " + string(i+1) + " Rundom number " + string(crap)) runtime.Notify("Crup number", i+1) runtime.Notify("Random number", crap) sum += crap diff --git a/SlotMashine/config.json b/SlotMashine/config.json index fa884ec..c835d50 100755 --- a/SlotMashine/config.json +++ b/SlotMashine/config.json @@ -1 +1 @@ -{"name":"SlotMashine","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":328,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"rollSlot","offset":95,"parameters":[{"name":"bet","type":"Integer"}],"returntype":"Void","safe":false}],"events":[{"name":"wheelNumber","parameters":[{"name":"int","type":"Integer"}]},{"name":"value","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file +{"name":"SlotMashine","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":548,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"rollSlot","offset":95,"parameters":[{"name":"bet","type":"Integer"}],"returntype":"Void","safe":false}],"events":[{"name":"wheelNumber","parameters":[{"name":"int","type":"Integer"}]},{"name":"value","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file diff --git a/SlotMashine/slot.go b/SlotMashine/slot.go index d9062aa..727a425 100644 --- a/SlotMashine/slot.go +++ b/SlotMashine/slot.go @@ -34,6 +34,17 @@ func _deploy(data interface{}, isUpdate bool) { func RollSlot(bet int) { ctx := storage.GetContext() playerOwner := runtime.GetScriptContainer().Sender + + if bet <= 0 { + panic("Invalid bet amount") + } + zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160) + playerBalance := contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int) + + if playerBalance < bet { + panic("Insufficient funds") + } + res := roll() if (res == 0){ changePlayerBalance(ctx, playerOwner, -bet) @@ -48,14 +59,17 @@ func roll() int { firstWheel := (runtime.GetRandom() % 8) + 1 runtime.Notify("wheelNumber", 1) runtime.Notify("value", firstWheel) + runtime.Log("WheelNumber 1, value="+string(firstWheel)) secondWheel := (runtime.GetRandom() % 8) + 1 runtime.Notify("wheelNumber", 2) runtime.Notify("value", secondWheel) + runtime.Log("WheelNumber 2, value="+string(secondWheel)) thirdWheel := (runtime.GetRandom() % 8) + 1 runtime.Notify("wheelNumber", 3) runtime.Notify("value", thirdWheel) + runtime.Log("WheelNumber 3, value="+string(thirdWheel)) if (firstWheel == secondWheel && firstWheel == thirdWheel){ return firstWheel diff --git a/SlotMashine/slot.nef b/SlotMashine/slot.nef index e8c8c38308688b7333f6afc16c19351652d53716..26b81e9a54f64fce6ef658bf3a669ecaa749faac 100755 GIT binary patch delta 281 zcmZo=eaJS!i%F1qqECV*JEP<5Z|Ua>9CZUZ41~`WRtV^b^9Xt7l_ln6rYIz(mMA3V z=9lJ`SWTYGC>2qZDR`hHi-$8QF()xEIn_T+Fek(@sWv*u>!zX#%WcKt>qkVk;A+(p-VfYJ3@)6|;j)S1~d$DDmf3EGWy!%nLT1J@J;cDvxM* zMrvw~UukYqYLSAWjsnmLrKz?VUN<#>Mr(9Co`3E>ZL%n%37SeHn96Kam7a_iXey0i SD)UfOE^cIGWKo?Rs{#N~nqbiY delta 79 zcmV-V0I>hz289KXN&+