2019-09-03 15:00:10 +00:00
|
|
|
package runtimecontract
|
2018-08-21 08:55:03 +00:00
|
|
|
|
|
|
|
import (
|
2022-03-24 13:44:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
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
|
|
|
)
|
|
|
|
|
2020-08-10 10:42:02 +00:00
|
|
|
var (
|
|
|
|
// Check if the invoker of the contract is the specified owner
|
2022-03-24 13:44:15 +00:00
|
|
|
owner = util.FromAddress("NbrUYaZgyhSkNoRo9ugRyEMdUZxrhkNaWB")
|
2020-08-10 10:42:02 +00:00
|
|
|
)
|
2018-08-21 08:55:03 +00:00
|
|
|
|
2022-03-24 13:44:15 +00:00
|
|
|
// init is transformed into _initialize method that is called whenever contract
|
|
|
|
// is being loaded (so you'll see this log entry with every invocation).
|
2020-08-10 10:42:02 +00:00
|
|
|
func init() {
|
2022-03-24 13:44:15 +00:00
|
|
|
// No events and logging allowed in verification context.
|
|
|
|
if runtime.GetTrigger() != runtime.Verification {
|
|
|
|
runtime.Log("init called")
|
|
|
|
}
|
2018-08-21 08:55:03 +00:00
|
|
|
}
|
2020-07-03 11:53:29 +00:00
|
|
|
|
2022-03-24 13:44:15 +00:00
|
|
|
// _deploy is called after contract deployment or update, it'll be called
|
|
|
|
// in deployment transaction and if call update method of this contract.
|
2021-01-28 13:31:50 +00:00
|
|
|
func _deploy(_ interface{}, isUpdate bool) {
|
2020-10-10 17:17:04 +00:00
|
|
|
if isUpdate {
|
2022-03-24 13:44:15 +00:00
|
|
|
Log("_deploy method called after contract update")
|
2020-10-10 17:17:04 +00:00
|
|
|
return
|
|
|
|
}
|
2022-03-24 13:44:15 +00:00
|
|
|
Log("_deploy method called after contract creation")
|
2020-10-10 17:17:04 +00:00
|
|
|
}
|
|
|
|
|
2022-03-24 13:44:15 +00:00
|
|
|
// CheckWitness checks owner's witness. It returns true if invoked by the owner
|
|
|
|
// and false otherwise.
|
2020-07-03 11:53:29 +00:00
|
|
|
func CheckWitness() bool {
|
|
|
|
if runtime.CheckWitness(owner) {
|
|
|
|
runtime.Log("Verified Owner")
|
2022-03-24 13:44:15 +00:00
|
|
|
return true
|
2020-07-03 11:53:29 +00:00
|
|
|
}
|
2022-03-24 13:44:15 +00:00
|
|
|
return false
|
2020-07-03 11:53:29 +00:00
|
|
|
}
|
|
|
|
|
2022-03-24 13:44:15 +00:00
|
|
|
// Log logs given message.
|
|
|
|
func Log(message string) {
|
2020-07-03 11:53:29 +00:00
|
|
|
runtime.Log(message)
|
|
|
|
}
|
|
|
|
|
2022-03-24 13:44:15 +00:00
|
|
|
// Notify emits an event with the specified data.
|
|
|
|
func Notify(event interface{}) {
|
|
|
|
runtime.Notify("Event", event)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify method is used when contract is being used as a signer of transaction,
|
|
|
|
// it can have parameters (that then need to be present in invocation script)
|
|
|
|
// and it returns simple pass/fail result. This implementation just checks for
|
|
|
|
// owner's signature presence.
|
|
|
|
func Verify() bool {
|
|
|
|
// Technically this restriction is not needed, but you can see the difference
|
|
|
|
// between invokefunction and invokecontractverify RPC methods with it.
|
|
|
|
if runtime.GetTrigger() != runtime.Verification {
|
2020-08-10 10:42:02 +00:00
|
|
|
return false
|
|
|
|
}
|
2022-03-24 13:44:15 +00:00
|
|
|
return CheckWitness()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy destroys the contract, only owner can do that.
|
|
|
|
func Destroy() {
|
|
|
|
if !Verify() {
|
|
|
|
panic("only owner can destroy")
|
|
|
|
}
|
|
|
|
management.Destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update updates the contract, only owner can do that. _deploy will be called
|
|
|
|
// after update.
|
|
|
|
func Update(nef, manifest []byte) {
|
|
|
|
if !Verify() {
|
|
|
|
panic("only owner can update")
|
|
|
|
}
|
|
|
|
management.Update(nef, manifest)
|
2020-07-03 11:53:29 +00:00
|
|
|
}
|