From 2ab855b2ec93d1a920440baa5adb5747e120c7ea Mon Sep 17 00:00:00 2001
From: Alex Vanin <alexey@nspcc.ru>
Date: Wed, 2 Sep 2020 19:24:46 +0300
Subject: [PATCH] [#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>
---
 pkg/morph/client/util.go | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/pkg/morph/client/util.go b/pkg/morph/client/util.go
index ea6d600e5..36ca84f3b 100644
--- a/pkg/morph/client/util.go
+++ b/pkg/morph/client/util.go
@@ -159,15 +159,17 @@ func IntFromStackItem(param stackitem.Item) (int64, error) {
 
 // BytesFromStackItem receives binary value from the value of a smart contract parameter.
 func BytesFromStackItem(param stackitem.Item) ([]byte, error) {
-	if param.Type() != stackitem.ByteArrayT {
-		if param.Type() == stackitem.AnyT && param.Value() == nil {
+	switch param.Type() {
+	case stackitem.BufferT, stackitem.ByteArrayT:
+		return param.TryBytes()
+	case stackitem.AnyT:
+		if param.Value() == nil {
 			return nil, nil
 		}
-
+		fallthrough
+	default:
 		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.