Skip to content

Commit

Permalink
Update types/collections.go
Browse files Browse the repository at this point in the history
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
julienrbrt and coderabbitai[bot] authored Jan 6, 2025
1 parent 9506c52 commit 0a1e0ae
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion types/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 0a1e0ae

Please sign in to comment.