Skip to content
This repository was archived by the owner on Apr 10, 2026. It is now read-only.

Commit 415ea4f

Browse files
authored
Linting for Tutorial (#134)
* litning * linting fix
1 parent e831370 commit 415ea4f

12 files changed

Lines changed: 35 additions & 58 deletions

File tree

.golangci.yml

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
linters:
2-
disable-all: true
3-
enable:
4-
- errcheck
2+
enable-all: true
3+
disable:
54
- golint
6-
- ineffassign
7-
- unconvert
8-
- misspell
9-
- govet
10-
linters-settings:
11-
gocyclo:
12-
min-complexity: 11
13-
errcheck:
14-
ignore: fmt:.*,io/ioutil:^Read.*,github.com/spf13/cobra:MarkFlagRequired,github.com/spf13/viper:BindPFlag
15-
golint:
16-
min-confidence: 1.1
17-
issues:
18-
exclude:
19-
- composite
20-
run:
21-
tests: false
5+
- unparam
6+
- gochecknoinits
7+
- gochecknoglobals

app.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ var (
5454
maccPerms = map[string][]string{
5555
auth.FeeCollectorName: nil,
5656
distr.ModuleName: nil,
57-
staking.BondedPoolName: []string{supply.Burner, supply.Staking},
58-
staking.NotBondedPoolName: []string{supply.Burner, supply.Staking},
57+
staking.BondedPoolName: {supply.Burner, supply.Staking},
58+
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
5959
}
6060
)
6161

@@ -157,7 +157,8 @@ func NewNameServiceApp(logger log.Logger, db dbm.DB) *nameServiceApp {
157157
app.accountKeeper,
158158
app.bankKeeper,
159159
supply.DefaultCodespace,
160-
maccPerms)
160+
maccPerms,
161+
)
161162

