Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting for Tutorial #134

Merged
merged 2 commits into from Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 5 additions & 19 deletions .golangci.yml
@@ -1,21 +1,7 @@
linters:
disable-all: true
enable:
- errcheck
enable-all: true
disable:
- golint
- ineffassign
- unconvert
- misspell
- govet
linters-settings:
gocyclo:
min-complexity: 11
errcheck:
ignore: fmt:.*,io/ioutil:^Read.*,github.com/spf13/cobra:MarkFlagRequired,github.com/spf13/viper:BindPFlag
golint:
min-confidence: 1.1
issues:
exclude:
- composite
run:
tests: false
- unparam
- gochecknoinits
- gochecknoglobals
7 changes: 4 additions & 3 deletions app.go
Expand Up @@ -54,8 +54,8 @@ var (
maccPerms = map[string][]string{
auth.FeeCollectorName: nil,
distr.ModuleName: nil,
staking.BondedPoolName: []string{supply.Burner, supply.Staking},
staking.NotBondedPoolName: []string{supply.Burner, supply.Staking},
staking.BondedPoolName: {supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
}
)

Expand Down Expand Up @@ -157,7 +157,8 @@ func NewNameServiceApp(logger log.Logger, db dbm.DB) *nameServiceApp {
app.accountKeeper,
app.bankKeeper,
supply.DefaultCodespace,
maccPerms)
maccPerms,
)

