vm: convert items to UTF-8 strings

Add `stackitem.ToString` for seamless string conversion.
This commit is contained in:
Evgenii Stratonikov 2020-07-29 11:18:51 +03:00
parent 82692d8d21
commit f40aba4cd0
9 changed files with 41 additions and 26 deletions

View file

@ -96,6 +96,16 @@ func (e *Element) Bytes() []byte {
return bs
}
// String attempts to get string from the element value.
// It is assumed to be use in interops and panics if string is not a valid UTF-8 byte sequence.
func (e *Element) String() string {
s, err := stackitem.ToString(e.value)
if err != nil {
panic(err)
}
return s
}
// Array attempts to get the underlying value of the element as an array of
// other items. Will panic if the item type is different which will be caught
// by the VM.