fix: notifications of roulette, craps

This commit is contained in:
shashkevichfrida 2024-01-07 16:58:37 +03:00
parent 655ba5e776
commit 6028952af5
13 changed files with 62 additions and 36 deletions

View file

@ -1 +1 @@
{"name":"Craps","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":311,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"playCraps","offset":95,"parameters":[{"name":"bet","type":"Integer"},{"name":"firstSum","type":"Integer"},{"name":"secondSum","type":"Integer"}],"returntype":"Void","safe":false}],"events":[{"name":"Crup number","parameters":[{"name":"int","type":"Integer"}]},{"name":"Random number","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null}
{"name":"Craps","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":543,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"playCraps","offset":95,"parameters":[{"name":"bet","type":"Integer"},{"name":"firstSum","type":"Integer"},{"name":"secondSum","type":"Integer"}],"returntype":"Void","safe":false}],"events":[{"name":"Crup number","parameters":[{"name":"int","type":"Integer"}]},{"name":"Random number","parameters":[{"name":"int","type":"Integer"}]},{"name":"playerBalance","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null}

View file

@ -16,7 +16,6 @@ func _deploy(data interface{}, isUpdate bool) {
return
}
// Parse hash of forint contract from incoming data
args := data.(struct {
zaCoinHash interop.Hash160
})
@ -50,6 +49,8 @@ func PlayCraps(bet int, firstSum int, secondSum int) {
} else {
changePlayerBalance(ctx, playerOwner, -bet)
}
playerBalance = contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int)
runtime.Notify("playerBalance", playerBalance)
}
func isWinner(firstSum int, secondSum int) bool {
@ -87,15 +88,13 @@ func changePlayerBalance(ctx storage.Context, playerOwner interop.Hash160, balan
var from, to interop.Hash160
var transferAmount int
if balanceChange > 0 {
// Transfer funds from contract to player owner
from = playerContract
to = playerOwner
transferAmount = balanceChange
} else {
// Transfer funds from player owner to contract
from = playerOwner
to = playerContract
transferAmount = -balanceChange // We flip sender/receiver, but keep amount positive
transferAmount = -balanceChange
}
transferred := contract.Call(zaCoinHash, "transfer", contract.All, from, to, transferAmount, nil).(bool)

Binary file not shown.

View file

@ -9,7 +9,13 @@ events:
parameters:
- name: "int"
type: "Integer"
- name: "playerBalance"
parameters:
- name: "int"
type: "Integer"
permissions:
- methods: '*'
events:
- "Crup number"
- "Random number"
- "playerBalance"

View file

@ -52,6 +52,8 @@ func PlayRoulette(bet int, selectedNumber int) {
} else {
changePlayerBalance(ctx, playerOwner, -bet)
}
playerBalance = contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int)
runtime.Notify("playerBalance", playerBalance)
}
func isWinner(selectedNumber int) bool {

View file

@ -1 +1 @@
{"name":"Roulette","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":408,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"playRoulette","offset":95,"parameters":[{"name":"bet","type":"Integer"},{"name":"selectedNumber","type":"Integer"}],"returntype":"Void","safe":false}],"events":[{"name":"rouletteNumber","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[{"pubkey":"027171df30177d401c638fb2ddc14f9dbda323291e363ba4f7c3b19a8b44c8ba0a","signature":"xSD7RzJHXAPvoQfwznNSFOu0E8CWbNrWLnLNInig/J66uBky9YZlj4h1wvC0VWQFtAnTLxmuo1UVRh2NGRhAww=="}],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null}
{"name":"Roulette","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":473,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"playRoulette","offset":95,"parameters":[{"name":"bet","type":"Integer"},{"name":"selectedNumber","type":"Integer"}],"returntype":"Void","safe":false}],"events":[{"name":"rouletteNumber","parameters":[{"name":"int","type":"Integer"}]},{"name":"playerBalance","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null}

Binary file not shown.

View file

@ -1,11 +1,16 @@
name: Roulette
name: Roulette
supportedstandards: []
events:
- name: "rouletteNumber"
parameters:
- name: "int"
type: "Integer"
- name: "playerBalance"
parameters:
- name: "int"
type: "Integer"
permissions:
- methods: '*'
events:
- "rouletteNumber"
- "playerBalance"

View file

@ -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":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}
{"name":"SlotMashine","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":458,"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":"SlotResult","parameters":[{"name":"array","type":"Array"}]},{"name":"playerBalance","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null}

View file

@ -1,16 +1,16 @@
name: SlotMashine
supportedstandards: []
events:
- name: "wheelNumber"
- name: "SlotResult"
parameters:
- name: "int"
type: "Integer"
- name: "value"
- name: "array"
type: "Array"
- name: "playerBalance"
parameters:
- name: "int"
type: "Integer"
permissions:
- methods: '*'
events:
- "wheelNumber"
- "value"
- "SlotResult"
- "playerBalance"

View file

@ -17,13 +17,12 @@ func _deploy(data interface{}, isUpdate bool) {
return
}
// Parse hash of forint contract from incoming data
args := data.(struct {
zaCoinHash interop.Hash160
})
if len(args.zaCoinHash) != interop.Hash160Len {
panic("invalid hash of zaCoin contract")
panic("Invalid hash of zaCoin contract")
}
@ -52,27 +51,22 @@ func RollSlot(bet int) {
win := res * bet
changePlayerBalance(ctx, playerOwner, win)
}
playerBalance = contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int)
runtime.Notify("playerBalance", playerBalance)
}
func roll() int {
var result [3]int
for i:=0; i<3; i++ {
wheel := (runtime.GetRandom() % 8) + 1
result[i] = wheel
runtime.Log("WheelNumber=" + string(i + 1) +", value="+string(wheel))
}
runtime.Notify("SlotResult", result)
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
if (result[0] == result[1] && result[0] == result[2]){
return result[0]
} else {
return 0
}
@ -86,7 +80,7 @@ func OnNEP17Payment(from interop.Hash160, amount int, data any) {
callingHash := runtime.GetCallingScriptHash()
if !callingHash.Equals(zaCoinHash) {
panic("only ZC is accepted")
panic("Only ZC is accepted")
}
}
@ -97,15 +91,13 @@ func changePlayerBalance(ctx storage.Context, playerOwner interop.Hash160, balan
var from, to interop.Hash160
var transferAmount int
if balanceChange > 0 {
// Transfer funds from contract to player owner
from = playerContract
to = playerOwner
transferAmount = balanceChange
} else {
// Transfer funds from player owner to contract
from = playerOwner
to = playerContract
transferAmount = -balanceChange // We flip sender/receiver, but keep amount positive
transferAmount = -balanceChange
}
transferred := contract.Call(zaCoinHash, "transfer", contract.All, from, to, transferAmount, nil).(bool)

Binary file not shown.

View file

@ -0,0 +1,22 @@
{
"name": "n3UserWallet",
"chain": "neo3",
"version": "1.0",
"scrypt": {
"cost": 16384,
"blockSize": 8,
"parallel": 8,
"size": 64
},
"accounts": [
{
"address": "NQCLAHuu4umnR99KB5m7U8ppJFtWqhw6DS",
"label": "test",
"isDefault": false,
"lock": false,
"key": "6PYKvmjnpLfNTbmx1YiHmZK6zYik7NSaqDZAeWcaVbcdxULYnXkKWW183H",
"contract": {},
"extra": null
}
]
}