From 11bb733f1a2c56857891fd38f8b4b2da8c461220 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 20 Jul 2023 11:42:48 +0300 Subject: [PATCH] interop: support ABORTMSG, ASSERT, ASSERTMSG opcodes Signed-off-by: Anna Shaleva --- pkg/interop/neogointernal/opcode.go | 6 +++++- pkg/interop/util/util.go | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/interop/neogointernal/opcode.go b/pkg/interop/neogointernal/opcode.go index a64e85733..0b39138ed 100644 --- a/pkg/interop/neogointernal/opcode.go +++ b/pkg/interop/neogointernal/opcode.go @@ -9,12 +9,16 @@ func Opcode1(op string, arg any) any { return nil } +// Opcode1NoReturn emits opcode with 1 argument and no return value. +func Opcode1NoReturn(op string, arg any) { +} + // Opcode2 emits opcode with 2 arguments. func Opcode2(op string, arg1, arg2 any) any { return nil } -// Opcode2NoReturn emits opcode with 2 arguments. +// Opcode2NoReturn emits opcode with 2 arguments and no return value. func Opcode2NoReturn(op string, arg1, arg2 any) { } diff --git a/pkg/interop/util/util.go b/pkg/interop/util/util.go index 9e93ed6c3..b17eb0124 100644 --- a/pkg/interop/util/util.go +++ b/pkg/interop/util/util.go @@ -13,6 +13,25 @@ func Abort() { neogointernal.Opcode0NoReturn("ABORT") } +// AbortMsg terminates current execution with the specified message. Unlike +// exception throwing with panic() it can't be recovered from. +func AbortMsg(msg string) { + neogointernal.Opcode1NoReturn("ABORTMSG", msg) +} + +// Assert terminates current execution if the condition specified is false. Unlike +// exception throwing with panic() it can't be recovered from. +func Assert(ok bool) { + neogointernal.Opcode1NoReturn("ASSERT", ok) +} + +// AssertMsg terminates current execution with the specified message if the +// condition specified is false. Unlike exception throwing with panic() it can't +// be recovered from. +func AssertMsg(ok bool, msg string) { + neogointernal.Opcode2NoReturn("ASSERTMSG", ok, msg) +} + // Equals compares a with b and will return true when a and b are equal. It's // implemented as an EQUAL VM opcode, so the rules of comparison are those // of EQUAL.