Make query.FilteredPaginate use generics, and remove the accumulate parameter #12242
Description
Summary
Currently query.FilteredPaginate creates a silly developer overhead for callers, as they have to maintain the entire slice to return at the end. (and handle the complexity for the accumulate
parameter.
Ideally this is instead handled by generic routines, and not the developer writing the query. This previously wasn't cleanly doable, due to needing to maintain the return type callee side. But now that generics have landed, the filtered paginate queries can easily use a generic type parameter for the slice type. Furthermore lets make this parameter a proto.message, so the serialization / deserialization can be handled for the caller.
Problem Definition
Reduce the developer overhead of writing a filtered paginate query. Currently even the simplest ones, net around 40 lines for the caller.
Proposal
Change filtered paginate from having the caller have to define the list of whats accumulated.
This should change the following API
cosmos-sdk/x/authz/keeper/grpc_query.go
Lines 67 to 103 in 5505428
return query.FilteredPaginate[Authorization](grantsStore, req.Pagination, k.cdc, func(key []byte, auth Authorization) (Authorization, error) {
auth1, err := auth.GetAuthorization()
if err != nil {
return false, err
}
// (This ok check seems useless even in he original code)
msg, ok := auth1.(proto.Message)
if !ok {
return false, status.Errorf(codes.Internal, "can't protomarshal %T", msg)
}
authorizationAny, err := codectypes.NewAnyWithValue(msg)
if err != nil {
return false, status.Errorf(codes.Internal, err.Error())
}
return authorizationAny, nil
})
Perhaps the new function needs a new name for backwards API compatibility? I'm not too sure though, I feel like this is a code reduction that should be universally accepted here.
For Admin Use
- Not duplicate issue
- Appropriate labels applied
- Appropriate contributors tagged
- Contributor assigned/self-assigned
Metadata
Assignees
Labels
Type
Projects
Status
No status
Activity