2019-03-16 22:08:35 +00:00
|
|
|
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
|
2019-03-18 21:14:03 +00:00
|
|
|
func THROWIFNOT(op stack.Instruction, ctx *stack.Context, istack *stack.Invocation, rstack *stack.RandomAccess) (Vmstate, error) {
|
2019-03-16 22:08:35 +00:00
|
|
|
|
|
|
|
// 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() {
|
2019-03-18 21:14:03 +00:00
|
|
|
return FAULT, errors.New("item on top of stack evaluates to false")
|
2019-03-16 22:08:35 +00:00
|
|
|
}
|
|
|
|
return NONE, nil
|
|
|
|
}
|