Skip to content

Commit

Permalink
some polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
okwme committed Jun 5, 2019
1 parent 6f70e9e commit ff1c725
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
14 changes: 8 additions & 6 deletions tutorial/app-complete.md
@@ -1,6 +1,6 @@
# Import your modules and finish your application

Now that your module is ready, it can be incorporated in the `./app.go` file, along with the other two modules [`auth`](https://godoc.org/github.com/cosmos/cosmos-sdk/x/auth) and [`bank`](https://godoc.org/github.com/cosmos/cosmos-sdk/x/bank):
Now that your module is ready, it can be incorporated in the `./app.go` file, along with the other two modules [`auth`](https://godoc.org/github.com/cosmos/cosmos-sdk/x/auth) and [`bank`](https://godoc.org/github.com/cosmos/cosmos-sdk/x/bank). Let's begin by adding your new nameservice module to the imports:

> _*NOTE*_: Your application needs to import the code you just wrote. Here the import path is set to this repository (`github.com/cosmos/sdk-application-tutorial/x/nameservice`). If you are following along in your own repo you will need to change the import path to reflect that (`github.com/{ .Username }/{ .Project.Repo }/x/nameservice`).
Expand All @@ -22,6 +22,7 @@ import (
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/staking"

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

bam "github.com/cosmos/cosmos-sdk/baseapp"
Expand All @@ -31,6 +32,8 @@ import (
dbm "github.com/tendermint/tendermint/libs/db"
)

const appName = "nameservice"

var (
// default home directories for the application CLI
DefaultCLIHome = os.ExpandEnv("$HOME/.nscli")
Expand All @@ -43,7 +46,7 @@ var (
)
```

Next you need to add the stores' keys as well as the `Keepers` in your `nameServiceApp` struct, and update the constructor accordingly
Next you need to add the stores' keys and the `Keepers` into your `nameServiceApp` struct. Update the constructor in `NewNameServiceApp()` too:

```go
// maintains independent module functionality
Expand All @@ -61,8 +64,6 @@ func init() {
)
}

const appName = "nameservice"

type nameServiceApp struct {
*bam.BaseApp
cdc *codec.Codec
Expand Down Expand Up @@ -120,6 +121,7 @@ func NewNameServiceApp(logger log.Logger, db dbm.DB) *nameServiceApp {
tkeyParams: sdk.NewTransientStoreKey(params.TStoreKey),
keySlashing: sdk.NewKVStoreKey(slashing.StoreKey),
}
}
```

At this point, the constructor still lacks important logic. Namely, it needs to:
Expand Down Expand Up @@ -298,9 +300,9 @@ func NewNameServiceApp(logger log.Logger, db dbm.DB) *nameServiceApp {

> _*NOTE*_: The TransientStore mentioned above is an in-memory implementation of the KVStore for state that is not persisted.
> _*NOTE*_: Pay attention to how the modules are initiated, the order to be exact. Here it started with Auth --> Bank --> Feecollection -->Staking --> Distribution --> Slashing, then the hooks were set for the staking module.
> _*NOTE*_: Pay attention to how the modules are initiated: the order matters! Here the sequence goes Auth --> Bank --> Feecollection --> Staking --> Distribution --> Slashing, then the hooks were set for the staking module. This is because some of these modules depend on others existing before they can be used.
The `initChainer` defines how accounts in `genesis.json` are mapped into the application state on initial chain start. The `ExportAppStateAndValidators` function helps bootstrap the initial state for the application. You don't need to worry too much about either of these for now. We also need to add a few more methods to our app `BeginBlocker, EndBLocker and LoadHeight`.
The `initChainer` defines how accounts in `genesis.json` are mapped into the application state on initial chain start. The `ExportAppStateAndValidators` function helps bootstrap the initial state for the application. You don't need to worry too much about either of these for now. We also need to add a few more methods to our app `BeginBlocker`, `EndBlocker` and `LoadHeight`.

The constructor registers the `initChainer` function, but it isn't defined yet. Go ahead and create it:

Expand Down
23 changes: 12 additions & 11 deletions tutorial/app-init.md
Expand Up @@ -10,26 +10,27 @@ Start by importing the necessary dependencies:
package app

import (
"github.com/tendermint/tendermint/libs/log"
"github.com/cosmos/cosmos-sdk/codec"
"encoding/json"
"os"

"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/auth"

"github.com/cosmos/cosmos-sdk/x/auth/genaccounts"

"github.com/cosmos/cosmos-sdk/x/bank"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/sdk-application-tutorial/x/nameservice"

bam "github.com/cosmos/cosmos-sdk/baseapp"
bam "github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
tlog "github.com/tendermint/tendermint/libs/log"
bam "github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
)
```

Expand Down
2 changes: 1 addition & 1 deletion tutorial/cli.md
Expand Up @@ -250,4 +250,4 @@ Notes on the above code:
- This abstraction allows clients to import the client functionality from your module in a standard way. You will see this when we [build the entrypoints](entrypoint.md)
- There is an [open issue](https://github.com/cosmos/cosmos-sdk/issues/2955) to add the rest functionality (described in the next part of this tutorial) to this interface as well.

### Now your ready to define [the routes that the REST client will use to communicate with your module](rest.md)!
### Now you're ready to define [the routes that the REST client will use to communicate with your module](rest.md)!
4 changes: 2 additions & 2 deletions tutorial/entrypoint.md
Expand Up @@ -284,6 +284,6 @@ Note:
- The code combines the CLI commands from Tendermint, Cosmos-SDK and your Nameservice module.
- The [`cobra` CLI documentation](http://github.com/spf13/cobra) will help with understanding the above code.
- You can see the `ModuleClient` defined earlier in action here.
- Note how the routes are included in the `registerRoutes` function
- Note how the routes are included in the `registerRoutes` function.

### Now that you have your binaries defined its time to deal with [dependency management and build your app](dep.md)!
### Now that you have your binaries defined its time to deal with [dependency management and build your app](gomod.md)!
11 changes: 5 additions & 6 deletions tutorial/genesis.md
@@ -1,4 +1,4 @@
###Genesis
# Genesis

The AppModule interface includes a number of functions for use in initializing and exporting GenesisState for the chain. The `ModuleBasicManager` calls these functions on each module when starting, stopping or exporting the chain. Here is a very basic implementation that you can expand upon.

Expand All @@ -10,10 +10,9 @@ type GenesisState struct {
}
```

Next `x/nameservice/genesis.go` and add the following code:
Go to `x/nameservice/genesis.go` and add the following code:

```go

package nameservice

import (
Expand Down Expand Up @@ -75,8 +74,8 @@ func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState {
A few notes about the above code:

- `ValidateGenesis()` validates the provided genesis state to ensure that expected invariants hold
- `DefaultGenesisState()` used mostly for testing. This provides a minimal GenesisState.
- `InitGenesis()` called on chain start, this function imports genesis state into the keeper.
- `ExportGenesis()` called after stopping the chain, this function loads application state into a GenesisState stuct to later be exported to `genesis.json` alongside data from the other modules.
- `DefaultGenesisState()` is used mostly for testing. This provides a minimal GenesisState.
- `InitGenesis()` is called on chain start, this function imports genesis state into the keeper.
- `ExportGenesis()` is called after stopping the chain, this function loads application state into a GenesisState stuct to later be exported to `genesis.json` alongside data from the other modules.

### Now your module has everything it needs to be [incorporated into your Cosmos SDK application](./app-complete.md)!
8 changes: 3 additions & 5 deletions tutorial/module.md
@@ -1,4 +1,4 @@
### AppModule Interface
# AppModule Interface

The Cosmos SDK provides a standard interface for modules. This [`AppModule`](https://github.com/cosmos/cosmos-sdk/blob/master/types/module.go) interface requires modules to provide a set of methods used by the `ModuleBasicsManager` to incorporate them into your application. First we will scaffold out the interface and implement **some** of its methods. Then we will incorporate our nameservice module alongside `auth` and `bank` into our app.

Expand All @@ -8,8 +8,6 @@ Lets start with adding the following code to `module.go`. We will leave a number

```go



package nameservice

import (
Expand Down Expand Up @@ -84,6 +82,7 @@ func (am AppModule) Route() string {
func (am AppModule) NewHandler() types.Handler {
return NewHandler(am.keeper)
}

func (am AppModule) QuerierRoute() string {
return ModuleName
}
Expand Down Expand Up @@ -111,9 +110,8 @@ func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage {
return ModuleCdc.MustMarshalJSON(gs)
}


```

To see more examples of AppModule implementation, check out some of the other modules in the SDK such as [x/staking](https://github.com/cosmos/cosmos-sdk/blob/master/x/staking/genesis.go)

Next, we need to [implement the genesis-specific methods called above.](./genesis.md)
### Next, we need to [implement the genesis-specific methods called above.](./genesis.md)
4 changes: 2 additions & 2 deletions tutorial/rest.md
@@ -1,6 +1,6 @@
# Nameservice Module Rest Interface

You module can also expose a REST interface to allow programatic access to the module's functionality. To get started create a file to hold the HTTP handlers:
Your module can also expose a REST interface to allow programatic access to the module's functionality. To get started create a file to hold the HTTP handlers:

- `./x/nameservice/client/rest/rest.go`

Expand Down Expand Up @@ -190,4 +190,4 @@ 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.

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

0 comments on commit ff1c725

Please sign in to comment.