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 0000000..4840c9e Binary files /dev/null and b/SlotMashine/slot.nef differ