Alias

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

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

package nameservice

import (
	"github.com/cosmos/sdk-application-tutorial/x/nameservice/types"
)
1
2
3
4
5

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

  1. a constant, this is where you will define immutable variables.
const (
	ModuleName = types.ModuleName
	RouterKey  = types.RouterKey
	StoreKey   = types.StoreKey
)
1
2
3
4
5
  1. a variable, which you will define to contain information such as your messages.
var (
	NewMsgBuyName = types.NewMsgBuyName
	NewMsgSetName = types.NewMsgSetName
	NewWhois      = types.NewWhois
	ModuleCdc     = types.ModuleCdc
	RegisterCodec = types.RegisterCodec
)
1
2
3
4
5
6
7
  1. a type, here you will define the types you have created in the types folder.
type (
	MsgSetName      = types.MsgSetName
	MsgBuyName      = types.MsgBuyName
	QueryResResolve = types.QueryResResolve
	QueryResNames   = types.QueryResNames
	Whois           = types.Whois
)
1
2
3
4
5
6
7

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!