forked from TrueCloudLab/neoneo-go
remove error on NewBoolean
Expose underlying with Getter on Boolean StackItem Add Equals method for ByteArray
This commit is contained in:
parent
80fd427517
commit
48413900ca
3 changed files with 19 additions and 4 deletions
|
@ -85,7 +85,7 @@ func (i *Int) ByteArray() (*ByteArray, error) {
|
||||||
// to convert an Integer into a Boolean StackItem
|
// to convert an Integer into a Boolean StackItem
|
||||||
func (i *Int) Boolean() (*Boolean, error) {
|
func (i *Int) Boolean() (*Boolean, error) {
|
||||||
boolean := (i.val.Int64() != 0)
|
boolean := (i.val.Int64() != 0)
|
||||||
return NewBoolean(boolean)
|
return NewBoolean(boolean), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Value returns the underlying big.Int
|
//Value returns the underlying big.Int
|
||||||
|
|
|
@ -7,11 +7,11 @@ type Boolean struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewBoolean returns a new boolean stack item
|
//NewBoolean returns a new boolean stack item
|
||||||
func NewBoolean(val bool) (*Boolean, error) {
|
func NewBoolean(val bool) *Boolean {
|
||||||
return &Boolean{
|
return &Boolean{
|
||||||
&abstractItem{},
|
&abstractItem{},
|
||||||
val,
|
val,
|
||||||
}, nil
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Boolean overrides the default implementation
|
// Boolean overrides the default implementation
|
||||||
|
@ -19,3 +19,8 @@ func NewBoolean(val bool) (*Boolean, error) {
|
||||||
func (b *Boolean) Boolean() (*Boolean, error) {
|
func (b *Boolean) Boolean() (*Boolean, error) {
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Value returns the underlying boolean value
|
||||||
|
func (b *Boolean) Value() bool {
|
||||||
|
return b.val
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package stack
|
package stack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -26,6 +27,15 @@ func (ba *ByteArray) ByteArray() (*ByteArray, error) {
|
||||||
return ba, nil
|
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
|
//Integer overrides the default Integer method to convert an
|
||||||
// ByteArray Into an integer
|
// ByteArray Into an integer
|
||||||
func (ba *ByteArray) Integer() (*Int, error) {
|
func (ba *ByteArray) Integer() (*Int, error) {
|
||||||
|
@ -41,7 +51,7 @@ func (ba *ByteArray) Boolean() (*Boolean, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("cannot convert byte array to a boolean")
|
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
|
// XXX: move this into a pkg/util/slice folder
|
||||||
|
|
Loading…
Reference in a new issue