From e4c80a001c1f79acf9db7842f2403ee274144d38 Mon Sep 17 00:00:00 2001 From: Jeroen Peeters Date: Tue, 21 Aug 2018 10:55:03 +0200 Subject: [PATCH] feat: add Log, Notify and Triggers Imported from CityOfZion/neo-storm (5065465e39fd2b308c487f49f75f517620139660). --- examples/check_witness.go | 17 ------------ examples/runtime/runtime.go | 43 +++++++++++++++++++++++++++++++ examples/{ => storage}/storage.go | 0 interop/runtime/runtime.go | 26 ++++++++++++++++++- 4 files changed, 68 insertions(+), 18 deletions(-) delete mode 100644 examples/check_witness.go create mode 100644 examples/runtime/runtime.go rename examples/{ => storage}/storage.go (100%) diff --git a/examples/check_witness.go b/examples/check_witness.go deleted file mode 100644 index 17b399cc7..000000000 --- a/examples/check_witness.go +++ /dev/null @@ -1,17 +0,0 @@ -package check_witness_contract - -import ( - "github.com/CityOfZion/neo-go-sc/interop/runtime" - "github.com/CityOfZion/neo-go-sc/interop/util" -) - -// Check if the invoker of the contract is the specified owner. - -var owner = util.FromAddress("Aej1fe4mUgou48Zzup5j8sPrE3973cJ5oz") - -func Main() bool { - if runtime.CheckWitness(owner) { - return true - } - return false -} diff --git a/examples/runtime/runtime.go b/examples/runtime/runtime.go new file mode 100644 index 000000000..a436dbf9e --- /dev/null +++ b/examples/runtime/runtime.go @@ -0,0 +1,43 @@ +package runtime_contract + +import ( + "github.com/CityOfZion/neo-go-sc/interop/runtime" + "github.com/CityOfZion/neo-go-sc/interop/util" +) + +// Check if the invoker of the contract is the specified owner +var owner = util.FromAddress("Aej1fe4mUgou48Zzup5j8sPrE3973cJ5oz") + +func Main(operation string, args []interface{}) bool { + trigger := runtime.GetTrigger() + + // Log owner upon Verification trigger + if trigger == runtime.Verification() { + if runtime.CheckWitness(owner) { + runtime.Log("Verified Owner") + } + return true + } + + // 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" { + message := args[0].(string) + runtime.Log(message) + return true + } + + if operation == "notify" { + runtime.Notify(args[0]) + return true + } + + return false +} diff --git a/examples/storage.go b/examples/storage/storage.go similarity index 100% rename from examples/storage.go rename to examples/storage/storage.go diff --git a/interop/runtime/runtime.go b/interop/runtime/runtime.go index da0e82bcb..3d85288c4 100644 --- a/interop/runtime/runtime.go +++ b/interop/runtime/runtime.go @@ -1,6 +1,30 @@ package runtime -// CheckWitness verifies if the given hash is the invoker of the contract. +// CheckWitness verifies if the given hash is the invoker of the contract func CheckWitness(hash []byte) bool { return true } + +// Notify passes data to the VM +func Notify(arg interface{}) int { + return 0 +} + +// Log passes a message to the VM +func Log(message string) {} + +// Application returns the Application trigger type +func Application() byte { + return 0x10 +} + +// Verification returns the Verification trigger type +func Verification() byte { + return 0x00 +} + +// GetTrigger return the current trigger type. The return in this function +// Doesn't really matter, this is just an interop placeholder +func GetTrigger() interface{} { + return 0 +}