From 646fb5134fb9ab223ddad8f5f00580642e2e6baf Mon Sep 17 00:00:00 2001 From: symyzi Date: Fri, 15 Dec 2023 01:00:10 +0300 Subject: [PATCH 1/2] Slot --- SlotMashine/config.json | 1 + SlotMashine/config.yml | 11 +++++ SlotMashine/go.mod | 5 ++ SlotMashine/go.sum | 2 + SlotMashine/slot.go | 99 ++++++++++++++++++++++++++++++++++++++++ SlotMashine/slot.nef | Bin 0 -> 609 bytes 6 files changed, 118 insertions(+) create mode 100644 SlotMashine/config.json create mode 100644 SlotMashine/config.yml create mode 100644 SlotMashine/go.mod create mode 100644 SlotMashine/go.sum create mode 100644 SlotMashine/slot.go create mode 100644 SlotMashine/slot.nef diff --git a/SlotMashine/config.json b/SlotMashine/config.json new file mode 100644 index 0000000..5253b0f --- /dev/null +++ b/SlotMashine/config.json @@ -0,0 +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":273,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"roll","offset":146,"parameters":[],"returntype":"Integer","safe":false},{"name":"rollSlot","offset":95,"parameters":[{"name":"bet","type":"Integer"}],"returntype":"Void","safe":false}],"events":[{"name":"Hello world!","parameters":[{"name":"args","type":"Array"}]}]},"features":{},"groups":[{"pubkey":"027171df30177d401c638fb2ddc14f9dbda323291e363ba4f7c3b19a8b44c8ba0a","signature":"BJ8mav1w7idePc0nfCF0RnL07oO9nzJMoAfG5dPpKyFAcnb0ucTLPQLZUD/bkvH0F/oG3DlCHPscCEMz2b2wGg=="}],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file diff --git a/SlotMashine/config.yml b/SlotMashine/config.yml new file mode 100644 index 0000000..f0fa80d --- /dev/null +++ b/SlotMashine/config.yml @@ -0,0 +1,11 @@ +name: SlotMashine +sourceurl: http://example.com/ +safemethods: [] +supportedstandards: [] +events: + - name: Hello world! + parameters: + - name: args + type: Array +permissions: + - methods: '*' diff --git a/SlotMashine/go.mod b/SlotMashine/go.mod new file mode 100644 index 0000000..a083f56 --- /dev/null +++ b/SlotMashine/go.mod @@ -0,0 +1,5 @@ +module SlotMashine + +go 1.21.5 + +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5 diff --git a/SlotMashine/go.sum b/SlotMashine/go.sum new file mode 100644 index 0000000..05f981f --- /dev/null +++ b/SlotMashine/go.sum @@ -0,0 +1,2 @@ +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= diff --git a/SlotMashine/slot.go b/SlotMashine/slot.go new file mode 100644 index 0000000..914c9cf --- /dev/null +++ b/SlotMashine/slot.go @@ -0,0 +1,99 @@ +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 { + wheelNumber:="Wheel number: " + value:=" Value: " + firstWheel := (runtime.GetRandom() % 8) + 1 + runtime.Notify(wheelNumber, 1, value, firstWheel) + + secondWheel := (runtime.GetRandom() % 8) + 1 + runtime.Notify(wheelNumber, 2, value, secondWheel) + + thirdWheel := (runtime.GetRandom() % 8) + 1 + runtime.Notify(wheelNumber, 3, 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") + } +} diff --git a/SlotMashine/slot.nef b/SlotMashine/slot.nef new file mode 100644 index 0000000000000000000000000000000000000000..4840c9e116bef3286c592fad825f77729d6d96fe GIT binary patch literal 609 zcmeZsbu-RO&DTxO*EP^HG%(gPWFQ#`XOxr_Sn2DhRwU*YV=9MMpWTq%&Bo=2V3nN&*z)?4l!$A04p@~va zmcV8;zKqO@*}5IBBEfk@f|*&t!Uu{ovI88aGUg}3B}#-cbAS@18M$Z@Wx|X)kX)cT2-36N==?eDlIWHCpAT(Bwqoh1R90K KRt~@9earzb-Mtk6 literal 0 HcmV?d00001 From 7eff5877d190d486ddac7263cdfe9e282aec9967 Mon Sep 17 00:00:00 2001 From: shashkevichfrida Date: Fri, 15 Dec 2023 18:00:48 +0300 Subject: [PATCH 2/2] slot, roulette done --- Craps/config.json | 2 +- Craps/craps.go | 2 -- Craps/go.mod | 2 -- Craps/go.sum | 4 ---- Roulette/Roulette.go | 5 ++--- Roulette/config.json | 1 + Roulette/go.mod | 5 +++++ Roulette/go.sum | 2 ++ Roulette/roulette.nef | Bin 0 -> 542 bytes Roulette/roulette.yml | 5 +++++ SlotMashine/config.json | 2 +- SlotMashine/config.yml | 6 ------ SlotMashine/go.mod | 2 +- SlotMashine/go.sum | 4 ++-- SlotMashine/slot.nef | Bin 609 -> 590 bytes 15 files changed, 20 insertions(+), 22 deletions(-) create mode 100755 Roulette/config.json create mode 100644 Roulette/go.mod create mode 100644 Roulette/go.sum create mode 100755 Roulette/roulette.nef create mode 100644 Roulette/roulette.yml mode change 100644 => 100755 SlotMashine/config.json mode change 100644 => 100755 SlotMashine/slot.nef diff --git a/Craps/config.json b/Craps/config.json index 6a19ca8..46d97a7 100755 --- a/Craps/config.json +++ b/Craps/config.json @@ -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} \ No newline at end of file +{"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":[{"pubkey":"027171df30177d401c638fb2ddc14f9dbda323291e363ba4f7c3b19a8b44c8ba0a","signature":"BK6YPJGG/GLKsVxdPra+Ti4p7Q2D502dzz8FXV8kYntGrd4IigAyXR4do0pUPLRBnZHUqZXpPo7+jkQko/hCIQ=="}],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file diff --git a/Craps/craps.go b/Craps/craps.go index b5def96..41a9867 100644 --- a/Craps/craps.go +++ b/Craps/craps.go @@ -9,8 +9,6 @@ import ( ) const ( - gasDecimals = 1_0000_0000 - initialBalance = 3000 zaCoinHashKey = "zaCoinHash" ) diff --git a/Craps/go.mod b/Craps/go.mod index 6531e63..1bc38fa 100644 --- a/Craps/go.mod +++ b/Craps/go.mod @@ -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 diff --git a/Craps/go.sum b/Craps/go.sum index aa82492..080fa54 100644 --- a/Craps/go.sum +++ b/Craps/go.sum @@ -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= diff --git a/Roulette/Roulette.go b/Roulette/Roulette.go index 196936c..09d490e 100644 --- a/Roulette/Roulette.go +++ b/Roulette/Roulette.go @@ -8,8 +8,6 @@ import ( ) const ( - gasDecimals = 1_0000_0000 - initialBalance = 3000 zaCoinHashKey = "zaCoinHash" ) @@ -44,8 +42,9 @@ func PlayRoulette(bet int, selectedNumber int) { } func isWinner(selectedNumber int) bool { + rouletteNumberMes := "Roulette number: " rouletteNumber := (runtime.GetRandom() % 36) + 1 - runtime.Notify("Roulette number:", rouletteNumber) + runtime.Notify(rouletteNumberMes, rouletteNumber) return rouletteNumber == selectedNumber } diff --git a/Roulette/config.json b/Roulette/config.json new file mode 100755 index 0000000..c2764e4 --- /dev/null +++ b/Roulette/config.json @@ -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":225,"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":[]},"features":{},"groups":[{"pubkey":"027171df30177d401c638fb2ddc14f9dbda323291e363ba4f7c3b19a8b44c8ba0a","signature":"FcCvRQaSYi8vaeDWGYxyHVclTxuuvTX5SagRGaoz018rX579K1GGi13EVJHix9iADDni/QSYOPNxH6Y2RzxXpA=="}],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file diff --git a/Roulette/go.mod b/Roulette/go.mod new file mode 100644 index 0000000..1acfc2e --- /dev/null +++ b/Roulette/go.mod @@ -0,0 +1,5 @@ +module Roulette + +go 1.21.5 + +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231214154544-3766206f441a diff --git a/Roulette/go.sum b/Roulette/go.sum new file mode 100644 index 0000000..8471af9 --- /dev/null +++ b/Roulette/go.sum @@ -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= diff --git a/Roulette/roulette.nef b/Roulette/roulette.nef new file mode 100755 index 0000000000000000000000000000000000000000..dd061baef5a84def36a628fafe043d9a438e2a65 GIT binary patch literal 542 zcmeZsbu-RO&DTxO*EP^HG%(gPWFQaxJ;xZ%#8j!q>`>u#(@}-xwqrqtz&WoQDy*lJ zSX>1dL^M=*5OFvhb$-@Pa z@Bk_U8WQaI%wD3!A)JK?EMMTL8^~cGe6Fz4M5!oCO}L^mz{I;aBQrbL^a9ZBN<0~v z6|;j)j{w;Y;mnLYffp)M}WG-+J0J?w~;(`oh7X~;^ihW_|b<+Uo zX@f#X%iuhlqO9WV8)|HsHSWNlAf~zJ6*&Vs1fBs$Oz_uKq?>RwkBT@;>GO>}?D%