fix: Roulette fixed checks
fix: Roulette added checks for balance, bets, selectedNum
This commit is contained in:
parent
a85d8b4a97
commit
5ac6dbe2a9
1 changed files with 18 additions and 7 deletions
|
@ -31,9 +31,22 @@ func _deploy(data interface{}, isUpdate bool) {
|
|||
func PlayRoulette(bet int, selectedNumber int) {
|
||||
ctx := storage.GetContext()
|
||||
playerOwner := runtime.GetScriptContainer().Sender
|
||||
|
||||
if bet <= 0 {
|
||||
panic("Invalid bet amount")
|
||||
}
|
||||
|
||||
playerBalance := contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int)
|
||||
if playerBalance < bet {
|
||||
panic("Insufficient funds")
|
||||
}
|
||||
|
||||
if selectedNumber < 1 || selectedNumber > 36 {
|
||||
panic("Illegal number selected for roulette")
|
||||
}
|
||||
|
||||
isWin := isWinner(selectedNumber)
|
||||
if isWin {
|
||||
// Calculate win amount based on the selectedNumber
|
||||
winAmount := calculateWinAmount(bet, selectedNumber)
|
||||
changePlayerBalance(ctx, playerOwner, winAmount)
|
||||
} else {
|
||||
|
@ -43,8 +56,6 @@ func PlayRoulette(bet int, selectedNumber int) {
|
|||
|
||||
func isWinner(selectedNumber int) bool {
|
||||
rouletteNumber := (runtime.GetRandom() % 36) + 1
|
||||
runtime.Notify("rouletteNumber", rouletteNumber)
|
||||
|
||||
return rouletteNumber == selectedNumber
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue