2019-09-03 15:00:10 +00:00
|
|
|
package runtimecontract
|
2018-08-21 08:55:03 +00:00
|
|
|
|
|
|
|
import (
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/util"
|
2018-08-21 08:55:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Check if the invoker of the contract is the specified owner
|
2020-06-16 10:47:29 +00:00
|
|
|
var owner = util.FromAddress("Nis7Cu1Qn6iBb8kbeQ5HgdZT7AsQPqywTC")
|
2018-08-21 08:55:03 +00:00
|
|
|
|
2019-09-03 14:51:37 +00:00
|
|
|
// Main is something to be ran from outside.
|
2018-08-21 08:55:03 +00:00
|
|
|
func Main(operation string, args []interface{}) bool {
|
|
|
|
trigger := runtime.GetTrigger()
|
|
|
|
|
|
|
|
// Log owner upon Verification trigger
|
|
|
|
if trigger == runtime.Verification() {
|
2020-07-03 11:53:29 +00:00
|
|
|
return CheckWitness()
|
2018-08-21 08:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Discerns between log and notify for this test
|
|
|
|
if trigger == runtime.Application() {
|
|
|
|
return handleOperation(operation, args)
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleOperation(operation string, args []interface{}) bool {
|
|
|
|
if operation == "log" {
|
2020-07-03 11:53:29 +00:00
|
|
|
return Log(args)
|
2018-08-21 08:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if operation == "notify" {
|
2020-07-03 11:53:29 +00:00
|
|
|
return Notify(args)
|
2018-08-21 08:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
2020-07-03 11:53:29 +00:00
|
|
|
|
|
|
|
// CheckWitness checks owner's witness
|
|
|
|
func CheckWitness() bool {
|
|
|
|
if runtime.CheckWitness(owner) {
|
|
|
|
runtime.Log("Verified Owner")
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Log logs given message
|
|
|
|
func Log(args []interface{}) bool {
|
|
|
|
message := args[0].(string)
|
|
|
|
runtime.Log(message)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify notifies about given message
|
|
|
|
func Notify(args []interface{}) bool {
|
2020-06-29 08:25:32 +00:00
|
|
|
runtime.Notify("Event", args[0])
|
2020-07-03 11:53:29 +00:00
|
|
|
return true
|
|
|
|
}
|