mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-06 19:55:10 +00:00
vm: convert items to UTF-8 strings
Add `stackitem.ToString` for seamless string conversion.
This commit is contained in:
parent
82692d8d21
commit
f40aba4cd0
9 changed files with 41 additions and 26 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue