Msgs and Handlers

Now that you have the Keeper setup, it is time to build the Msgs and Handlers that actually allow users to buy names and set values for them.

Msgs

Msgs trigger state transitions. Msgs are wrapped in Txs that clients submit to the network. The Cosmos SDK wraps and unwraps Msgs from Txs, which means, as an app developer, you only have to define Msgs. Msgs must satisfy the following interface (we'll implement all of these in the next section):

// Transactions messages must fulfill the Msg
type Msg interface {
	// Return the message type.
	// Must be alphanumeric or empty.
	Type() string

	// Returns a human-readable string for the message, intended for utilization
	// within tags
	Route() string

	// ValidateBasic does a simple validation check that
	// doesn't require access to any other information.
	ValidateBasic() Error

	// Get the canonical byte representation of the Msg.
	GetSignBytes() []byte

	// Signers returns the addrs of signers that must sign.
	// CONTRACT: All signatures must be present to be valid.
	// CONTRACT: Returns addrs in some deterministic order.
	GetSigners() []AccAddress
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

Handlers

Handlers define the action that needs to be taken (which stores need to get updated, how, and under what conditions) when a given Msg is received.

In this module you have two types of Msgs that users can send to interact with the application state: SetName and BuyName. They will each have an associated Handler.

Now that you have a better understanding of Msgs and Handlers, you can start building your first message: SetName.