From cc4f3a1df467652490e30738002da0ed278ff2ca Mon Sep 17 00:00:00 2001 From: shashkevichfrida Date: Tue, 16 Jan 2024 16:59:15 +0300 Subject: [PATCH] refactor craps, rps --- Craps/config.json | 2 +- Craps/craps.go | 29 +++----- Craps/craps.nef | Bin 628 -> 832 bytes Craps/craps.yml | 5 ++ Exchanger/config.json | 1 + Exchanger/exchanger.nef | Bin 0 -> 517 bytes {ZaCoinRefill => Exchanger}/go.mod | 0 {ZaCoinRefill => Exchanger}/go.sum | 0 Exchanger/main.go | 111 +++++++++++++++++++++++++++++ Exchanger/neo-go.yml | 16 +++++ RPS/config.json | 2 +- RPS/rps.go | 86 ++++++++-------------- RPS/rps.nef | Bin 1004 -> 830 bytes RPS/rps.yml | 9 ++- Roulette/Roulette.go | 31 +++----- Roulette/config.json | 3 +- Roulette/roulette.nef | Bin 786 -> 794 bytes Roulette/roulette.yml | 7 +- SlotMashine/config.json | 3 +- SlotMashine/config.yml | 5 ++ SlotMashine/slot.go | 31 +++----- SlotMashine/slot.nef | Bin 645 -> 778 bytes ZaCoinRefill/config.json | 1 - ZaCoinRefill/exchanger.nef | Bin 718 -> 0 bytes ZaCoinRefill/zaCoinRefill.go | 68 ------------------ ZaCoinRefill/zaCoinRefill.nef | Bin 536 -> 0 bytes ZaCoinRefill/zaCoinRefill.yml | 11 --- 27 files changed, 216 insertions(+), 205 deletions(-) create mode 100755 Exchanger/config.json create mode 100755 Exchanger/exchanger.nef rename {ZaCoinRefill => Exchanger}/go.mod (100%) rename {ZaCoinRefill => Exchanger}/go.sum (100%) create mode 100644 Exchanger/main.go create mode 100644 Exchanger/neo-go.yml delete mode 100755 ZaCoinRefill/config.json delete mode 100755 ZaCoinRefill/exchanger.nef delete mode 100644 ZaCoinRefill/zaCoinRefill.go delete mode 100755 ZaCoinRefill/zaCoinRefill.nef delete mode 100644 ZaCoinRefill/zaCoinRefill.yml diff --git a/Craps/config.json b/Craps/config.json index bdb2011..760fef3 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":543,"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"}]},{"name":"playerBalance","parameters":[{"name":"int","type":"Integer"}]}]},"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":540,"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"}]},{"name":"gameResult","parameters":[{"name":"int","type":"Integer"}]},{"name":"playerBalance","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file diff --git a/Craps/craps.go b/Craps/craps.go index 85e6479..632a250 100644 --- a/Craps/craps.go +++ b/Craps/craps.go @@ -32,6 +32,7 @@ func _deploy(data interface{}, isUpdate bool) { func PlayCraps(bet int, firstSum int, secondSum int) { ctx := storage.GetContext() playerOwner := runtime.GetScriptContainer().Sender + playerContract := runtime.GetExecutingScriptHash() if bet <= 0 { panic("Invalid bet amount") @@ -43,11 +44,14 @@ func PlayCraps(bet int, firstSum int, secondSum int) { panic("Insufficient funds") } + isWin := isWinner(firstSum, secondSum) if (isWin){ - changePlayerBalance(ctx, playerOwner, bet) + changePlayerBalance(playerContract, playerOwner, bet) + runtime.Notify("gameResult", int(1)) } else { - changePlayerBalance(ctx, playerOwner, -bet) + changePlayerBalance(playerOwner, playerContract, bet) + runtime.Notify("gameResult", int(0)) } playerBalance = contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int) runtime.Notify("playerBalance", playerBalance) @@ -61,7 +65,6 @@ func isWinner(firstSum int, secondSum int) bool { sum := 0 for i:=0; i<2; i++ { crap := (runtime.GetRandom() % 6) + 1 - runtime.Log("Crup number " + string(i+1) + " Rundom number " + string(crap)) runtime.Notify("Crup number", i+1) runtime.Notify("Random number", crap) sum += crap @@ -81,23 +84,11 @@ func OnNEP17Payment(from interop.Hash160, amount int, data any) { } } -func changePlayerBalance(ctx storage.Context, playerOwner interop.Hash160, balanceChange int) { - zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160) - playerContract := runtime.GetExecutingScriptHash() +func changePlayerBalance(sender interop.Hash160, recipient interop.Hash160, balanceChange int) { + ctx := storage.GetContext() + zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160) - var from, to interop.Hash160 - var transferAmount int - if balanceChange > 0 { - from = playerContract - to = playerOwner - transferAmount = balanceChange - } else { - from = playerOwner - to = playerContract - transferAmount = -balanceChange - } - - transferred := contract.Call(zaCoinHash, "transfer", contract.All, from, to, transferAmount, nil).(bool) + transferred := contract.Call(zaCoinHash, "transfer", contract.All, sender, recipient, balanceChange, nil).(bool) if !transferred { panic("failed to transfer zaCoins") } diff --git a/Craps/craps.nef b/Craps/craps.nef index 8f5090dd62daae4bd4306261c6ea4ee7471c192d..b04d7ce22c110af7999790648709bad6177a3d12 100755 GIT binary patch delta 316 zcmeyua)51u7vqPC-ii9$%#O3arJpNs)D7e?5I$Gvc>CXqlA;O$9dRBZ&%Cn4oXix3 zq|_3H#N7PSyb`O)J&aQI#hHQ!O0#)5lM-_h^O95j(*$!v9FuCJgS>7ks<7NvEXk?R z18XlXO-sv6&P>fKQAjJzODVRhtO_vgV_;w?%TrU!%B%=Boyo|+ASigCoSla&Jux>m zD7CmWrzD>}z;P;Lexi~}W)@IQDNv07Pz?uEjW+dla}7`h7Y}bi zPGV(hkrTwt`CJg)8*fQ5PHtgTmanL+;tmlxP@KubQBstcSDcnwB%cj2XVt2rtjYdN KiYz^y1|I=SOly_^ delta 143 zcmX@W_Jw7F7o*BV??gRjX2;pz($5t*>IQNc2%jsgtO_uZDaumg&B&|>Hq~NeU{K-# zGG_;y$^qG%_cKZ{GP5&ROuQp$U*LHA--?n#?jr7Dfs!f#Bd*M%%HpaLCCYv8Qz{tqJ@VAJON2EbI%AnA#-Eq_6dZ!003fb#}9;tZU zG*Dr=ZQ$w<&csxy#_Ukxb<+_j;8>6$aL((73hOB)7FPiV5e*d{dC$DE#GK3&g^a}F z42AqOg{nm7{LDOs9A|$^KUbK^!v&G>04f6-672ZQUZTYzoP)_xH;}_X z_*_AT;}7*WJ*(6-c~k;&5-U@S6f%ny^72a*N-|OviW75F6%vcV?Bv9poYW#K$J_r_ zloV!UR&a-yGcXiotx}Wb5pzq-%t=jAD9KlV1%*O-VlhN*Nsc)qLvgm?fl?kGXgD~g zm82Hs1~^V-%umb!%9iB`9w=w$;f6|w7N-{FvqPkTA;Ao`vH+y8kVn}W>Ou8l1*md` p;STr1<~< literal 0 HcmV?d00001 diff --git a/ZaCoinRefill/go.mod b/Exchanger/go.mod similarity index 100% rename from ZaCoinRefill/go.mod rename to Exchanger/go.mod diff --git a/ZaCoinRefill/go.sum b/Exchanger/go.sum similarity index 100% rename from ZaCoinRefill/go.sum rename to Exchanger/go.sum diff --git a/Exchanger/main.go b/Exchanger/main.go new file mode 100644 index 0000000..a4ff4fb --- /dev/null +++ b/Exchanger/main.go @@ -0,0 +1,111 @@ +package Exchanger + +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" + "github.com/nspcc-dev/neo-go/pkg/interop/native/gas" + "github.com/nspcc-dev/neo-go/pkg/interop/lib/address" + //"github.com/nspcc-dev/neo-go/pkg/interop/util" +) + +const ( + zaCoinHashKey = "zaCoinHash" +) + +var walletAddress = address.ToHash160("NXbLSnHA8dNuMUPUSNNivx7XFucN1w5bRq") + +func _deploy(data interface{}, isUpdate bool) { + if isUpdate { + return + } + + 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 BuyZaCoin(count int, player interop.Hash160) { + + playerOwner := runtime.GetScriptContainer().Sender + + if !runtime.CheckWitness(playerOwner) { + panic("Player is not the same as the caller") + } + contractHash := runtime.GetExecutingScriptHash() + + + transferredGas := gas.Transfer(playerOwner, contractHash, count, nil) + + if !transferredGas { + panic("Failed to transfer gas") + } + + balanceAfter := gas.BalanceOf(runtime.GetExecutingScriptHash()) + runtime.Notify("balanceAfter", balanceAfter) + balanceUser := gas.BalanceOf(playerOwner) + runtime.Notify("balanceUser", balanceUser) + //balanceBefore := gas.BalanceOf(runtime.GetExecutingScriptHash()) + //gasTransfer(player, count) + //balanceAfter := gas.BalanceOf(runtime.GetExecutingScriptHash()) + + //changePlayerBalance(ctx, playerOwner, count) + //if (balanceBefore - balanceAfter == count) { + // changePlayerBalance(ctx, playerOwner, count) + //} else { + // util.Abort() + //} +} + +func OnNEP17Payment(from interop.Hash160, amount int, data any) { + contractHash := runtime.GetExecutingScriptHash() + balance := gas.BalanceOf(contractHash) + runtime.Log("Contract's balance changed and has "+ string(balance)+" gas") +} + +func gasTransfer(playerOwner interop.Hash160, gasCount int) { + if !runtime.CheckWitness(playerOwner) { + panic("Player is not the same as the caller") + } + contractHash := runtime.GetExecutingScriptHash() + + + transferredGas := gas.Transfer(playerOwner, contractHash, gasCount, nil) + + if !transferredGas { + panic("Failed to transfer gas") + } +} + + +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, "zacoin").(bool) + if !transferred { + panic("failed to transfer zaCoins") + } +} diff --git a/Exchanger/neo-go.yml b/Exchanger/neo-go.yml new file mode 100644 index 0000000..9946e3b --- /dev/null +++ b/Exchanger/neo-go.yml @@ -0,0 +1,16 @@ +name: Exchanger +supportedstandards: [] +events: + - name: "balanceAfter" + parameters: + - name: "int" + type: "Integer" + - name: "balanceUser" + parameters: + - name: "int" + type: "Integer" +permissions: + - methods: '*' + events: + - "balanceAfter" + - "balanceUser" diff --git a/RPS/config.json b/RPS/config.json index c744d05..a7533bc 100644 --- a/RPS/config.json +++ b/RPS/config.json @@ -1 +1 @@ -{"name":"rps","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":687,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"playRPS","offset":95,"parameters":[{"name":"playerChoice","type":"String"},{"name":"bet","type":"Integer"}],"returntype":"Void","safe":false}],"events":[{"name":"computerChoice","parameters":[{"name":"str","type":"String"}]},{"name":"playerBalance","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file +{"name":"rps","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":538,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"playRPS","offset":95,"parameters":[{"name":"playerChoice","type":"Integer"},{"name":"bet","type":"Integer"}],"returntype":"Void","safe":false}],"events":[{"name":"computerChoice","parameters":[{"name":"int","type":"Integer"}]},{"name":"gameResult","parameters":[{"name":"int","type":"Integer"}]},{"name":"playerBalance","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file diff --git a/RPS/rps.go b/RPS/rps.go index 44dc221..4726039 100644 --- a/RPS/rps.go +++ b/RPS/rps.go @@ -11,11 +11,6 @@ const ( zaCoinHashKey = "zaCoinHash" ) -type Result struct { - win bool - tie bool - lose bool -} func _deploy(data interface{}, isUpdate bool) { if isUpdate { @@ -34,10 +29,11 @@ func _deploy(data interface{}, isUpdate bool) { storage.Put(ctx, zaCoinHashKey, args.zaCoinHash) } -func PlayRPS(playerChoice string, bet int) { +func PlayRPS(playerChoice int, bet int) { ctx := storage.GetContext() playerOwner := runtime.GetScriptContainer().Sender + playerContract := runtime.GetExecutingScriptHash() if bet <= 0 { panic("Invalid bet amount") @@ -48,57 +44,49 @@ func PlayRPS(playerChoice string, bet int) { panic("Insufficient funds") } - if playerChoice != "rock" && playerChoice != "paper" && playerChoice != "scissors" { + if playerChoice <= 0 || playerChoice > 3 { panic("invalid player choice") } computerChoice := (runtime.GetRandom() % 3) + 1 + runtime.Notify("computerChoice", computerChoice) - var computerChoiceString string - switch computerChoice { - case 0: - computerChoiceString = "rock" - case 1: - computerChoiceString = "paper" - case 2: - computerChoiceString = "scissors" - } + result := isWinner(playerChoice, computerChoice) - runtime.Notify("computerChoice", computerChoiceString) - - result := isWinner(playerChoice, computerChoiceString) - - if result.tie { - runtime.Log("game tied: player chose " + playerChoice + ", computer chose " + computerChoiceString) - } else if result.win { - changePlayerBalance(ctx, playerOwner, bet) - } else { - runtime.Log("player lost: player chose " + playerChoice + ", computer chose " + computerChoiceString) + if result == 1 { + changePlayerBalance(playerContract, playerOwner, bet) + runtime.Notify("gameResult", result) + } else if result == 0 { + changePlayerBalance(playerOwner, playerContract, bet) + runtime.Notify("gameResult", result) + } else { + runtime.Log("game tied") + runtime.Notify("gameResult", result) } playerBalance = contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int) - runtime.Notify("playerBalance", playerBalance) + runtime.Notify("playerBalance", playerBalance) } -func isWinner(playerChoice, computerChoice string) Result { +func isWinner(playerChoice int, computerChoice int) int { if playerChoice == computerChoice { - return Result{tie: true} + return 2 } - if playerChoice == "rock" && computerChoice == "scissors" { - return Result{win: true} + if playerChoice == 1 && computerChoice == 3 { + return 1 } - if playerChoice == "scissors" && computerChoice == "paper" { - return Result{win: true} + if playerChoice == 3 && computerChoice == 2 { + return 1 } - if playerChoice == "paper" && computerChoice == "rock" { - return Result{win: true} + if playerChoice == 2 && computerChoice == 1 { + return 1 } - return Result{lose: true} + return 0 } func OnNEP17Payment(from interop.Hash160, amount int, data any) { @@ -111,24 +99,12 @@ func OnNEP17Payment(from interop.Hash160, amount int, data any) { } } -func changePlayerBalance(ctx storage.Context, playerOwner interop.Hash160, balanceChange int) { - zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160) - playerContract := runtime.GetExecutingScriptHash() +func changePlayerBalance(sender interop.Hash160, recipient interop.Hash160, balanceChange int) { + ctx := storage.GetContext() + zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160) - var from, to interop.Hash160 - var transferAmount int - if balanceChange > 0 { - from = playerContract - to = playerOwner - transferAmount = balanceChange - } else { - from = playerOwner - to = playerContract - transferAmount = -balanceChange - } - - transferred := contract.Call(zaCoinHash, "transfer", contract.All, from, to, transferAmount, nil).(bool) - if !transferred { - panic("failed to transfer zaCoins") - } + transferred := contract.Call(zaCoinHash, "transfer", contract.All, sender, recipient, balanceChange, nil).(bool) + if !transferred { + panic("failed to transfer zaCoins") + } } diff --git a/RPS/rps.nef b/RPS/rps.nef index 9773565ed074eb0a64073c8506ec2081e06582bf..c21168c0c6f43e97293f56742aebcc31a45f46ea 100644 GIT binary patch delta 399 zcmaFEzK?B!7t=eYi9QKpd`ynBzonlmaMTUtFc3ah=y?0zijty5@Xrq1&oUIM;I6w z$~p2m1hv$&GAn~keHj@TfV>0coIG6ViMgpksl}x^CHb5Ij#C-)6P3d9IRv!SGqZpy zm0>EmP*ie3RqF6?g7hntWTvJ#o`3E>4Qwhmidyb~da$uTx0myvI6j{T&GkSPyga-G zIf<32MNSYu=JP_VatLQ&s;Jar5pt*y)Z(ZV)?yKKs1OFSgupBzAWIO$5^xA-VTOcX z1`k(NqH}&`-eg|p_{o2ml;tZbtGGi%4isndaFi4!<`t)<7RhHr+^}j@QP$++%!({> H$6Fl%b~Am_ delta 586 zcmdnT_J)0e7tR~p(32xnlbsGP3G!O6iX zyx##DcGK0wDiIzB$#QalWjTtip`kckO}G*oR7moW@Sd(FR0#=GxD?O?;r)|SnTnX% znJXq2FiF}MINtuZqNI?!h`U&zq)NbuE3>GwxT-{nv$80&xN3GuR(1||h{%Dm3?7b> dqQt!7wA3Q`Jc!3utt!o(EXl0MazIjhA^`V9z##wt diff --git a/RPS/rps.yml b/RPS/rps.yml index 2da2783..4fc80fa 100644 --- a/RPS/rps.yml +++ b/RPS/rps.yml @@ -3,8 +3,12 @@ supportedstandards: [] events: - name: computerChoice parameters: - - name: str - type: String + - name: int + type: Integer + - name: gameResult + parameters: + - name: int + type: Integer - name: playerBalance parameters: - name: int @@ -14,3 +18,4 @@ permissions: events: - computerChoice - playerBalance + - gameResult diff --git a/Roulette/Roulette.go b/Roulette/Roulette.go index 9a46ef6..2191db7 100644 --- a/Roulette/Roulette.go +++ b/Roulette/Roulette.go @@ -31,6 +31,7 @@ func _deploy(data interface{}, isUpdate bool) { func PlayRoulette(bet int, selectedNumber int) { ctx := storage.GetContext() playerOwner := runtime.GetScriptContainer().Sender + playerContract := runtime.GetExecutingScriptHash() if bet <= 0 { panic("Invalid bet amount") @@ -48,9 +49,11 @@ func PlayRoulette(bet int, selectedNumber int) { isWin := isWinner(selectedNumber) if isWin { winAmount := calculateWinAmount(bet, selectedNumber) - changePlayerBalance(ctx, playerOwner, winAmount) + changePlayerBalance(zaCoinHash, playerContract, playerOwner, winAmount) + runtime.Notify("gameResult", int(1)) } else { - changePlayerBalance(ctx, playerOwner, -bet) + changePlayerBalance(zaCoinHash, playerOwner, playerContract, bet) + runtime.Notify("gameResult", int(0)) } playerBalance = contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int) runtime.Notify("playerBalance", playerBalance) @@ -87,24 +90,10 @@ func OnNEP17Payment(from interop.Hash160, amount int, data any) { } } -func changePlayerBalance(ctx storage.Context, playerOwner interop.Hash160, balanceChange int) { - zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160) - playerContract := runtime.GetExecutingScriptHash() +func changePlayerBalance(zaCoinHash interop.Hash160, sender interop.Hash160, recipient interop.Hash160, balanceChange int) { - var from, to interop.Hash160 - var transferAmount int - if balanceChange > 0 { - from = playerContract - to = playerOwner - transferAmount = balanceChange - } else { - from = playerOwner - to = playerContract - transferAmount = -balanceChange - } - - transferred := contract.Call(zaCoinHash, "transfer", contract.All, from, to, transferAmount, nil).(bool) - if !transferred { - panic("failed to transfer zaCoins") - } + transferred := contract.Call(zaCoinHash, "transfer", contract.All, sender, recipient, balanceChange, nil).(bool) + if !transferred { + panic("failed to transfer zaCoins") + } } diff --git a/Roulette/config.json b/Roulette/config.json index 2eac8fe..4bb5e69 100644 --- a/Roulette/config.json +++ b/Roulette/config.json @@ -1,2 +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":473,"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"}]},{"name":"playerBalance","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} - +{"name":"Roulette","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":535,"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"}]},{"name":"gameResult","parameters":[{"name":"int","type":"Integer"}]},{"name":"playerBalance","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file diff --git a/Roulette/roulette.nef b/Roulette/roulette.nef index c411147c11e3001cffe60dc305263b52356bd26f..fa72544260964a9f34dfbbb39ce6d4a72c2f4fd0 100755 GIT binary patch delta 307 zcmbQlHj8b77vrgk-pY)b6Z37wc$ge#e@j1C;HVqOVIX|2(DC-a6(vOz_ZV9iX9^xD z&F0}uO3X>jOHTDq6U+^9Osb6z^17+0!g5=&B&R}8oJYtruedZVEi*YYHLpY=tu!yC zcybh@QN8JG1_p+*JT;?=$^g^bKz2EMc2;ISdx&WiBLjn=;DK@u97n;+gfl9b}cnfk8D^rV{ zAU??FhG?I>gYlLk6H8@PHFt=}fx-$Nj*_CpyyCRfBKb^+F{@S;WK4d`q{x!1>+l%> DEF)(J delta 278 zcmbQmHi>P57vrIc-pY)g6Z35a*qIz>e@j1C;HVqOVIX|2aN;53?4nG;10`8JoJol} ziFwJX{%L|aA&yD4(Lr7}6;)VnD;8&0=y~!ed*&6Frln;jXQt+rD5RCd@%s;YlhjQGgn#(47qvpRC7dq+_C6nyV(q!x5QZs!*Pp zr)X7C8DNrHmXVnkZ2F3UfkBBUBeP<5u<1P@d-5;FTg>dt6_azBB<%|vZ~t3SQpjDz zT`W*iC1AvrSyWkERieaMS(I5^HM=A$JBK?&%#4D>-mF7 0 { - from = playerContract - to = playerOwner - transferAmount = balanceChange - } else { - from = playerOwner - to = playerContract - transferAmount = -balanceChange - } - - transferred := contract.Call(zaCoinHash, "transfer", contract.All, from, to, transferAmount, nil).(bool) - if !transferred { - panic("failed to transfer zaCoins") - } + transferred := contract.Call(zaCoinHash, "transfer", contract.All, sender, recipient, balanceChange, nil).(bool) + if !transferred { + panic("failed to transfer zaCoins") + } } diff --git a/SlotMashine/slot.nef b/SlotMashine/slot.nef index e8c8c38308688b7333f6afc16c19351652d53716..76a4c1fc9ba5ba35e898cc2084279f132bd0e016 100755 GIT binary patch delta 468 zcmZo=?P8nY#kgytw=$#W#C%(Q9!AI6-_p+&IO+y+7zm#$biDm&;x5PE=^0zOwLTrD^W-*%}Xh^GM&M|z)+Sauvtw#J2R^y#I%Kxfk8mn6D(6CR zQ$81(qkt;7d3XzQ5-U@SoFGom=Z5HZ2xnp7E)Xcp6yB=l=a_wOrG~^J!Ffd)UN_WO zTn~9=oiE_w3C~DP&G9SEO^Qk_vdt8n=XFy9=vj?!9u6G^U^tbg+IDBb#2n8*cb}Fy zr%-8QhTwr>9`nRjUdzCMPf{vP|=DnhgNSg`fif delta 335 zcmeBTYh|6_#b`RwTbVI)V!mxX3!~%gZ|Ua>9CZUZ41~`WnkW@z32av5%gC&l9c*gN z$iSe)pH;D-I3qJV*i;9|bqMEVaLm59QbS^q;JgAs!2^Xn+~pamsX2b7xk;%-nE{Sd z8S@h}1P>JPu$Cp}l%{4uMBsXgg#-_j!1N@8HRV8*WD6cBg=)%0(^Mubc%YmerVFeo zpBd>a-b}Ohoht@F|Rl+wMafM#4)Kh UI%w6Z(%i{UnG{)Uk6p+B0KEcnwg3PC diff --git a/ZaCoinRefill/config.json b/ZaCoinRefill/config.json deleted file mode 100755 index 5ab9704..0000000 --- a/ZaCoinRefill/config.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"Exchanger","abi":{"methods":[{"name":"_deploy","offset":0,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"getZaCoin","offset":95,"parameters":[],"returntype":"Void","safe":false},{"name":"onNEP17Payment","offset":244,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false}],"events":[{"name":"playerBalance","parameters":[{"name":"int","type":"Integer"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"extra":null} \ No newline at end of file diff --git a/ZaCoinRefill/exchanger.nef b/ZaCoinRefill/exchanger.nef deleted file mode 100755 index 8d32c2cfcb674f2fcc6d04dbd04f8184b731cd60..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 718 zcmeZsbu-RO&DTxO*EP^HG%(gPWFP}Do-cdUeSuBK%f0V$Xdu~-ZQT(F()%cAtSLkLm@v+p(@ciKQm7uIX@3* zS8|D!=2TJ0 zxuGJNbwfoo$LppB&>tFEPUN0h+qp)u<>5GH&mQ)$g61OLhZt?0No*yJR)F+xH|@;xC9gvj<^4(~O*_kVl105xx3cyAcau;zI3zSp| z7;$A5RTfv3C~;O6WfoV>F3HNyfdzVq$bqs99(cl$&kJ!(s*Mg>wW>6Cm6|+{R2ruJ NkeCL#!Qd&AH2`nJ>E8eV diff --git a/ZaCoinRefill/zaCoinRefill.go b/ZaCoinRefill/zaCoinRefill.go deleted file mode 100644 index 56c0eda..0000000 --- a/ZaCoinRefill/zaCoinRefill.go +++ /dev/null @@ -1,68 +0,0 @@ -package Exchanger - -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" - minZaCoin = 5 - zaCoinForTransfer = 50 -) - - -func _deploy(data interface{}, isUpdate bool) { - if isUpdate { - return - } - - 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 GetZaCoin() { - ctx := storage.GetContext() - playerOwner := runtime.GetScriptContainer().Sender - - zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160) - playerBalance := contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int) - if playerBalance < minZaCoin { - changePlayerBalance(ctx, playerOwner, zaCoinForTransfer) - } - - playerBalance = contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner).(int) - runtime.Notify("playerBalance", playerBalance) - -} - -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, transferAmount int) { - zaCoinHash := storage.Get(ctx, zaCoinHashKey).(interop.Hash160) - playerContract := runtime.GetExecutingScriptHash() - - transferred := contract.Call(zaCoinHash, "transfer", contract.All, playerContract, playerOwner, transferAmount, nil).(bool) - if !transferred { - panic("failed to transfer zaCoins") - } -} diff --git a/ZaCoinRefill/zaCoinRefill.nef b/ZaCoinRefill/zaCoinRefill.nef deleted file mode 100755 index 8a516effd0f84c5fafd33d11bb9b952d2ff487dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 536 zcmeZsbu-RO&DTxO*EP^HG%(gPWFQaxJ;4~x#8j!q>`>u#(@}-xwqrqtz&WoQDy*lJ zSX>1dL^M=*5OFvhb$-@Pa z@Bk_U8WQaI%wD3!A)K87EMMTL8^~cGe6BD9SzUnRq}UgRUN;SZRvQ#$3LYrQ;^9n6 z%t_2kPW4X{%n5N!s*Mivx~T}1S1isJ)#J&?WH1Ug-2n71P<1Ja>RdF{f(OcYcnfk8 zD^rV{AV%f|I8J5EPjm=pVTL#gw_^$&ErauHin5BcZ>X_l-cVxZR8h#jp(2@iLq#;( z>!t?KK^mD*dOA>6iJ4=Sngow