forked from TrueCloudLab/frostfs-contract
Update "Deposit" method
Deposit method now takes script hashes instead of public keys and uses native gas token.
This commit is contained in:
parent
62ba54e88e
commit
ca54f71d30
1 changed files with 15 additions and 13 deletions
|
@ -27,10 +27,9 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// GAS NEP-5 HASH
|
tokenHash = "\x3b\x7d\x37\x11\xc6\xf0\xcc\xf9\xb1\xdc\xa9\x03\xd1\xbf\xa1\xd8\x96\xf1\x23\x8c"
|
||||||
tokenHash = "\x77\xea\x59\x6b\x7a\xdf\x7e\x4d\xd1\x40\x76\x97\x31\xb7\xd2\xf0\xe0\x6b\xcd\x9b"
|
|
||||||
innerRingCandidateFee = 100 * 1000 * 1000 // 10^8
|
innerRingCandidateFee = 100 * 1000 * 1000 // 10^8
|
||||||
version = 1
|
version = 2
|
||||||
voteKey = "ballots"
|
voteKey = "ballots"
|
||||||
blockDiff = 20 // change base on performance evaluation
|
blockDiff = 20 // change base on performance evaluation
|
||||||
)
|
)
|
||||||
|
@ -131,9 +130,13 @@ func Main(op string, args []interface{}) interface{} {
|
||||||
|
|
||||||
return true
|
return true
|
||||||
case "Deposit":
|
case "Deposit":
|
||||||
pk := args[0].([]byte)
|
if len(args) < 2 || len(args) > 3 {
|
||||||
if !runtime.CheckWitness(pk) {
|
panic("deposit: bad arguments")
|
||||||
panic("you should be the owner of the public key")
|
}
|
||||||
|
|
||||||
|
from := args[0].([]byte)
|
||||||
|
if !runtime.CheckWitness(from) {
|
||||||
|
panic("deposit: you should be the owner of the wallet")
|
||||||
}
|
}
|
||||||
|
|
||||||
amount := args[1].(int)
|
amount := args[1].(int)
|
||||||
|
@ -141,24 +144,23 @@ func Main(op string, args []interface{}) interface{} {
|
||||||
amount = amount * 100000000
|
amount = amount * 100000000
|
||||||
}
|
}
|
||||||
|
|
||||||
from := pubToScriptHash(pk)
|
|
||||||
to := runtime.GetExecutingScriptHash()
|
to := runtime.GetExecutingScriptHash()
|
||||||
params := []interface{}{from, to, amount}
|
params := []interface{}{from, to, amount}
|
||||||
|
|
||||||
transferred := engine.AppCall([]byte(tokenHash), "transfer", params).(bool)
|
transferred := engine.AppCall([]byte(tokenHash), "transfer", params).(bool)
|
||||||
if !transferred {
|
if !transferred {
|
||||||
panic("failed to transfer funds, aborting")
|
panic("deposit: failed to transfer funds, aborting")
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.Log("funds have been transferred")
|
runtime.Log("deposit: funds have been transferred")
|
||||||
|
|
||||||
var rcv = []byte{}
|
var rcv = from
|
||||||
if len(args) == 3 {
|
if len(args) == 3 {
|
||||||
rcv = args[2].([]byte) // todo: check if rcv value is valid
|
rcv = args[2].([]byte) // todo: check if rcv value is valid
|
||||||
}
|
}
|
||||||
|
|
||||||
txHash := runtime.GetScriptContainer().Hash
|
tx := runtime.GetScriptContainer()
|
||||||
|
runtime.Notify("Deposit", from, amount, rcv, tx.Hash)
|
||||||
runtime.Notify("Deposit", pk, amount, rcv, txHash)
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
case "Withdraw":
|
case "Withdraw":
|
||||||
|
|
Loading…
Reference in a new issue