Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into aayushijain23/add-n…
Browse files Browse the repository at this point in the history
…ew-msg-type-delete
  • Loading branch information
aayushijain23 committed Jul 18, 2019
2 parents 50341f8 + 680cc25 commit d39bb23
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 48 deletions.
6 changes: 3 additions & 3 deletions tutorial/README.md
Expand Up @@ -35,17 +35,17 @@ Through the course of this tutorial you will create the following files that mak
│   └── rest
│   └── rest.go
├── types
├── codec.go
├── key.go
├── msgs.go
├── querier.go
└── types.go
├── alias.go
├── codec.go
├── genesis.go
├── handler.go
├── keeper.go
├── querier.go
├── module.go
└── geneis.go
└── querier.go

```

Expand Down
12 changes: 6 additions & 6 deletions tutorial/alias.md
Expand Up @@ -2,7 +2,7 @@

Start by creating a `./x/nameservice/alias.go` file. The main reason for having this file is to prevent import cycles. You can read more about import cycles in go here: [Golang import cycles](https://stackoverflow.com/questions/28256923/import-cycle-not-allowed)

First start by import the types folder you have created.
First start by importing the "types" folder you have created.

```go
package nameservice
Expand All @@ -12,9 +12,9 @@ import (
)
```

There are three types of types we will create in the alias.go file.
There are three kinds of types we will create in the alias.go file.

1. A const, this is where you will define imutable variables.
1. a constant, this is where you will define immutable variables.

```go
const (
Expand All @@ -24,7 +24,7 @@ const (
)
```

2. A var, here you will define varibale, like your messages.
2. a variable, which you will define to contain information such as your messages.

```go
var (
Expand All @@ -37,7 +37,7 @@ var (
)
```

3. A type, here you will define the types you have created in the types folder.
3. a type, here you will define the types you have created in the types folder.

```go
type (
Expand All @@ -50,6 +50,6 @@ type (
)
```

Now you have aliased your needed consts, vars, and types. We can move forward with the creation of the module.
Now you have aliased your needed constants, variables, and types. We can move forward with the creation of the module.

### Register your types in the [Amino encoding format next](./codec.md)!
10 changes: 5 additions & 5 deletions tutorial/app-complete.md
Expand Up @@ -38,10 +38,10 @@ var (
// default home directories for the application CLI
DefaultCLIHome = os.ExpandEnv("$HOME/.nscli")

// DefaultNodeHome sets the folder where the applcation data and configuration will be stored
// DefaultNodeHome sets the folder where the application data and configuration will be stored
DefaultNodeHome = os.ExpandEnv("$HOME/.nsd")

// ModuleBasicManager is in charge of setting up basic module elemnets
// ModuleBasicManager is in charge of setting up basic module elements
ModuleBasics = module.NewBasicManager(
genaccounts.AppModuleBasic{},
genutil.AppModuleBasic{},
Expand Down Expand Up @@ -161,9 +161,9 @@ func NewNameServiceApp(logger log.Logger, db dbm.DB) *nameServiceApp {

// The ParamsKeeper handles parameter storage for the application
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams, params.DefaultCodespace)
// Set specific supspaces
// Set specific subspaces
authSubspace := app.paramsKeeper.Subspace(auth.DefaultParamspace)
bankSupspace := app.paramsKeeper.Subspace(bank.DefaultParamspace)
bankSubspace := app.paramsKeeper.Subspace(bank.DefaultParamspace)
stakingSubspace := app.paramsKeeper.Subspace(staking.DefaultParamspace)
distrSubspace := app.paramsKeeper.Subspace(distr.DefaultParamspace)
slashingSubspace := app.paramsKeeper.Subspace(slashing.DefaultParamspace)
Expand All @@ -179,7 +179,7 @@ func NewNameServiceApp(logger log.Logger, db dbm.DB) *nameServiceApp {
// The BankKeeper allows you perform sdk.Coins interactions
app.bankKeeper = bank.NewBaseKeeper(
app.accountKeeper,
bankSupspace,
banksubspace,
bank.DefaultCodespace,
)

Expand Down
4 changes: 2 additions & 2 deletions tutorial/app-init.md
Expand Up @@ -82,10 +82,10 @@ var (
// default home directories for the application CLI
DefaultCLIHome = os.ExpandEnv("$HOME/.nscli")

// DefaultNodeHome sets the folder where the applcation data and configuration will be stored
// DefaultNodeHome sets the folder where the application data and configuration will be stored
DefaultNodeHome = os.ExpandEnv("$HOME/.nsd")

// ModuleBasicManager is in charge of setting up basic module elemnets
// ModuleBasicManager is in charge of setting up basic module elements
ModuleBasics sdk.ModuleBasicManager
)

Expand Down
25 changes: 24 additions & 1 deletion tutorial/build-run.md
Expand Up @@ -72,7 +72,7 @@ and to make sure your genesis file is correct, run:

You can now start `nsd` by calling `nsd start`. You will see logs begin streaming that represent blocks being produced, this will take a couple of seconds.

Open another terminal to run commands against the network you have just created:
You have run your first node successfully.

```bash
# First check the accounts to ensure they have funds
Expand Down Expand Up @@ -105,3 +105,26 @@ nscli query nameservice whois jack.id
```

### Congratulations, you have built a Cosmos SDK application! This tutorial is now complete. If you want to see how to run the same commands using the REST server [click here](run-rest.md).


# Run second node on another machine (Optional)
Open terminal to run commands against that just created to install nsd and nscli
## init use another moniker and same namechain
```bash
nsd init <moniker-2> --chain-id namechain
```

## overwrite ~/.nsd/config/genesis.json with first node's genesis.json

## change persistent_peers
```bash
vim /.nsd/config/config.toml
persistent_peers = "id@firt_node_ip:26656"
run "nscli status" on first node to get id.
```

## start this second node
```bash
nsd start
```

20 changes: 10 additions & 10 deletions tutorial/cn/15-build-run.md
Expand Up @@ -2,7 +2,7 @@

## 编译`nameservice`应用

要在此仓库中编译nameservice应用程序以查看功能,首先需要安装 **Go 1.12.1** 或更高版本。
要在此仓库中编译 nameservice 应用程序以查看功能,首先需要安装 **Go 1.12.1** 或更高版本。

如果从未用过 `go mod`,需要先添加几个环境变量。

Expand Down Expand Up @@ -32,16 +32,16 @@ nscli help

> 注意:在下面的命令中,使用终端来提取地址。你也可以只是输入创建密钥时保存的原始字符串,如下所示。这些命令需要在你的机器上安装[`jq`](https://stedolan.github.io/jq/download/)
> 注意:如果你之前已经运行过该教程,则可以从头开始使用`nsd unsafe-reset-all`或删除home文件夹下的两个执行程序的数据及配置文件夹`rm -rf~ / .ns *`
> 注意:如果你之前已经运行过该教程,则可以从头开始使用`nsd unsafe-reset-all`或删除 home 文件夹下的两个执行程序的数据及配置文件夹`rm -rf ~/.ns *`
> 注意:如果你的 Cosmos 应用需要使用 ledger,使用命令 `nscli keys add jack` 创建 key 时需要在后面添加 ---ledger 参数。只要这样就可以了。当对交易进行签名时。jack 会被自动识别为由 ledger 生成的 key,进而请求 ledger 设备。
```bash
# Initialize configuration files and genesis file
nsd init --chain-id namechain

# Copy the `Address` output here and save it for later use
# [optional] add "--ledger" at the end to use a Ledger Nano S
# Copy the `Address` output here and save it for later use
# [optional] add "--ledger" at the end to use a Ledger Nano S
nscli keys add jack

# Copy the `Address` output here and save it for later use
Expand All @@ -64,14 +64,14 @@ nscli config trust-node true

```bash
# First check the accounts to ensure they have funds
nscli query account $(nscli keys show jack -a)
nscli query account $(nscli keys show alice -a)
nscli query account $(nscli keys show jack -a)
nscli query account $(nscli keys show alice -a)

# Buy your first name using your coins from the genesis file
nscli tx nameservice buy-name jack.id 5nametoken --from jack
nscli tx nameservice buy-name jack.id 5nametoken --from jack

# Set the value for the name you just bought
nscli tx nameservice set-name jack.id 8.8.8.8 --from jack
nscli tx nameservice set-name jack.id 8.8.8.8 --from jack

# Try out a resolve query against the name you registered
nscli query nameservice resolve jack.id
Expand All @@ -82,7 +82,7 @@ nscli query nameservice whois jack.id
# > {"value":"8.8.8.8","owner":"cosmos1l7k5tdt2qam0zecxrx78yuw447ga54dsmtpk2s","price":[{"denom":"nametoken","amount":"5"}]}

# Alice buys name from jack
nscli tx nameservice buy-name jack.id 10nametoken --from alice
nscli tx nameservice buy-name jack.id 10nametoken --from alice
```

### 恭喜,您已经构建了一个Cosmos SDK应用程序! 本教程现已完成。 如果要查看如何使用REST服务器运行相同的命令,请[单击此处](./16-run-rest.md)
### 恭喜,您已经构建了一个 Cosmos SDK 应用程序! 本教程现已完成。 如果要查看如何使用 REST 服务器运行相同的命令,请[单击此处](./16-run-rest.md)
32 changes: 21 additions & 11 deletions tutorial/gomod.md
Expand Up @@ -7,15 +7,20 @@ Help users build your application by writing a `./Makefile` in the root director
> _*NOTE*_: The below Makefile contains some of same commands as the Cosmos SDK and Tendermint Makefiles.
```makefile
all: install
all: lint install

install: go.sum
GO111MODULE=on go install -tags "$(build_tags)" ./cmd/nsd
GO111MODULE=on go install -tags "$(build_tags)" ./cmd/nscli
go install -mod=readonly $(BUILD_FLAGS) ./cmd/nsd
go install -mod=readonly $(BUILD_FLAGS) ./cmd/nscli

go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify

lint:
golangci-lint run
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
go mod verify
```

### How about including Ledger Nano S support?
Expand Down Expand Up @@ -56,16 +61,21 @@ endif

```makefile
include Makefile.ledger

all: install
all: lint install

install: go.sum
GO111MODULE=on go install -tags "$(build_tags)" ./cmd/nsd
GO111MODULE=on go install -tags "$(build_tags)" ./cmd/nscli
go install -mod=readonly $(BUILD_FLAGS) ./cmd/nsd
go install -mod=readonly $(BUILD_FLAGS) ./cmd/nscli

go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify
@echo "--> Ensure dependencies have not been modified"
GO111MODULE=on go mod verify

lint:
golangci-lint run
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
go mod verify

```

## `go.mod`
Expand Down
2 changes: 1 addition & 1 deletion tutorial/key.md
@@ -1,6 +1,6 @@
# Key

Start by creating a key.go file withing in the types folder. Within your key.go file, you will set your keys to be used throughout the creation of the module.
Start by creating a key.go file in the types folder. Within your key.go file, you will set your keys to be used throughout the creation of the module.

Defining the keys that will be used throughout the application helps with writing DRY code.

Expand Down
17 changes: 8 additions & 9 deletions tutorial/rest.md
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/sdk-application-tutorial/x/nameservice/types"

clientrest "github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
Expand All @@ -37,13 +36,13 @@ First, define the REST client interface for your module in a `RegisterRoutes` fu

```go
// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec, storeName string) {
r.HandleFunc(fmt.Sprintf("/%s/names", storeName), namesHandler(cdc, cliCtx, storeName)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/names", storeName), buyNameHandler(cdc, cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/names", storeName), setNameHandler(cdc, cliCtx)).Methods("PUT")
r.HandleFunc(fmt.Sprintf("/%s/names/{%s}", storeName, restName), resolveNameHandler(cdc, cliCtx, storeName)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/names/{%s}/whois", storeName, restName), whoIsHandler(cdc, cliCtx, storeName)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/names", storeName), deleteNameHandler(cdc, cliCtx)).Methods("DELETE")
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, storeName string) {
r.HandleFunc(fmt.Sprintf("/%s/names", storeName), namesHandler(cliCtx, storeName)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/names", storeName), buyNameHandler(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/names", storeName), setNameHandler(cliCtx)).Methods("PUT")
r.HandleFunc(fmt.Sprintf("/%s/names/{%s}", storeName, restName), resolveNameHandler(cliCtx, storeName)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/names/{%s}/whois", storeName, restName), whoIsHandler(cliCtx, storeName)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/names", storeName), deleteNameHandler(cliCtx)).Methods("DELETE")
}
```

Expand Down Expand Up @@ -228,6 +227,6 @@ func deleteNameHandler(cliCtx context.CLIContext) http.HandlerFunc {
Notes on the above code:

- The [`BaseReq`](https://godoc.org/github.com/cosmos/cosmos-sdk/client/utils#BaseReq) contains the basic required fields for making a transaction (which key to use, how to decode it, which chain you are on, etc...) and is designed to be embedded as shown.
- `baseReq.ValidateBasic` and `clientrest.CompleteAndBroadcastTxREST` handle setting the response code for you and therefore you don't need to worry about handling errors or successes when using those functions.
- `baseReq.ValidateBasic` handles setting the response code for you and therefore you don't need to worry about handling errors or successes when using those functions.

### Next its time to augment `nameservice` by implementing the [AppModule interface](./module.md)!

0 comments on commit d39bb23

Please sign in to comment.