From 79e92d5e1494715a080e5805ad35d51234b97b42 Mon Sep 17 00:00:00 2001 From: BlockChainDev Date: Sat, 16 Mar 2019 22:08:35 +0000 Subject: [PATCH] Add THROWIFNOT Opcode --- pkg/vm/vm_ops_exceptions.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 pkg/vm/vm_ops_exceptions.go diff --git a/pkg/vm/vm_ops_exceptions.go b/pkg/vm/vm_ops_exceptions.go new file mode 100644 index 000000000..bdf45dbfa --- /dev/null +++ b/pkg/vm/vm_ops_exceptions.go @@ -0,0 +1,33 @@ +package vm + +import ( + "errors" + + "github.com/CityOfZion/neo-go/pkg/vm/stack" +) + +// vm exceptions + +// THROWIFNOT faults if the item on the top of the stack +// does not evaluate to true +// For specific logic on how a number of bytearray is evaluated can be seen +// from the boolean conversion methods on the stack items +func THROWIFNOT(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation) (Vmstate, error) { + + // Pop item from top of stack + item, err := ctx.Estack.Pop() + if err != nil { + return FAULT, err + } + // Convert to a boolean + ok, err := item.Boolean() + if err != nil { + return FAULT, err + } + + // If false, throw + if !ok.Value() { + return FAULT, errors.New("Item on top of stack evaluates to false") + } + return NONE, nil +}