162163
// The staking keeper
163164
stakingKeeper := staking.NewKeeper(

cmd/nscli/main.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ import (
1818
"github.com/tendermint/tendermint/libs/cli"
1919
)
2020

21-
const (
22-
storeAcc = "acc"
23-
storeNS = "nameservice"
24-
)
25-
2621
func main() {
2722
cobra.EnableCommandSorting = false
2823

cmd/nsd/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ func main() {
4343
rootCmd.AddCommand(
4444
genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome),
4545
genutilcli.CollectGenTxsCmd(ctx, cdc, genaccounts.AppModuleBasic{}, app.DefaultNodeHome),
46-
genutilcli.GenTxCmd(ctx, cdc, app.ModuleBasics, staking.AppModuleBasic{}, genaccounts.AppModuleBasic{}, app.DefaultNodeHome, app.DefaultCLIHome),
46+
genutilcli.GenTxCmd(
47+
ctx, cdc, app.ModuleBasics, staking.AppModuleBasic{},
48+
genaccounts.AppModuleBasic{}, app.DefaultNodeHome, app.DefaultCLIHome,
49+
),
4750
genutilcli.ValidateGenesisCmd(ctx, cdc, app.ModuleBasics),
4851
// AddGenesisAccountCmd allows users to add accounts to the genesis file
4952
genaccscli.AddGenesisAccountCmd(ctx, cdc, app.DefaultNodeHome, app.DefaultCLIHome),

tutorial/cn/13-entrypoint.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Entrypoint
22

3-
golang的规范是把编译成可执行程序的文件放在项目的`./cmd`文件夹中。对于你的应用程序,您要创建2个可执行程序
3+
golang 的规范是把编译成可执行程序的文件放在项目的`./cmd`文件夹中。对于你的应用程序,您要创建 2 个可执行程序
44

5-
- `nsd` : 此可执行程序类似于`bitcoind`或其他加密货币的daemon,因为它维护p2p连接,广播交易,处理本地存储并提供用以与网络交互的RPC接口。在这种情况下,Tendermint被用于网络层和排序交易
5+
- `nsd` : 此可执行程序类似于`bitcoind`或其他加密货币的 daemon,因为它维护 p2p 连接,广播交易,处理本地存储并提供用以与网络交互的 RPC 接口。在这种情况下,Tendermint 被用于网络层和排序交易
66
- `nscli` : 此可执行程序提供用户与你的应用程序交互的命令。
77

88
首先请在项目目录中创建两个将会被实例化成这可执行程序的文件:
@@ -251,16 +251,16 @@ func SimpleAppGenTx(cdc *codec.Codec, pk crypto.PubKey) (
251251

252252
注意上述代码中:
253253

254-
- 上面的大部分代码都结合了来自以下包的CLI命令
254+
- 上面的大部分代码都结合了来自以下包的 CLI 命令
255255
1. Tendermint
256256
2. Cosmos-SDK
257-
3. 你的nameservice模块
257+
3. 你的 nameservice 模块
258258
- `InitCmd`允许应用程序从配置中生成创世纪状态。深入了解函数调用,以了解有关区块链初始化过程的更多信息。
259259
- `AddGenesisAccountCmd`可以方便地将帐户添加到创世文件中,允许在区块链启动时就使用资产钱包。
260260

261261
## nscli
262262

263-
通过构建nscli命令完成
263+
通过构建 nscli 命令完成
264264

265265
> 注意:你的应用程序需要导入你刚编写的代码。这里导入路径设置为此存储库(`github.com/cosmos/sdk-application-tutorial`)。如果您是在自己的仓库中进行的前面的操作,则需要更改导入路径(github.com/{.Username}/{.Project.Repo})。
266266
@@ -291,11 +291,6 @@ import (
291291
nsrest "github.com/cosmos/sdk-application-tutorial/x/nameservice/client/rest"
292292
)
293293

294-
const (
295-
storeAcc = "acc"
296-
storeNS = "nameservice"
297-
)
298-
299294
var defaultCLIHome = os.ExpandEnv("$HOME/.nscli")
300295

301296
func main() {
@@ -336,7 +331,7 @@ func main() {
336331
client.LineBreak,
337332
keys.Commands(),
338333
client.LineBreak,
339-
334+
340335
)
341336

342337
executor := cli.PrepareMainCmd(rootCmd, "NS", defaultCLIHome)
@@ -425,10 +420,9 @@ func initConfig(cmd *cobra.Command) error {
425420

426421
注意:
427422

428-
- 代码结合了来自以下包的CLI命令:Tendermint、Cosmos-SDK、你的nameservice模块
429-
- [`cobra` CLI文档](https://github.com/spf13/cobra)将有助于理解上述代码。
423+
- 代码结合了来自以下包的 CLI 命令:Tendermint、Cosmos-SDK、你的 nameservice 模块
424+
- [`cobra` CLI 文档](https://github.com/spf13/cobra)将有助于理解上述代码。
430425
- 你可以在这里看到之前定义的`ModuleClient`
431426
- 注意如何将路由包含在`registerRoutes`函数中
432427

433428
### 现在你已经定义了二进制文件,那么就可以来处理[依赖关系管理并构建应用程序](./14-dep.md)
434-

tutorial/entrypoint.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ import (
132132
"github.com/tendermint/tendermint/libs/cli"
133133
)
134134

135-
const (
136-
storeAcc = "acc"
137-
storeNS = "nameservice"
138-
)
139135

140136
func main() {
141137
cobra.EnableCommandSorting = false

x/nameservice/alias.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ var (
1515
NewMsgSetName = types.NewMsgSetName
1616
NewMsgDeleteName = types.NewMsgDeleteName
1717
NewWhois = types.NewWhois
18-
ModuleCdc = types.ModuleCdc
19-
RegisterCodec = types.RegisterCodec
18+
ModuleCdc = types.ModuleCdc
19+
RegisterCodec = types.RegisterCodec
2020
)
2121

2222
type (

x/nameservice/genesis.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ func NewGenesisState(whoIsRecords []Whois) GenesisState {
1818
func ValidateGenesis(data GenesisState) error {
1919
for _, record := range data.WhoisRecords {
2020
if record.Owner == nil {
21-
return fmt.Errorf("Invalid WhoisRecord: Value: %s. Error: Missing Owner", record.Value)
21+
return fmt.Errorf("invalid WhoisRecord: Value: %s. Error: Missing Owner", record.Value)
2222
}
2323
if record.Value == "" {
24-
return fmt.Errorf("Invalid WhoisRecord: Owner: %s. Error: Missing Value", record.Owner)
24+
return fmt.Errorf("invalid WhoisRecord: Owner: %s. Error: Missing Value", record.Owner)
2525
}
2626
if record.Price == nil {
27-
return fmt.Errorf("Invalid WhoisRecord: Value: %s. Error: Missing Price", record.Value)
27+
return fmt.Errorf("invalid WhoisRecord: Value: %s. Error: Missing Price", record.Value)
2828
}
2929
}
3030
return nil
@@ -47,10 +47,11 @@ func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState {
4747
var records []Whois
4848
iterator := k.GetNamesIterator(ctx)
4949
for ; iterator.Valid(); iterator.Next() {
50+
5051
name := string(iterator.Key())
51-
var whois Whois
52-
whois = k.GetWhois(ctx, name)
52+
whois := k.GetWhois(ctx, name)
5353
records = append(records, whois)
54+
5455
}
5556
return GenesisState{WhoisRecords: records}
5657
}

x/nameservice/handler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package nameservice
22

33
import (
44
"fmt"
5+
56
"github.com/cosmos/sdk-application-tutorial/x/nameservice/types"
67

78
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -35,7 +36,8 @@ func handleMsgSetName(ctx sdk.Context, keeper Keeper, msg MsgSetName) sdk.Result
3536

3637
// Handle a message to buy name
3738
func handleMsgBuyName(ctx sdk.Context, keeper Keeper, msg MsgBuyName) sdk.Result {
38-
if keeper.GetPrice(ctx, msg.Name).IsAllGT(msg.Bid) { // Checks if the the bid price is greater than the price paid by the current owner
39+
// Checks if the the bid price is greater than the price paid by the current owner
40+
if keeper.GetPrice(ctx, msg.Name).IsAllGT(msg.Bid) {
3941
return sdk.ErrInsufficientCoins("Bid not high enough").Result() // If not, throw an error
4042
}
4143
if keeper.HasOwner(ctx, msg.Name) {

x/nameservice/keeper.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
sdk "github.com/cosmos/cosmos-sdk/types"
88
)
99

10-
// Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine
10+
// Keeper maintains the link to storage and exposes getter/setter methods for the various parts of the state machine
1111
type Keeper struct {
1212
coinKeeper bank.Keeper
1313

@@ -104,4 +104,3 @@ func (k Keeper) IsNamePresent(ctx sdk.Context, name string) bool {
104104
store := ctx.KVStore(k.storeKey)
105105
return store.Has([]byte(name))
106106
}
107-

0 commit comments

Comments
 (0)