diff --git a/pkg/vm/stack/Int.go b/pkg/vm/stack/Int.go index 2483a78ea..ac9a4cdba 100644 --- a/pkg/vm/stack/Int.go +++ b/pkg/vm/stack/Int.go @@ -85,7 +85,7 @@ func (i *Int) ByteArray() (*ByteArray, error) { // to convert an Integer into a Boolean StackItem func (i *Int) Boolean() (*Boolean, error) { boolean := (i.val.Int64() != 0) - return NewBoolean(boolean) + return NewBoolean(boolean), nil } //Value returns the underlying big.Int diff --git a/pkg/vm/stack/boolean.go b/pkg/vm/stack/boolean.go index 2441a303c..66e3647e5 100644 --- a/pkg/vm/stack/boolean.go +++ b/pkg/vm/stack/boolean.go @@ -7,11 +7,11 @@ type Boolean struct { } //NewBoolean returns a new boolean stack item -func NewBoolean(val bool) (*Boolean, error) { +func NewBoolean(val bool) *Boolean { return &Boolean{ &abstractItem{}, val, - }, nil + } } // Boolean overrides the default implementation @@ -19,3 +19,8 @@ func NewBoolean(val bool) (*Boolean, error) { func (b *Boolean) Boolean() (*Boolean, error) { return b, nil } + +// Value returns the underlying boolean value +func (b *Boolean) Value() bool { + return b.val +} diff --git a/pkg/vm/stack/bytearray.go b/pkg/vm/stack/bytearray.go index 6b1de0d79..7d1c3c818 100644 --- a/pkg/vm/stack/bytearray.go +++ b/pkg/vm/stack/bytearray.go @@ -1,6 +1,7 @@ package stack import ( + "bytes" "errors" "math/big" "strconv" @@ -26,6 +27,15 @@ func (ba *ByteArray) ByteArray() (*ByteArray, error) { return ba, nil } +//Equals returns true, if two bytearrays are equal +func (ba *ByteArray) Equals(other *ByteArray) *Boolean { + // If either are nil, return false + if ba == nil || other == nil { + return NewBoolean(false) + } + return NewBoolean(bytes.Equal(ba.val, other.val)) +} + //Integer overrides the default Integer method to convert an // ByteArray Into an integer func (ba *ByteArray) Integer() (*Int, error) { @@ -41,7 +51,7 @@ func (ba *ByteArray) Boolean() (*Boolean, error) { if err != nil { return nil, errors.New("cannot convert byte array to a boolean") } - return NewBoolean(boolean) + return NewBoolean(boolean), nil } // XXX: move this into a pkg/util/slice folder