Skip to content

Commit c7e38c6

Browse files
Jerónimo AlbiPantani
andauthored
docs: update tutorials to work with SDK v0.50 (#3705)
* chore: add `--chain-id` flag to blog commands * chore: use `cosmossdk.io/store` * chore: change blog tutorial to use the store service * chore: use `cosmossdk.io/errors` * chore: change "PostID" to "PostId" * chore: add missing import to code snippet * fix: correct expected keepers interface args * chore: add `--chain-id` flag to loan commands * ci: fix broken links * ci: fix broken references * ci: fix broken reference * chore: fix typo --------- Co-authored-by: Danilo Pantani <danpantani@gmail.com>
1 parent 336121c commit c7e38c6

File tree

23 files changed

+117
-105
lines changed

23 files changed

+117
-105
lines changed

.github/workflows/md-link-checker-config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
},
1818
{
1919
"pattern": "^index.md"
20+
},
21+
{
22+
"pattern": "^https://docs.starport.network"
2023
}
2124
],
2225
"replacementPatterns": [

docs/docs/02-guide/04-blog/00-express.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ While `ignite chain serve` is running in one terminal window, open another
173173
terminal and use the chain's binary to create a new blog post on the blockchain:
174174

175175
```
176-
blogd tx blog create-post 'Hello, World!' 'This is a blog post' --from alice
176+
blogd tx blog create-post 'Hello, World!' 'This is a blog post' --from alice --chain-id blog
177177
```
178178

179179
When using the `--from` flag to specify the account that will be used to sign a
@@ -220,7 +220,7 @@ transaction will be broadcasted to the blockchain and the blog post will be
220220
updated with the new body content.
221221

222222
```
223-
blogd tx blog update-post 0 'Hello, World!' 'This is a blog post from Alice' --from alice
223+
blogd tx blog update-post 0 'Hello, World!' 'This is a blog post from Alice' --from alice --chain-id blog
224224
```
225225

226226
Now that we have updated the blog post with new content, let's query the
@@ -263,7 +263,7 @@ example of how the blockchain can enforce rules and permissions, and it shows
263263
that only authorized users are able to make changes to the blockchain.
264264

265265
```
266-
blogd tx blog delete-post 0 --from bob
266+
blogd tx blog delete-post 0 --from bob --chain-id blog
267267
268268
raw_log: 'failed to execute message; message index: 0: incorrect owner: unauthorized'
269269
```
@@ -273,7 +273,7 @@ account. Since Alice is the author of the blog post, she should be authorized to
273273
delete it.
274274

275275
```
276-
blogd tx blog delete-post 0 --from alice
276+
blogd tx blog delete-post 0 --from alice --chain-id blog
277277
```
278278

279279
To check whether the blog post has been successfully deleted by Alice, we can
@@ -306,4 +306,4 @@ some of the code ourselves, we can gain a deeper understanding of how Ignite
306306
works and how it can be used to create applications on a blockchain. This will
307307
help us learn more about the capabilities of Ignite CLI and how it can be used
308308
to build robust and powerful applications. Keep an eye out for these tutorials
309-
and get ready to dive deeper into the world of blockchains with Ignite!
309+
and get ready to dive deeper into the world of blockchains with Ignite!

docs/docs/02-guide/04-blog/03-create.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ import (
2929

3030
"blog/x/blog/types"
3131

32-
"github.com/cosmos/cosmos-sdk/store/prefix"
32+
"cosmossdk.io/store/prefix"
33+
"github.com/cosmos/cosmos-sdk/runtime"
3334
sdk "github.com/cosmos/cosmos-sdk/types"
3435
)
3536

3637
func (k Keeper) AppendPost(ctx sdk.Context, post types.Post) uint64 {
3738
count := k.GetPostCount(ctx)
3839
post.Id = count
39-
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PostKey))
40+
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
41+
store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.PostKey))
4042
appendedValue := k.cdc.MustMarshal(&post)
4143
store.Set(GetPostIDBytes(post.Id), appendedValue)
4244
k.SetPostCount(ctx, count+1)
@@ -126,7 +128,8 @@ In the file `post.go`, let's define the `GetPostCount` function as follows:
126128

