neoneo-go/examples/runtime/runtime.go

56 lines
1.1 KiB
Go
Raw Normal View History

package runtimecontract
import (
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/util"
)
2020-08-10 10:42:02 +00:00
var (
// Check if the invoker of the contract is the specified owner
2021-03-22 15:12:56 +00:00
owner = util.FromAddress("NX1yL5wDx3inK2qUVLRVaqCLUxYnAbv85S")
2020-08-10 10:42:02 +00:00
trigger byte
)
2020-08-10 10:42:02 +00:00
// init initializes trigger before any other contract method is called
func init() {
trigger = runtime.GetTrigger()
}
func _deploy(_ interface{}, isUpdate bool) {
if isUpdate {
Log("_deploy method called before contract update")
return
}
Log("_deploy method called before contract creation")
}
// CheckWitness checks owner's witness
func CheckWitness() bool {
2020-08-10 10:42:02 +00:00
// Log owner upon Verification trigger
if trigger != runtime.Verification {
return false
}
if runtime.CheckWitness(owner) {
runtime.Log("Verified Owner")
}
return true
}
// Log logs given message
2020-08-10 10:42:02 +00:00
func Log(message string) bool {
if trigger != runtime.Application {
return false
}
runtime.Log(message)
return true
}
// Notify notifies about given message
2020-08-10 10:42:02 +00:00
func Notify(event interface{}) bool {
if trigger != runtime.Application {
return false
}
runtime.Notify("Event", event)
return true
}