@@ -22,25 +22,24 @@ import (
2222
2323 " blog/x/blog/types"
2424
25- " github.com/cosmos/cosmos-sdk /store/prefix"
25+ " cosmossdk.io /store/prefix"
2626 sdk " github.com/cosmos/cosmos-sdk/types"
27+ " github.com/cosmos/cosmos-sdk/runtime"
2728 " github.com/cosmos/cosmos-sdk/types/query"
2829 " google.golang.org/grpc/codes"
2930 " google.golang.org/grpc/status"
3031)
3132
32- func (k Keeper ) ListPost (goCtx context .Context , req *types .QueryListPostRequest ) (*types .QueryListPostResponse , error ) {
33+ func (k Keeper ) ListPost (ctx context .Context , req *types .QueryListPostRequest ) (*types .QueryListPostResponse , error ) {
3334 if req == nil {
3435 return nil , status.Error (codes.InvalidArgument , " invalid request" )
3536 }
3637
37- var posts []types.Post
38- ctx := sdk.UnwrapSDKContext (goCtx)
39-
40- store := ctx.KVStore (k.storeKey )
41- postStore := prefix.NewStore (store, types.KeyPrefix (types.PostKey ))
38+ storeAdapter := runtime.KVStoreAdapter (k.storeService .OpenKVStore (ctx))
39+ store := prefix.NewStore (storeAdapter, types.KeyPrefix (types.PostKey ))
4240
43- pageRes , err := query.Paginate (postStore, req.Pagination , func (key []byte , value []byte ) error {
41+ var posts []types.Post
42+ pageRes , err := query.Paginate (store, req.Pagination , func (key []byte , value []byte ) error {
4443 var post types.Post
4544 if err := k.cdc .Unmarshal (value, &post); err != nil {
4645 return err
@@ -63,14 +62,12 @@ func (k Keeper) ListPost(goCtx context.Context, req *types.QueryListPostRequest)
6362` QueryListPostResponse ` and an error.
6463
6564The function first checks if the request object is ` nil ` and returns an error
66- with a ` InvalidArgument ` code if it is. It then initializes an empty slice of
67- ` Post ` objects and unwraps the context object.
68-
69- It retrieves a key-value store from the context using the ` storeKey ` field of
70- the keeper struct and creates a new store using a prefix of the ` PostKey ` . It
71- then calls the ` Paginate ` function from the ` query ` package on the store and the
72- pagination information in the request object. The function passed as an argument
73- to Paginate iterates over the key-value pairs in the store and unmarshals the
65+ with a ` InvalidArgument ` code if it is.
66+
67+ It creates a new store using a prefix of the ` PostKey ` and then calls the
68+ ` Paginate ` function from the ` query ` package on the store and the pagination
69+ information in the request object. The function passed as an argument to
70+ Paginate iterates over the key-value pairs in the store and unmarshals the
7471values into ` Post ` objects, which are then appended to the ` posts ` slice.
7572
7673If an error occurs during pagination, the function returns an ` Internal error `
@@ -94,4 +91,4 @@ Run the command to generate Go files from proto:
9491
9592```
9693ignite generate proto-go
97- ```
94+ ```
0 commit comments