[Blockchain] Cosmos Starport 101 - 为你的新数据类型 生成代码

 

# 项目模板

$ starport app github.com/hello/planet --address-prefix your_new_prefix

项目目录结构的说明看这里: https://docs.starport.network/scaffold/project.html#directory-structure

 

# 创建数据类型, 比如 post 类型, 包含有 title 和 body, 具体可查看命令帮助

$ starport -h

$ starport type -h

$ starport type post title body

含义: starport type [typeName] [field1] [field2] ... [flags]

这是实际意义上的第一步, 为什么要这么做, 请参考这里: https://tutorials.cosmos.network/blog/tutorial/01-index.html

Starport 进一步帮我们省去手工创建过程, 之后我们才可以进行数据的 CRUD.

字段可以是数字和指定的类型,默认是字符串. https://docs.starport.network/scaffold/type.html#command-overview

 

在 app 创建的基础模板上,starport v0.15.1 产生以下修改文件 和 新增文件:

modified: proto/planet/genesis.proto
modified: proto/planet/query.proto
modified: proto/planet/tx.proto
modified: vue/planet/store/generated/index.d.ts
modified: vue/planet/store/generated/index.js
modified: vue/planet/store/generated/index.ts
modified: vue/planet/views/Types.vue
modified: x/planet/client/cli/query.go
modified: x/planet/client/cli/tx.go
modified: x/planet/client/rest/rest.go
modified: x/planet/genesis.go
modified: x/planet/handler.go
modified: x/planet/keeper/query.go
modified: x/planet/module.go
modified: x/planet/types/codec.go
modified: x/planet/types/genesis.go
modified: x/planet/types/genesis.pb.go
modified: x/planet/types/keys.go
modified: x/planet/types/query.go
modified: x/planet/types/query.pb.go
modified: x/planet/types/tx.pb.go

Untracked files:

proto/planet/posts.proto
vue/src/store/generated/farwish/
x/planet/client/cli/queryPosts.go
x/planet/client/cli/txPosts.go
x/planet/client/rest/queryPosts.go
x/planet/client/rest/txPosts.go
x/planet/keeper/grpc_query_posts.go
x/planet/keeper/msg_server_posts.go
x/planet/keeper/query_posts.go
x/planet/keeper/posts.go
x/planet/types/messages_posts.go
x/planet/types/query.pb.gw.go
x/planet/types/posts.pb.go

 

# Cosmos SDK's version is: Stargate v0.40.0

$ starport serve

 

# 运行起来之后 可以使用根据模块名字而生成的 CLI 命令有 planetd.

# https://docs.starport.network/scaffold/type.html#cli-commands

$ planetd tx planet create-posts hello helloWorld --from=alice

$ planetd tx planet create-posts hi helloWorld --from=bob

$ planetd q planetd list-posts

$ planetd tx planet delete-posts 0 --from=alice

$ planetd tx planet delete-posts 1 --from=bob

 

[Blockchain] Cosmos Starport 安装的三种方式

[Blockchain] Cosmos Starport 地址前缀的变更方式

Link: https://www.cnblogs.com/farwish/p/14797454.html

posted on 2021-05-21 21:29  ercom  阅读(96)  评论(0编辑  收藏  举报