examples: add defer/recover to OnNEP17Payment handlers

Transaction must be ABORTed, exceptions are not sufficient.
This commit is contained in:
Roman Khimov 2022-03-23 11:58:07 +03:00
parent e557da70a4
commit a5979f6d64
2 changed files with 12 additions and 0 deletions

View file

@ -351,6 +351,12 @@ func removeOwner(ctx storage.Context, token []byte, holder interop.Hash160) {
// this method directly, instead it's called by GAS contract when you transfer
// GAS from your address to the address of this NFT contract.
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
defer func() {
if r := recover(); r != nil {
runtime.Log(r.(string))
util.Abort()
}
}()
if string(runtime.GetCallingScriptHash()) != gas.Hash {
panic("only GAS is accepted")
}

View file

@ -210,6 +210,12 @@ func postTransfer(from interop.Hash160, to interop.Hash160, token []byte, data i
// this method directly, instead it's called by GAS contract when you transfer
// GAS from your address to the address of this NFT contract.
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
defer func() {
if r := recover(); r != nil {
runtime.Log(r.(string))
util.Abort()
}
}()
if string(runtime.GetCallingScriptHash()) != gas.Hash {
panic("only GAS is accepted")
}