// The staking keeper
stakingKeeper := staking.NewKeeper(
Expand Down
5 changes: 0 additions & 5 deletions cmd/nscli/main.go
Expand Up @@ -18,11 +18,6 @@ import (
"github.com/tendermint/tendermint/libs/cli"
)

const (
storeAcc = "acc"
storeNS = "nameservice"
)

func main() {
cobra.EnableCommandSorting = false

Expand Down
5 changes: 4 additions & 1 deletion cmd/nsd/main.go
Expand Up @@ -43,7 +43,10 @@ func main() {
rootCmd.AddCommand(
genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(ctx, cdc, genaccounts.AppModuleBasic{}, app.DefaultNodeHome),
genutilcli.GenTxCmd(ctx, cdc, app.ModuleBasics, staking.AppModuleBasic{}, genaccounts.AppModuleBasic{}, app.DefaultNodeHome, app.DefaultCLIHome),
genutilcli.GenTxCmd(
ctx, cdc, app.ModuleBasics, staking.AppModuleBasic{},
genaccounts.AppModuleBasic{}, app.DefaultNodeHome, app.DefaultCLIHome,
),
genutilcli.ValidateGenesisCmd(ctx, cdc, app.ModuleBasics),
// AddGenesisAccountCmd allows users to add accounts to the genesis file
genaccscli.AddGenesisAccountCmd(ctx, cdc, app.DefaultNodeHome, app.DefaultCLIHome),
Expand Down
22 changes: 8 additions & 14 deletions tutorial/cn/13-entrypoint.md
@@ -1,8 +1,8 @@
# Entrypoint

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

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

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

注意上述代码中:

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

## nscli

通过构建nscli命令完成
通过构建 nscli 命令完成

> 注意:你的应用程序需要导入你刚编写的代码。这里导入路径设置为此存储库(`github.com/cosmos/sdk-application-tutorial`)。如果您是在自己的仓库中进行的前面的操作,则需要更改导入路径(github.com/{.Username}/{.Project.Repo})。

Expand Down Expand Up @@ -291,11 +291,6 @@ import (
nsrest "github.com/cosmos/sdk-application-tutorial/x/nameservice/client/rest"
)

const (
storeAcc = "acc"
storeNS = "nameservice"
)

var defaultCLIHome = os.ExpandEnv("$HOME/.nscli")

func main() {
Expand Down Expand Up @@ -336,7 +331,7 @@ func main() {
client.LineBreak,
keys.Commands(),
client.LineBreak,

)

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

注意:

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

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

4 changes: 0 additions & 4 deletions tutorial/entrypoint.md
Expand Up @@ -132,10 +132,6 @@ import (
"github.com/tendermint/tendermint/libs/cli"
)

const (
storeAcc = "acc"
storeNS = "nameservice"
)

func main() {
cobra.EnableCommandSorting = false
Expand Down
4 changes: 2 additions & 2 deletions x/nameservice/alias.go
Expand Up @@ -15,8 +15,8 @@ var (
NewMsgSetName = types.NewMsgSetName
NewMsgDeleteName = types.NewMsgDeleteName
NewWhois = types.NewWhois
ModuleCdc = types.ModuleCdc
RegisterCodec = types.RegisterCodec
ModuleCdc = types.ModuleCdc
RegisterCodec = types.RegisterCodec
)

type (
Expand Down
11 changes: 6 additions & 5 deletions x/nameservice/genesis.go
Expand Up @@ -18,13 +18,13 @@ func NewGenesisState(whoIsRecords []Whois) GenesisState {
func ValidateGenesis(data GenesisState) error {
for _, record := range data.WhoisRecords {
if record.Owner == nil {
return fmt.Errorf("Invalid WhoisRecord: Value: %s. Error: Missing Owner", record.Value)
return fmt.Errorf("invalid WhoisRecord: Value: %s. Error: Missing Owner", record.Value)
}
if record.Value == "" {
return fmt.Errorf("Invalid WhoisRecord: Owner: %s. Error: Missing Value", record.Owner)
return fmt.Errorf("invalid WhoisRecord: Owner: %s. Error: Missing Value", record.Owner)
}
if record.Price == nil {
return fmt.Errorf("Invalid WhoisRecord: Value: %s. Error: Missing Price", record.Value)
return fmt.Errorf("invalid WhoisRecord: Value: %s. Error: Missing Price", record.Value)
}
}
return nil
Expand All @@ -47,10 +47,11 @@ func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState {
var records []Whois
iterator := k.GetNamesIterator(ctx)
for ; iterator.Valid(); iterator.Next() {

name := string(iterator.Key())
var whois Whois
whois = k.GetWhois(ctx, name)
whois := k.GetWhois(ctx, name)
records = append(records, whois)

}
return GenesisState{WhoisRecords: records}
}
4 changes: 3 additions & 1 deletion x/nameservice/handler.go
Expand Up @@ -2,6 +2,7 @@ package nameservice

import (
"fmt"

"github.com/cosmos/sdk-application-tutorial/x/nameservice/types"

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

// Handle a message to buy name
func handleMsgBuyName(ctx sdk.Context, keeper Keeper, msg MsgBuyName) sdk.Result {
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
// Checks if the the bid price is greater than the price paid by the current owner
if keeper.GetPrice(ctx, msg.Name).IsAllGT(msg.Bid) {
return sdk.ErrInsufficientCoins("Bid not high enough").Result() // If not, throw an error
}
if keeper.HasOwner(ctx, msg.Name) {
Expand Down
3 changes: 1 addition & 2 deletions x/nameservice/keeper.go
Expand Up @@ -7,7 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

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

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

2 changes: 1 addition & 1 deletion x/nameservice/querier.go
Expand Up @@ -38,7 +38,7 @@ func queryResolve(ctx sdk.Context, path []string, req abci.RequestQuery, keeper
return []byte{}, sdk.ErrUnknownRequest("could not resolve name")
}

res, err := codec.MarshalJSONIndent(keeper.cdc, QueryResResolve{value})
res, err := codec.MarshalJSONIndent(keeper.cdc, QueryResResolve{Value: value})
if err != nil {
panic("could not marshal result to JSON")
}
Expand Down
2 changes: 1 addition & 1 deletion x/nameservice/types/errors.go
Expand Up @@ -12,4 +12,4 @@ const (

func ErrNameDoesNotExist(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeNameDoesNotExist, "Name does not exist")
}
}