vm: implement * -> ByteArray conversion

This commit is contained in:
Evgenii Stratonikov 2019-09-10 14:38:25 +03:00
parent 9b10b4c4d8
commit 7e14c5a274

View file

@ -86,7 +86,19 @@ func (e *Element) Bool() bool {
// Bytes attempts to get the underlying value of the element as a byte array.
// Will panic if the assertion failed which will be caught by the VM.
func (e *Element) Bytes() []byte {
return e.value.Value().([]byte)
switch t := e.value.(type) {
case *ByteArrayItem:
return t.value
case *BigIntegerItem:
return util.ArrayReverse(t.value.Bytes()) // neoVM returns in LE
case *BoolItem:
if t.value {
return []byte{1}
}
return []byte{0}
default:
panic("can't convert to []byte: " + t.String())
}
}
// Array attempts to get the underlying value of the element as an array of