From 0a1e0aeb85067549e4613ab32a2ccc36365242eb Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 6 Jan 2025 15:01:17 +0100 Subject: [PATCH] Update types/collections.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- types/collections.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/types/collections.go b/types/collections.go index 0abde0f64190..f1321126597e 100644 --- a/types/collections.go +++ b/types/collections.go @@ -125,9 +125,21 @@ func (a genericAddressKey[T]) SchemaCodec() (collcodec.SchemaCodec[T], error) { return collcodec.SchemaCodec[T]{ Fields: []schema.Field{{Kind: schema.AddressKind}}, ToSchemaType: func(t T) (any, error) { + if len(t) == 0 { + return nil, fmt.Errorf("invalid empty address") + } return t, nil }, - FromSchemaType: nil, + FromSchemaType: func(s any) (T, error) { + addr, ok := s.([]byte) + if !ok { + return nil, fmt.Errorf("expected []byte, got %T", s) + } + if len(addr) == 0 { + return nil, fmt.Errorf("invalid empty address") + } + return T(addr), nil + }, }, nil }