merge
This commit is contained in:
commit
8d8273f615
24 changed files with 64108 additions and 33 deletions
|
@ -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":313,"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":[]},"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":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}
|
|
@ -1,7 +1,6 @@
|
|||
package Craps
|
||||
|
||||
import (
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
|
@ -9,8 +8,6 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
gasDecimals = 1_0000_0000
|
||||
initialBalance = 3000
|
||||
zaCoinHashKey = "zaCoinHash"
|
||||
)
|
||||
|
||||
|
@ -45,17 +42,15 @@ func PlayCraps(bet int, firstSum int, secondSum int) {
|
|||
}
|
||||
|
||||
func isWinner(firstSum int, secondSum int) bool {
|
||||
crupNumber:="Crup number: "
|
||||
rundomNumber:=" Random number: "
|
||||
if (!((firstSum >= 3 && firstSum <= 18) && (secondSum >= 3 && firstSum <= 18))){
|
||||
panic("first and second sum should be from 3 to 18")
|
||||
if (!((firstSum >= 2 && firstSum <= 12) && (secondSum >= 2 && firstSum <= 12))){
|
||||
panic("first and second sum should be from 2 to 12")
|
||||
}
|
||||
|
||||
sum := 0
|
||||
|
||||
for i:=0; i<3; i++ {
|
||||
for i:=0; i<2; i++ {
|
||||
crap := (runtime.GetRandom() % 6) + 1
|
||||
runtime.Notify(crupNumber, i+1, rundomNumber, crap)
|
||||
runtime.Notify("Crup number", i+1)
|
||||
runtime.Notify("Random number", crap)
|
||||
sum += crap
|
||||
}
|
||||
|
||||
|
|
BIN
Craps/craps.nef
BIN
Craps/craps.nef
Binary file not shown.
|
@ -1,5 +1,15 @@
|
|||
name: Craps
|
||||
supportedstandards: []
|
||||
events:
|
||||
- name: "Crup number"
|
||||
parameters:
|
||||
- name: "int"
|
||||
type: "Integer"
|
||||
- name: "Random number"
|
||||
parameters:
|
||||
- name: "int"
|
||||
type: "Integer"
|
||||
permissions:
|
||||
- methods: '*'
|
||||
events:
|
||||
- "Crup number"
|
||||
|
|
|
@ -3,5 +3,3 @@ module Craps
|
|||
go 1.21.4
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231121104256-0493ddbd70b2
|
||||
|
||||
require github.com/nspcc-dev/neo-go v0.104.0 // indirect
|
||||
|
|
|
@ -1,6 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go v0.104.0 h1:FGj3Z46yABcFIAI1SCLd1jQSoh+B00h/2VAgEgY1JKQ=
|
||||
github.com/nspcc-dev/neo-go v0.104.0/go.mod h1:omsUK5PAtG2/nQ3/evs95QEg3wtkj3LH53e0NKtXVwQ=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5 h1:09CpI5uwsxb1EeFPIKQRwwWlfCmDD/Dwwh01lPiQScM=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231121104256-0493ddbd70b2 h1:hPVF8iMmsQ15GSemj1ma6C9BkwfAugEXsUAVTEniK5M=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231121104256-0493ddbd70b2/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag=
|
||||
|
|
|
@ -8,8 +8,6 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
gasDecimals = 1_0000_0000
|
||||
initialBalance = 3000
|
||||
zaCoinHashKey = "zaCoinHash"
|
||||
)
|
||||
|
||||
|
@ -23,7 +21,7 @@ func _deploy(data interface{}, isUpdate bool) {
|
|||
})
|
||||
|
||||
if len(args.zaCoinHash) != interop.Hash160Len {
|
||||
panic("invalid hash of zaCoin contract")
|
||||
panic("Invalid hash of zaCoin contract")
|
||||
}
|
||||
|
||||
ctx := storage.GetContext()
|
||||
|
@ -33,9 +31,23 @@ 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")
|
||||
}
|
||||
zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160)
|
||||
playerBalance := contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int)
|
||||
if playerBalance < bet {
|
||||
panic("Insufficient funds lol, expected > " + string(rune(bet)) + "but balance " + string(rune(playerBalance)))
|
||||
}
|
||||
|
||||
if selectedNumber < 1 || selectedNumber > 36 {
|
||||
panic("Illegal number selected for roulette")
|
||||
}
|
||||
|
||||
isWin := isWinner(selectedNumber)
|
||||
if isWin {
|
||||
// Calculate win amount based on the selectedNumber
|
||||
panic("You win!")
|
||||
winAmount := calculateWinAmount(bet, selectedNumber)
|
||||
changePlayerBalance(ctx, playerOwner, winAmount)
|
||||
} else {
|
||||
|
@ -45,8 +57,8 @@ func PlayRoulette(bet int, selectedNumber int) {
|
|||
|
||||
func isWinner(selectedNumber int) bool {
|
||||
rouletteNumber := (runtime.GetRandom() % 36) + 1
|
||||
runtime.Notify("Roulette number:", rouletteNumber)
|
||||
|
||||
runtime.Notify("rouletteNumber", rouletteNumber)
|
||||
runtime.Log("rouletteNumber " + string(rouletteNumber))
|
||||
return rouletteNumber == selectedNumber
|
||||
}
|
||||
|
||||
|
|
1
Roulette/config.json
Normal file
1
Roulette/config.json
Normal file
|
@ -0,0 +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":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null}
|
5
Roulette/go.mod
Normal file
5
Roulette/go.mod
Normal file
|
@ -0,0 +1,5 @@
|
|||
module Roulette
|
||||
|
||||
go 1.21.5
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231214154544-3766206f441a
|
2
Roulette/go.sum
Normal file
2
Roulette/go.sum
Normal file
|
@ -0,0 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231214154544-3766206f441a h1:1AVlB7TD9HC+PutOO1rzNhJ/6t1ieGX1ULIj2ReH+g4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231214154544-3766206f441a/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag=
|
BIN
Roulette/roulette.nef
Executable file
BIN
Roulette/roulette.nef
Executable file
Binary file not shown.
11
Roulette/roulette.yml
Normal file
11
Roulette/roulette.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
name: Roulette
|
||||
supportedstandards: []
|
||||
events:
|
||||
- name: "rouletteNumber"
|
||||
parameters:
|
||||
- name: "int"
|
||||
type: "Integer"
|
||||
permissions:
|
||||
- methods: '*'
|
||||
events:
|
||||
- "rouletteNumber"
|
2
SlotMashine/config.json
Executable file
2
SlotMashine/config.json
Executable file
|
@ -0,0 +1,2 @@
|
|||
{"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}
|
||||
|
16
SlotMashine/config.yml
Normal file
16
SlotMashine/config.yml
Normal file
|
@ -0,0 +1,16 @@
|
|||
name: SlotMashine
|
||||
supportedstandards: []
|
||||
events:
|
||||
- name: "wheelNumber"
|
||||
parameters:
|
||||
- name: "int"
|
||||
type: "Integer"
|
||||
- name: "value"
|
||||
parameters:
|
||||
- name: "int"
|
||||
type: "Integer"
|
||||
permissions:
|
||||
- methods: '*'
|
||||
events:
|
||||
- "wheelNumber"
|
||||
- "value"
|
5
SlotMashine/go.mod
Normal file
5
SlotMashine/go.mod
Normal file
|
@ -0,0 +1,5 @@
|
|||
module SlotMashine
|
||||
|
||||
go 1.21.5
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231214154544-3766206f441a
|
2
SlotMashine/go.sum
Normal file
2
SlotMashine/go.sum
Normal file
|
@ -0,0 +1,2 @@
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231214154544-3766206f441a h1:1AVlB7TD9HC+PutOO1rzNhJ/6t1ieGX1ULIj2ReH+g4=
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231214154544-3766206f441a/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag=
|
101
SlotMashine/slot.go
Normal file
101
SlotMashine/slot.go
Normal file
|
@ -0,0 +1,101 @@
|
|||
package SlotMashine
|
||||
|
||||
import (
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||
)
|
||||
|
||||
const (
|
||||
zaCoinHashKey = "zaCoinHash"
|
||||
)
|
||||
|
||||
func _deploy(data interface{}, isUpdate bool) {
|
||||
if isUpdate {
|
||||
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")
|
||||
}
|
||||
|
||||
|
||||
ctx := storage.GetContext()
|
||||
storage.Put(ctx, zaCoinHashKey, args.zaCoinHash)
|
||||
}
|
||||
|
||||
func RollSlot(bet int) {
|
||||
ctx := storage.GetContext()
|
||||
playerOwner := runtime.GetScriptContainer().Sender
|
||||
res := roll()
|
||||
if (res == 0){
|
||||
changePlayerBalance(ctx, playerOwner, -bet)
|
||||
} else {
|
||||
win := res * bet
|
||||
changePlayerBalance(ctx, playerOwner, win)
|
||||
}
|
||||
}
|
||||
|
||||
func roll() int {
|
||||
|
||||
firstWheel := (runtime.GetRandom() % 8) + 1
|
||||
runtime.Notify("wheelNumber", 1)
|
||||
runtime.Notify("value", firstWheel)
|
||||
|
||||
secondWheel := (runtime.GetRandom() % 8) + 1
|
||||
runtime.Notify("wheelNumber", 2)
|
||||
runtime.Notify("value", secondWheel)
|
||||
|
||||
thirdWheel := (runtime.GetRandom() % 8) + 1
|
||||
runtime.Notify("wheelNumber", 3)
|
||||
runtime.Notify("value", thirdWheel)
|
||||
|
||||
if (firstWheel == secondWheel && firstWheel == thirdWheel){
|
||||
return firstWheel
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
func OnNEP17Payment(from interop.Hash160, amount int, data any) {
|
||||
ctx := storage.GetContext()
|
||||
zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160)
|
||||
|
||||
callingHash := runtime.GetCallingScriptHash()
|
||||
if !callingHash.Equals(zaCoinHash) {
|
||||
panic("only ZC is accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func changePlayerBalance(ctx storage.Context, playerOwner interop.Hash160, balanceChange int) {
|
||||
zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160)
|
||||
playerContract := runtime.GetExecutingScriptHash()
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
transferred := contract.Call(zaCoinHash, "transfer", contract.All, from, to, transferAmount, nil).(bool)
|
||||
if !transferred {
|
||||
panic("failed to transfer zaCoins")
|
||||
}
|
||||
}
|
BIN
SlotMashine/slot.nef
Executable file
BIN
SlotMashine/slot.nef
Executable file
Binary file not shown.
|
@ -1 +1 @@
|
|||
{"name":"ZaCoin","abi":{"methods":[{"name":"balanceOf","offset":583,"parameters":[{"name":"holder","type":"Hash160"}],"returntype":"Integer","safe":true},{"name":"decimals","offset":559,"parameters":[],"returntype":"Integer","safe":true},{"name":"isUsableAddress","offset":254,"parameters":[{"name":"addr","type":"ByteArray"}],"returntype":"Boolean","safe":false},{"name":"mint","offset":633,"parameters":[{"name":"to","type":"Hash160"}],"returntype":"Void","safe":false},{"name":"symbol","offset":554,"parameters":[],"returntype":"String","safe":true},{"name":"totalSupply","offset":564,"parameters":[],"returntype":"Integer","safe":true},{"name":"transfer","offset":606,"parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Boolean","safe":false}],"events":[{"name":"Transfer","parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"}]}]},"features":{},"groups":[{"pubkey":"027171df30177d401c638fb2ddc14f9dbda323291e363ba4f7c3b19a8b44c8ba0a","signature":"2YQ2Jy/KZJlg9lQyguFyOpKfY4L2HYvwHkb6XkiALhVlPFVUKXvKMF5I2u9dnIFCLvI0W9h/D/46edTwPCpLjg=="}],"permissions":[{"contract":"*","methods":["onNEP17Payment"]}],"supportedstandards":["NEP-17"],"trusts":[],"extra":null}
|
||||
{"name":"ZaCoin","abi":{"methods":[{"name":"balanceOf","offset":583,"parameters":[{"name":"holder","type":"Hash160"}],"returntype":"Integer","safe":true},{"name":"decimals","offset":559,"parameters":[],"returntype":"Integer","safe":true},{"name":"isUsableAddress","offset":254,"parameters":[{"name":"addr","type":"ByteArray"}],"returntype":"Boolean","safe":false},{"name":"mint","offset":633,"parameters":[{"name":"to","type":"Hash160"}],"returntype":"Void","safe":false},{"name":"symbol","offset":554,"parameters":[],"returntype":"String","safe":true},{"name":"totalSupply","offset":564,"parameters":[],"returntype":"Integer","safe":true},{"name":"transfer","offset":606,"parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Boolean","safe":false}],"events":[{"name":"Transfer","parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":["onNEP17Payment"]}],"supportedstandards":["NEP-17"],"trusts":[],"extra":null}
|
Binary file not shown.
|
@ -7,7 +7,6 @@ import (
|
|||
)
|
||||
|
||||
func getToken() Token {
|
||||
// Owner of the wallet is wallets/game-wallet.json нету еще
|
||||
owner := address.ToHash160("NXbLSnHA8dNuMUPUSNNivx7XFucN1w5bRq")
|
||||
token := Token{
|
||||
Name: "ZaCoin",
|
||||
|
@ -53,6 +52,6 @@ func Mint(to interop.Hash160) {
|
|||
ctx := storage.GetContext()
|
||||
minted := getToken().Mint(ctx, to)
|
||||
if !minted {
|
||||
panic("failed to mint initial supply")
|
||||
panic("Failed to mint initial supply")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":"1.0","accounts":[{"address":"NhCHDEtGgSph1v6PmjFC1gtzJWNKtNSadk","key":"6PYQVTyo4PHBvegpRzSCNijGw6Zj2qN4wLVxTj5CM8nvsoYxkzBHqPzjzq","label":"wallet1","contract":{"script":"DCEDsJuqv/P2EHx+msuHIab8VhjUW1AkejFNguVIcCzOjNVBVuezJw==","parameters":[{"name":"parameter0","type":"Signature"}],"deployed":false},"lock":false,"isDefault":false}],"scrypt":{"n":16384,"r":8,"p":8},"extra":{"Tokens":null}}
|
||||
{"version":"1.0","accounts":[{"address":"NNkgaxu8GR6s53CYcjGkavVjJsqC4LH6J9","key":"6PYLVbnCcCCb4GA6vPShKapv9PRwwo9rPmY33wDvvrbs9mysTQrPJYaUYK","label":"","contract":{"script":"DCEDvS4Krub5RkiiMrvQ4jM1PgqDw5rlhScBziY1oCTNZ7RBVuezJw==","parameters":[{"name":"parameter0","type":"Signature"}],"deployed":false},"lock":false,"isDefault":false}],"scrypt":{"n":16384,"r":8,"p":8},"extra":{"Tokens":null}}
|
|
@ -1 +1 @@
|
|||
{"version":"1.0","accounts":[{"address":"NivQRezLwGP8xFPr87DD5XaYGUKK3BMsTa","key":"6PYWJrGbrRmY9eTagWhNaucN2PfuPmi1G3QStUwNX8uAtCjTs6UYj1V1J9","label":"wallet2","contract":{"script":"DCED44dZlzprtyK6q8LdhANqOfCy9T0y/sRaTazeilD+S3BBVuezJw==","parameters":[{"name":"parameter0","type":"Signature"}],"deployed":false},"lock":false,"isDefault":false}],"scrypt":{"n":16384,"r":8,"p":8},"extra":{"Tokens":null}}
|
||||
{"version":"1.0","accounts":[{"address":"NW3soYmG6gBDmcWnFwDZbTVcFtgHPfKy4Z","key":"6PYVqRwEt2NDWwv4BY4ExMVY4tVsdHfSjQq9PCcX7GEfzoigU3fWedp1AQ","label":"frida","contract":{"script":"DCECujzjikhCmhorLPbReBCUm685BB5wgJI2DNJ0V01Ix9VBVuezJw==","parameters":[{"name":"parameter0","type":"Signature"}],"deployed":false},"lock":false,"isDefault":false}],"scrypt":{"n":16384,"r":8,"p":8},"extra":{"Tokens":null}}
|
Loading…
Reference in a new issue