From 7ab6c67c46af639841b97a73575774d3a6f02a6d Mon Sep 17 00:00:00 2001 From: shashkevichfrida Date: Fri, 17 Nov 2023 15:41:59 +0300 Subject: [PATCH] add 2 contracts --- Craps/craps.go | 22 ++++++++++++++ Craps/craps.yml | 11 +++++++ Craps/go.mod | 4 +++ Player/go.mod | 4 +++ Player/player.go | 73 +++++++++++++++++++++++++++++++++++++++++++++++ Player/player.yml | 11 +++++++ 6 files changed, 125 insertions(+) create mode 100644 Craps/craps.go create mode 100644 Craps/craps.yml create mode 100644 Craps/go.mod create mode 100644 Player/go.mod create mode 100644 Player/player.go create mode 100644 Player/player.yml diff --git a/Craps/craps.go b/Craps/craps.go new file mode 100644 index 0000000..1a71897 --- /dev/null +++ b/Craps/craps.go @@ -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 +} + diff --git a/Craps/craps.yml b/Craps/craps.yml new file mode 100644 index 0000000..10334ce --- /dev/null +++ b/Craps/craps.yml @@ -0,0 +1,11 @@ +name: Craps +sourceurl: http://example.com/ +safemethods: [] +supportedstandards: [] +events: + - name: Hello world! + parameters: + - name: args + type: Array +permissions: + - methods: '*' diff --git a/Craps/go.mod b/Craps/go.mod new file mode 100644 index 0000000..11eb6b7 --- /dev/null +++ b/Craps/go.mod @@ -0,0 +1,4 @@ +module Craps +require ( + github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5 +) \ No newline at end of file diff --git a/Player/go.mod b/Player/go.mod new file mode 100644 index 0000000..68b3261 --- /dev/null +++ b/Player/go.mod @@ -0,0 +1,4 @@ +module Player +require ( + github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5 +) \ No newline at end of file diff --git a/Player/player.go b/Player/player.go new file mode 100644 index 0000000..268fc12 --- /dev/null +++ b/Player/player.go @@ -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 +} diff --git a/Player/player.yml b/Player/player.yml new file mode 100644 index 0000000..773b9be --- /dev/null +++ b/Player/player.yml @@ -0,0 +1,11 @@ +name: Player +sourceurl: http://example.com/ +safemethods: [] +supportedstandards: [] +events: + - name: Hello world! + parameters: + - name: args + type: Array +permissions: + - methods: '*'