[#184] *: Change panic to Log+ABORT in OnNEP17Payment

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-11-30 12:44:05 +03:00 committed by Alex Vanin
parent e6a33e8193
commit a2f5f7a74a
5 changed files with 19 additions and 7 deletions

View file

@ -28,7 +28,7 @@ const (
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
caller := runtime.GetCallingScriptHash()
if !common.BytesEqual(caller, []byte(gas.Hash)) && !common.BytesEqual(caller, []byte(neo.Hash)) {
panic("alphabet contract accepts GAS and NEO only")
common.AbortWithMessage("alphabet contract accepts GAS and NEO only")
}
}

View file

@ -1,5 +1,10 @@
package common
import (
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/util"
)
var (
mintPrefix = []byte{0x01}
burnPrefix = []byte{0x02}
@ -33,3 +38,10 @@ func UnlockTransferDetails(epoch int) []byte {
func ContainerFeeTransferDetails(cid []byte) []byte {
return append(containerFeePrefix, cid...)
}
// AbortWithMessage calls `runtime.Log` with passed message
// and calls `ABORT` opcode.
func AbortWithMessage(msg string) {
runtime.Log(msg)
util.Abort()
}

View file

@ -244,14 +244,14 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
}
if amount <= 0 {
panic("amount must be positive")
common.AbortWithMessage("amount must be positive")
} else if maxBalanceAmountGAS < amount {
panic("out of max amount limit")
common.AbortWithMessage("out of max amount limit")
}
caller := runtime.GetCallingScriptHash()
if !common.BytesEqual(caller, interop.Hash160(gas.Hash)) {
panic("only GAS can be accepted for deposit")
common.AbortWithMessage("only GAS can be accepted for deposit")
}
switch len(rcv) {
@ -259,7 +259,7 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
case 0:
rcv = from
default:
panic("invalid data argument, expected Hash160")
common.AbortWithMessage("invalid data argument, expected Hash160")
}
runtime.Log("funds have been transferred")

View file

@ -22,7 +22,7 @@ const (
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
caller := runtime.GetCallingScriptHash()
if !common.BytesEqual(caller, []byte(gas.Hash)) {
panic("processing contract accepts GAS only")
common.AbortWithMessage("processing contract accepts GAS only")
}
}

View file

@ -19,7 +19,7 @@ const (
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
caller := runtime.GetCallingScriptHash()
if !common.BytesEqual(caller, []byte(gas.Hash)) {
panic("proxy contract accepts GAS only")
common.AbortWithMessage("proxy contract accepts GAS only")
}
}