[#7] Allow to get bytes from buffer stackitem

Smart-contract can return slice of bytes as buffer type.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-09-02 19:24:46 +03:00
parent 5e5e431534
commit 2ab855b2ec

View file

@ -159,15 +159,17 @@ func IntFromStackItem(param stackitem.Item) (int64, error) {
// BytesFromStackItem receives binary value from the value of a smart contract parameter. // BytesFromStackItem receives binary value from the value of a smart contract parameter.
func BytesFromStackItem(param stackitem.Item) ([]byte, error) { func BytesFromStackItem(param stackitem.Item) ([]byte, error) {
if param.Type() != stackitem.ByteArrayT { switch param.Type() {
if param.Type() == stackitem.AnyT && param.Value() == nil { case stackitem.BufferT, stackitem.ByteArrayT:
return param.TryBytes()
case stackitem.AnyT:
if param.Value() == nil {
return nil, nil return nil, nil
} }
fallthrough
default:
return nil, errors.Errorf("chain/client: %s is not a byte array type", param.Type()) return nil, errors.Errorf("chain/client: %s is not a byte array type", param.Type())
} }
return param.TryBytes()
} }
// ArrayFromStackItem returns the slice contract parameters from passed parameter. // ArrayFromStackItem returns the slice contract parameters from passed parameter.