fix: changes in exch
This commit is contained in:
parent
9044ca51a9
commit
ec2b55b383
1 changed files with 13 additions and 7 deletions
|
@ -21,15 +21,14 @@ func _deploy(data interface{}, isUpdate bool) {
|
|||
})
|
||||
|
||||
if len(args.zaCoinHash) != interop.Hash160Len {
|
||||
panic("invalid hash of zaCoin contract")
|
||||
}
|
||||
|
||||
panic("invalid hash of zaCoin contract")
|
||||
}
|
||||
|
||||
ctx := storage.GetContext()
|
||||
storage.Put(ctx, zaCoinHashKey, args.zaCoinHash)
|
||||
}
|
||||
|
||||
func BuyZaCoin(gasCount int){
|
||||
func BuyZaCoin(gasCount int) bool {
|
||||
playerOwner := runtime.GetScriptContainer().Sender
|
||||
|
||||
playerBalance := gas.BalanceOf(playerOwner)
|
||||
|
@ -40,12 +39,19 @@ func BuyZaCoin(gasCount int){
|
|||
|
||||
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)
|
||||
panic("failed to transfer gas")
|
||||
}
|
||||
resultAmountZaCoin := gasCount * 57
|
||||
transferredZaCoin := contract.Call(zaCoinHash, "transfer", contract.All, contractHash, playerBalance, resultAmountZaCoin, nil).(bool)
|
||||
|
||||
if !transferredZaCoin {
|
||||
panic("failed to transfer zaCoins")
|
||||
} else {
|
||||
runtime.Log("Gas balance: ", gas.BalanceOf(playerOwner))
|
||||
runtime.Log("ZaCoin balance: ", contract.Call(zaCoinHash, "balanceOf", contract.ReadStates, playerOwner))
|
||||
}
|
||||
|
||||
return transferredZaCoin
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue