@@ -146,39 +146,64 @@ func (k Keeper) GranteeGrants(c context.Context, req *authz.QueryGranteeGrantsRe
146146 }
147147
148148 ctx := sdk .UnwrapSDKContext (c )
149- store := prefix .NewStore (ctx .KVStore (k .storeKey ), GrantKey )
150149
151- authorizations , pageRes , err := query .GenericFilteredPaginate (k .cdc , store , req .Pagination , func (key []byte , auth * authz.Grant ) (* authz.GrantAuthorization , error ) {
152- auth1 , err := auth .GetAuthorization ()
150+ if req .Pagination == nil {
151+ req .Pagination = & query.PageRequest {}
152+ }
153+
154+ if req .Pagination .Limit == 0 {
155+ req .Pagination .Limit = query .DefaultLimit
156+ }
157+
158+ iter := sdk .KVStorePrefixIterator (ctx .KVStore (k .storeKey ), granteeStoreKey (grantee , nil ))
159+ defer func () {
160+ _ = iter .Close ()
161+ }()
162+
163+ var pageRes * query.PageResponse
164+ var grants []* authz.GrantAuthorization
165+
166+ for ; iter .Valid (); iter .Next () {
167+ grantee , granter := parseGranteeStoreKey (iter .Key ())
168+
169+ var authorizations []* authz.GrantAuthorization
170+
171+ store := prefix .NewStore (ctx .KVStore (k .storeKey ), grantStoreKey (grantee , granter , "" ))
172+ authorizations , pageRes , err = query .GenericFilteredPaginate (k .cdc , store , req .Pagination , func (key []byte , auth * authz.Grant ) (* authz.GrantAuthorization , error ) {
173+ auth1 , err := auth .GetAuthorization ()
174+ if err != nil {
175+ return nil , err
176+ }
177+
178+ authorizationAny , err := codectypes .NewAnyWithValue (auth1 )
179+ if err != nil {
180+ return nil , status .Errorf (codes .Internal , err .Error ())
181+ }
182+
183+ return & authz.GrantAuthorization {
184+ Authorization : authorizationAny ,
185+ Expiration : auth .Expiration ,
186+ Granter : granter .String (),
187+ Grantee : grantee .String (),
188+ }, nil
189+ }, func () * authz.Grant {
190+ return & authz.Grant {}
191+ })
192+
153193 if err != nil {
154194 return nil , err
155195 }
156196
157- granter , g , _ := parseGrantStoreKey (append (GrantKey , key ... ))
158- if ! g .Equals (grantee ) {
159- return nil , nil
160- }
197+ grants = append (grants , authorizations ... )
161198
162- authorizationAny , err := codectypes . NewAnyWithValue ( auth1 )
163- if err != nil {
164- return nil , status . Errorf ( codes . Internal , err . Error ())
199+ req . Pagination . Limit -= uint64 ( len ( authorizations ) )
200+ if req . Pagination . Limit == 0 {
201+ break
165202 }
166-
167- return & authz.GrantAuthorization {
168- Authorization : authorizationAny ,
169- Expiration : auth .Expiration ,
170- Granter : granter .String (),
171- Grantee : grantee .String (),
172- }, nil
173- }, func () * authz.Grant {
174- return & authz.Grant {}
175- })
176- if err != nil {
177- return nil , err
178203 }
179204
180205 return & authz.QueryGranteeGrantsResponse {
181- Grants : authorizations ,
206+ Grants : grants ,
182207 Pagination : pageRes ,
183208 }, nil
184209}
0 commit comments