add 2 contracts
This commit is contained in:
parent
a0789c9bd1
commit
7ab6c67c46
6 changed files with 125 additions and 0 deletions
22
Craps/craps.go
Normal file
22
Craps/craps.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package Craps
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
)
|
||||
|
||||
func IsWinner(firstSum int, secondSum int) bool {
|
||||
if (!((firstSum >= 3 && firstSum <= 18) && (secondSum >= 3 && firstSum <= 18))){
|
||||
panic("first and second sum should be from 3 to 36")
|
||||
}
|
||||
|
||||
sum := 0
|
||||
|
||||
for i:=0; i<3; i++ {
|
||||
crap := randomInRange(1, 6)
|
||||
runtime.Notify("Crup number: %d,Random Number: %d", i+1, randomNumber)
|
||||
sum += crup
|
||||
}
|
||||
|
||||
return sum == firstSum || sum == secondSum
|
||||
}
|
||||
|
11
Craps/craps.yml
Normal file
11
Craps/craps.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
name: Craps
|
||||
sourceurl: http://example.com/
|
||||
safemethods: []
|
||||
supportedstandards: []
|
||||
events:
|
||||
- name: Hello world!
|
||||
parameters:
|
||||
- name: args
|
||||
type: Array
|
||||
permissions:
|
||||
- methods: '*'
|
4
Craps/go.mod
Normal file
4
Craps/go.mod
Normal file
|
@ -0,0 +1,4 @@
|
|||
module Craps
|
||||
require (
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5
|
||||
)
|
4
Player/go.mod
Normal file
4
Player/go.mod
Normal file
|
@ -0,0 +1,4 @@
|
|||
module Player
|
||||
require (
|
||||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5
|
||||
)
|
73
Player/player.go
Normal file
73
Player/player.go
Normal file
|
@ -0,0 +1,73 @@
|
|||
package Player
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/oracle"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/lib/address"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||
)
|
||||
|
||||
type Player struct {
|
||||
balance int
|
||||
}
|
||||
|
||||
func _deploy(data interface{}, isUpdate bool) {
|
||||
if isUpdate {
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
func NewPlayer(playerName string) {
|
||||
ctx := storage.GetContext()
|
||||
|
||||
existingPlayer := storage.Get(ctx, playerName)
|
||||
if existingPlayer != nil {
|
||||
panic("player already exists")
|
||||
}
|
||||
|
||||
player := Player{
|
||||
balance: 0,
|
||||
}
|
||||
|
||||
storage.Put(ctx, playerName, std.Serialize(player))
|
||||
}
|
||||
|
||||
func ReplenishBalance(playerName string, balance int) {
|
||||
|
||||
}
|
||||
|
||||
func playCraps(plyerName string, bet int, firstSum int, secondSum int) {
|
||||
player := getPlayer(playerName)
|
||||
if bet <= player.balance {
|
||||
panic("not enough money on the balance sheet")
|
||||
}
|
||||
|
||||
crapsHash := address.ToHash160("сюда надо hash смартконтракта Craps")
|
||||
isWinner := contract.Call(crapsHash, "isWinner", contract.ReadOnly, firstSum, secondSum).(bool)
|
||||
|
||||
if isWinner {
|
||||
player.balance += bet
|
||||
}
|
||||
else {
|
||||
player.balance -= bet
|
||||
}
|
||||
}
|
||||
|
||||
func getPlayer(playerName string) Player {
|
||||
ctx := storage.GetReadOnlyContext()
|
||||
data := storage.Get(ctx, playerName)
|
||||
if data == nil {
|
||||
panic("player not found")
|
||||
}
|
||||
|
||||
return std.Deserialize(data.([]byte)).(Player)
|
||||
}
|
||||
|
||||
func Balance(playerName string) int {
|
||||
p := getPlayer(playerName)
|
||||
return p.balance
|
||||
}
|
11
Player/player.yml
Normal file
11
Player/player.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
name: Player
|
||||
sourceurl: http://example.com/
|
||||
safemethods: []
|
||||
supportedstandards: []
|
||||
events:
|
||||
- name: Hello world!
|
||||
parameters:
|
||||
- name: args
|
||||
type: Array
|
||||
permissions:
|
||||
- methods: '*'
|
Loading…
Reference in a new issue