127129
```go title="x/blog/keeper/post.go"
128130
func (k Keeper) GetPostCount(ctx sdk.Context) uint64 {
129-
store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{})
131+
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
132+
store := prefix.NewStore(storeAdapter, []byte{})
130133
byteKey := types.KeyPrefix(types.PostCountKey)
131134
bz := store.Get(byteKey)
132135
if bz == nil {
@@ -209,7 +212,8 @@ in the database.
209212

210213
```go title="x/blog/keeper/post.go"
211214
func (k Keeper) SetPostCount(ctx sdk.Context, count uint64) {
212-
store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{})
215+
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
216+
store := prefix.NewStore(storeAdapter, []byte{})
213217
byteKey := types.KeyPrefix(types.PostCountKey)
214218
bz := make([]byte, 8)
215219
binary.BigEndian.PutUint64(bz, count)
@@ -316,4 +320,4 @@ then returns a `MsgCreatePostResponse` object containing the ID of the newly
316320
created post.
317321

318322
By implementing these methods, you have successfully implemented the necessary
319-
logic for handling "create post" messages and adding posts to the blockchain.
323+
logic for handling "create post" messages and adding posts to the blockchain.

docs/docs/02-guide/04-blog/04-update.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Implement the `GetPost` keeper method in `post.go`:
1515

1616
```go title="x/blog/keeper/post.go"
1717
func (k Keeper) GetPost(ctx sdk.Context, id uint64) (val types.Post, found bool) {
18-
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PostKey))
18+
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
19+
store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.PostKey))
1920
b := store.Get(GetPostIDBytes(id))
2021
if b == nil {
2122
return val, false
@@ -48,7 +49,8 @@ Implement the `SetPost` keeper method in `post.go`:
4849

4950
```go title="x/blog/keeper/post.go"
5051
func (k Keeper) SetPost(ctx sdk.Context, post types.Post) {
51-
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PostKey))
52+
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
53+
store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.PostKey))
5254
b := k.cdc.MustMarshal(&post)
5355
store.Set(GetPostIDBytes(post.Id), b)
5456
}
@@ -78,6 +80,7 @@ import (
7880

7981
"blog/x/blog/types"
8082

83+
errorsmod "cosmossdk.io/errors"
8184
sdk "github.com/cosmos/cosmos-sdk/types"
8285
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
8386
)
@@ -92,10 +95,10 @@ func (k msgServer) UpdatePost(goCtx context.Context, msg *types.MsgUpdatePost) (
9295
}
9396
val, found := k.GetPost(ctx, msg.Id)
9497
if !found {
95-
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("key %d doesn't exist", msg.Id))
98+
return nil, errorsmod.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("key %d doesn't exist", msg.Id))
9699
}
97100
if msg.Creator != val.Creator {
98-
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "incorrect owner")
101+
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "incorrect owner")
99102
}
100103
k.SetPost(ctx, post)
101104
return &types.MsgUpdatePostResponse{}, nil
@@ -124,4 +127,4 @@ can be useful for correcting mistakes or updating the content of a post as new
124127
information becomes available.
125128

126129
Finally, you implemented the `UpdatePost` method, which is called whenever the
127-
blockchain processes a message requesting an update to a post.
130+
blockchain processes a message requesting an update to a post.

docs/docs/02-guide/04-blog/05-delete.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ message.
77

88
```go title="x/blog/keeper/post.go"
99
func (k Keeper) RemovePost(ctx sdk.Context, id uint64) {
10-
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PostKey))
10+
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
11+
store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.PostKey))
1112
store.Delete(GetPostIDBytes(id))
1213
}
1314
```
@@ -32,6 +33,7 @@ import (
3233

3334
"blog/x/blog/types"
3435

36+
errorsmod "cosmossdk.io/errors"
3537
sdk "github.com/cosmos/cosmos-sdk/types"
3638
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
3739
)
@@ -40,10 +42,10 @@ func (k msgServer) DeletePost(goCtx context.Context, msg *types.MsgDeletePost) (
4042
ctx := sdk.UnwrapSDKContext(goCtx)
4143
val, found := k.GetPost(ctx, msg.Id)
4244
if !found {
43-
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("key %d doesn't exist", msg.Id))
45+
return nil, errorsmod.Wrap(sdkerrors.ErrKeyNotFound, fmt.Sprintf("key %d doesn't exist", msg.Id))
4446
}
4547
if msg.Creator != val.Creator {
46-
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "incorrect owner")
48+
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "incorrect owner")
4749
}
4850
k.RemovePost(ctx, msg.Id)
4951
return &types.MsgDeletePostResponse{}, nil
@@ -57,7 +59,7 @@ a pointer to a message of type `*types.MsgDeletePostResponse` and an `error`.
5759
Inside the function, the context is unwrapped using the `sdk.UnwrapSDKContext`
5860
function and the value of the post with the ID specified in the message is
5961
retrieved using the `GetPost` function. If the post is not found, an error is
60-
returned using the `sdkerrors.Wrap` function. If the creator of the message does
62+
returned using the `errorsmod.Wrap` function. If the creator of the message does
6163
not match the creator of the post, another error is returned. If both of these
6264
checks pass, the `RemovePost` function is called with the context and the ID of
6365
the post to delete the post. Finally, the function returns a response message
@@ -71,4 +73,4 @@ requester is the creator of the post before deleting it.
7173
Congratulations on completing the implementation of the `RemovePost` and
7274
`DeletePost` methods in the keeper package! These methods provide functionality
7375
for removing a post from a store and handling a request to delete a post,
74-
respectively.
76+
respectively.

