66 "google.golang.org/grpc/codes"
77 "google.golang.org/grpc/status"
88
9- proto "github.com/gogo/protobuf/proto"
10-
11- "github.com/cosmos/cosmos-sdk/codec"
129 codectypes "github.com/cosmos/cosmos-sdk/codec/types"
1310 "github.com/cosmos/cosmos-sdk/store/prefix"
1411 sdk "github.com/cosmos/cosmos-sdk/types"
@@ -64,34 +61,22 @@ func (k Keeper) Grants(c context.Context, req *authz.QueryGrantsRequest) (*authz
6461 key := grantStoreKey (grantee , granter , "" )
6562 grantsStore := prefix .NewStore (store , key )
6663
67- var authorizations []* authz.Grant
68- pageRes , err := query .FilteredPaginate (grantsStore , req .Pagination , func (key []byte , value []byte , accumulate bool ) (bool , error ) {
69- auth , err := unmarshalAuthorization (k .cdc , value )
70- if err != nil {
71- return false , err
72- }
73-
64+ authorizations , pageRes , err := query .GenericFilteredPaginate (k .cdc , grantsStore , req .Pagination , func (key []byte , auth * authz.Grant ) (* authz.Grant , error ) {
7465 auth1 , err := auth .GetAuthorization ()
7566 if err != nil {
76- return false , err
67+ return nil , err
7768 }
7869
79- if accumulate {
80- msg , ok := auth1 .(proto.Message )
81- if ! ok {
82- return false , status .Errorf (codes .Internal , "can't protomarshal %T" , msg )
83- }
84-
85- authorizationAny , err := codectypes .NewAnyWithValue (msg )
86- if err != nil {
87- return false , status .Errorf (codes .Internal , err .Error ())
88- }
89- authorizations = append (authorizations , & authz.Grant {
90- Authorization : authorizationAny ,
91- Expiration : auth .Expiration ,
92- })
70+ authorizationAny , err := codectypes .NewAnyWithValue (auth1 )
71+ if err != nil {
72+ return nil , status .Errorf (codes .Internal , err .Error ())
9373 }
94- return true , nil
74+ return & authz.Grant {
75+ Authorization : authorizationAny ,
76+ Expiration : auth .Expiration ,
77+ }, nil
78+ }, func () * authz.Grant {
79+ return & authz.Grant {}
9580 })
9681 if err != nil {
9782 return nil , err
@@ -118,34 +103,29 @@ func (k Keeper) GranterGrants(c context.Context, req *authz.QueryGranterGrantsRe
118103 store := ctx .KVStore (k .storeKey )
119104 authzStore := prefix .NewStore (store , grantStoreKey (nil , granter , "" ))
120105
121- var grants []* authz.GrantAuthorization
122- pageRes , err := query .FilteredPaginate (authzStore , req .Pagination , func (key []byte , value []byte , accumulate bool ) (bool , error ) {
123- auth , err := unmarshalAuthorization (k .cdc , value )
106+ grants , pageRes , err := query .GenericFilteredPaginate (k .cdc , authzStore , req .Pagination , func (key []byte , auth * authz.Grant ) (* authz.GrantAuthorization , error ) {
107+ auth1 , err := auth .GetAuthorization ()
124108 if err != nil {
125- return false , err
109+ return nil , err
126110 }
127111
128- auth1 , err := auth . GetAuthorization ( )
112+ any , err := codectypes . NewAnyWithValue ( auth1 )
129113 if err != nil {
130- return false , err
114+ return nil , status . Errorf ( codes . Internal , err . Error ())
131115 }
132116
133- if accumulate {
134- any , err := codectypes .NewAnyWithValue (auth1 )
135- if err != nil {
136- return false , status .Errorf (codes .Internal , err .Error ())
137- }
138-
139- grantee := firstAddressFromGrantStoreKey (key )
140- grants = append (grants , & authz.GrantAuthorization {
141- Granter : granter .String (),
142- Grantee : grantee .String (),
143- Authorization : any ,
144- Expiration : auth .Expiration ,
145- })
146- }
147- return true , nil
117+ grantee := firstAddressFromGrantStoreKey (key )
118+ return & authz.GrantAuthorization {
119+ Granter : granter .String (),
120+ Grantee : grantee .String (),
121+ Authorization : any ,
122+ Expiration : auth .Expiration ,
123+ }, nil
124+
125+ }, func () * authz.Grant {
126+ return & authz.Grant {}
148127 })
128+
149129 if err != nil {
150130 return nil , err
151131 }
@@ -170,36 +150,30 @@ func (k Keeper) GranteeGrants(c context.Context, req *authz.QueryGranteeGrantsRe
170150 ctx := sdk .UnwrapSDKContext (c )
171151 store := prefix .NewStore (ctx .KVStore (k .storeKey ), GrantKey )
172152
173- var authorizations []* authz.GrantAuthorization
174- pageRes , err := query .FilteredPaginate (store , req .Pagination , func (key []byte , value []byte , accumulate bool ) (bool , error ) {
175- auth , err := unmarshalAuthorization (k .cdc , value )
153+ authorizations , pageRes , err := query .GenericFilteredPaginate (k .cdc , store , req .Pagination , func (key []byte , auth * authz.Grant ) (* authz.GrantAuthorization , error ) {
154+ auth1 , err := auth .GetAuthorization ()
176155 if err != nil {
177- return false , err
156+ return nil , err
178157 }
179158
180159 granter , g , _ := parseGrantStoreKey (append (GrantKey , key ... ))
181160 if ! g .Equals (grantee ) {
182- return false , nil
161+ return nil , nil
183162 }
184163
185- auth1 , err := auth . GetAuthorization ( )
164+ authorizationAny , err := codectypes . NewAnyWithValue ( auth1 )
186165 if err != nil {
187- return false , err
188- }
189- if accumulate {
190- any , err := codectypes .NewAnyWithValue (auth1 )
191- if err != nil {
192- return false , status .Errorf (codes .Internal , err .Error ())
193- }
194-
195- authorizations = append (authorizations , & authz.GrantAuthorization {
196- Authorization : any ,
197- Expiration : auth .Expiration ,
198- Granter : granter .String (),
199- Grantee : grantee .String (),
200- })
166+ return nil , status .Errorf (codes .Internal , err .Error ())
201167 }
202- return true , nil
168+
169+ return & authz.GrantAuthorization {
170+ Authorization : authorizationAny ,
171+ Expiration : auth .Expiration ,
172+ Granter : granter .String (),
173+ Grantee : grantee .String (),
174+ }, nil
175+ }, func () * authz.Grant {
176+ return & authz.Grant {}
203177 })
204178 if err != nil {
205179 return nil , err
@@ -210,9 +184,3 @@ func (k Keeper) GranteeGrants(c context.Context, req *authz.QueryGranteeGrantsRe
210184 Pagination : pageRes ,
211185 }, nil
212186}
213-
214- // unmarshal an authorization from a store value
215- func unmarshalAuthorization (cdc codec.BinaryCodec , value []byte ) (v authz.Grant , err error ) {
216- err = cdc .Unmarshal (value , & v )
217- return v , err
218- }
0 commit comments