[#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.
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.