2021-11-29 12:21:40 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import "github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
|
|
|
|
|
|
|
var (
|
2022-04-14 11:56:51 +00:00
|
|
|
// ErrAlphabetWitnessFailed appears when the method must be
|
|
|
|
// called by the Alphabet but was not.
|
2021-11-29 12:21:40 +00:00
|
|
|
ErrAlphabetWitnessFailed = "alphabet witness check failed"
|
2022-04-14 11:56:51 +00:00
|
|
|
// ErrOwnerWitnessFailed appears when the method must be called
|
|
|
|
// by an owner of some assets but was not.
|
2021-11-29 12:21:40 +00:00
|
|
|
ErrOwnerWitnessFailed = "owner witness check failed"
|
2022-04-14 11:56:51 +00:00
|
|
|
// ErrWitnessFailed appears when the method must be called
|
2021-11-29 12:21:40 +00:00
|
|
|
// using certain public key but was not.
|
|
|
|
ErrWitnessFailed = "witness check failed"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CheckAlphabetWitness checks witness of the passed caller.
|
2022-04-14 11:56:51 +00:00
|
|
|
// It panics with ErrAlphabetWitnessFailed message on fail.
|
2023-02-10 15:07:44 +00:00
|
|
|
func CheckAlphabetWitness() {
|
|
|
|
checkWitnessWithPanic(AlphabetAddress(), ErrAlphabetWitnessFailed)
|
2021-11-29 12:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CheckOwnerWitness checks witness of the passed caller.
|
2022-04-14 11:56:51 +00:00
|
|
|
// It panics with ErrOwnerWitnessFailed message on fail.
|
2021-11-29 12:21:40 +00:00
|
|
|
func CheckOwnerWitness(caller []byte) {
|
|
|
|
checkWitnessWithPanic(caller, ErrOwnerWitnessFailed)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CheckWitness checks witness of the passed caller.
|
2022-04-14 11:56:51 +00:00
|
|
|
// It panics with ErrWitnessFailed message on fail.
|
2021-11-29 12:21:40 +00:00
|
|
|
func CheckWitness(caller []byte) {
|
|
|
|
checkWitnessWithPanic(caller, ErrWitnessFailed)
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkWitnessWithPanic(caller []byte, panicMsg string) {
|
|
|
|
if !runtime.CheckWitness(caller) {
|
|
|
|
panic(panicMsg)
|
|
|
|
}
|
|
|
|
}
|