docs/docs/02-guide/04-blog/07-list.md

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6564
The 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
7471
values into `Post` objects, which are then appended to the `posts` slice.
7572

7673
If 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
```
9693
ignite generate proto-go
97-
```
94+
```

docs/docs/02-guide/04-blog/08-play.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Create a blog post by Alice
44

55
```
6-
blogd tx blog create-post hello world --from alice
6+
blogd tx blog create-post hello world --from alice --chain-id blog
77
```
88

99
## Show a blog post
@@ -23,7 +23,7 @@ post:
2323
## Create a blog post by Bob
2424
2525
```
26-
blogd tx blog create-post foo bar --from bob
26+
blogd tx blog create-post foo bar --from bob --chain-id blog
2727
```
2828

2929
## List all blog posts with pagination
@@ -50,7 +50,7 @@ post:
5050
## Update a blog post
5151
5252
```
53-
blogd tx blog update-post hello cosmos 0 --from alice
53+
blogd tx blog update-post hello cosmos 0 --from alice --chain-id blog
5454
```
5555

5656
```
@@ -68,7 +68,7 @@ post:
6868
## Delete a blog post
6969
7070
```
71-
blogd tx blog delete-post 0 --from alice
71+
blogd tx blog delete-post 0 --from alice --chain-id blog
7272
```
7373

7474
```
@@ -89,9 +89,9 @@ post:
8989
## Delete a blog post unsuccessfully
9090
9191
```
92-
blogd tx blog delete-post 1 --from alice
92+
blogd tx blog delete-post 1 --from alice --chain-id blog
9393
```
9494

9595
```yml
9696
raw_log: 'failed to execute message; message index: 0: incorrect owner: unauthorized'
97-
```
97+
```

docs/docs/02-guide/05-loan/02-bank.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import (
2424
type BankKeeper interface {
2525
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
2626
// highlight-start
27-
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
28-
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
29-
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
27+
SendCoins(ctx context.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
28+
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
29+
SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
3030
// highlight-end
3131
}
32-
```
32+
```

docs/docs/02-guide/05-loan/03-request.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,40 +76,41 @@ import (
7676
// highlight-next-line
7777
"strconv"
7878

79+
errorsmod "cosmossdk.io/errors"
7980
sdk "github.com/cosmos/cosmos-sdk/types"
8081
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
8182
)
8283

8384
func (msg *MsgRequestLoan) ValidateBasic() error {
8485
_, err := sdk.AccAddressFromBech32(msg.Creator)
8586
if err != nil {
86-
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
87+
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
8788
}
8889
// highlight-start
8990
amount, _ := sdk.ParseCoinsNormalized(msg.Amount)
9091
if !amount.IsValid() {
91-
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "amount is not a valid Coins object")
92+
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "amount is not a valid Coins object")
9293
}
9394
if amount.Empty() {
94-
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "amount is empty")
95+
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "amount is empty")
9596
}
9697
fee, _ := sdk.ParseCoinsNormalized(msg.Fee)
9798
if !fee.IsValid() {
98-
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee is not a valid Coins object")
99+
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "fee is not a valid Coins object")
99100
}
100101
deadline, err := strconv.ParseInt(msg.Deadline, 10, 64)
101102
if err != nil {
102-
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "deadline is not an integer")
103+
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "deadline is not an integer")
103104
}
104105
if deadline <= 0 {
105-
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "deadline should be a positive integer")
106+
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "deadline should be a positive integer")
106107
}
107108
collateral, _ := sdk.ParseCoinsNormalized(msg.Collateral)
108109
if !collateral.IsValid() {
109-
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "collateral is not a valid Coins object")
110+
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "collateral is not a valid Coins object")
110111
}
111112
if collateral.Empty() {
112-
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "collateral is empty")
113+
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "collateral is empty")
113114
}
114115
// highlight-end
115116
return nil

0 commit comments

Comments
 (0)