add exchanger

This commit is contained in:
shashkevichfrida 2024-01-07 17:43:07 +03:00
parent 6028952af5
commit 9044ca51a9
3 changed files with 61 additions and 0 deletions

51
Exchanger/exchanger.go Normal file
View file

@ -0,0 +1,51 @@
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"
)
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(gasCount int){
playerOwner := runtime.GetScriptContainer().Sender
playerBalance := gas.BalanceOf(playerOwner)
if playerBalance < gasCount {
panic("Insufficient funds")
}
contractHash := runtime.GetExecutingScriptHash()
transferredGas := gas.Transfer(playerOwner, contractHash, gasCount, nil).(bool)
if !transferredGas {
panic("failed to transfer gas")
}
transferredZaCoin := contract.Call(zaCoinHash, "transfer", contract.All, contractHash, playerBalance, gasCount, nil).(bool)
if !transferredZaCoin {
panic("failed to transfer zaCoins")
}
}

6
Exchanger/exchanger.yml Normal file
View file

@ -0,0 +1,6 @@
name: Exchanger
sourceurl: http://example.com/
safemethods: []
supportedstandards: []
permissions:
- methods: '*'

4
Exchanger/go.mod Normal file
View file

@ -0,0 +1,4 @@
module Exchanger
require (
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231020160724-c3955f87d1b5
)