core: allow Null in System.Contract.Update

Null means absense of script or manifest, empty
byte-slice is an error.

Related #1459.
This commit is contained in:
Evgenii Stratonikov 2020-10-05 16:12:08 +03:00
parent 0e82d4cbd1
commit 0b76f875c7
3 changed files with 61 additions and 24 deletions

View file

@ -100,6 +100,19 @@ func (e *Element) Bytes() []byte {
return bs
}
// BytesOrNil attempts to get the underlying value of the element as a byte array or nil.
// Will panic if the assertion failed which will be caught by the VM.
func (e *Element) BytesOrNil() []byte {
if _, ok := e.value.(stackitem.Null); ok {
return nil
}
bs, err := e.value.TryBytes()
if err != nil {
panic(err)
}
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 {