Msg 和 Handler
现在你已经设置了Keeper,是时候构建允许用户购买域名和设置解析值的Msg和Handler了。
Msg
Msg触发状态转变。Msgs被包裹在客户端提交至网络的Txs中。Cosmos SDK从Txs中打包和解包来自Msgs,这就意味着,作为一个应用开发者,你只需要去定义Msgs。Msgs必须要满足下面的接口(我们会在下一小节实现):
// 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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Handler
Handler定义了在接收到一个特定Msg时,需要采取的操作(哪些存储需要更新,怎样更新及要满足什么条件)。
在此模块中,你有两种类型的Msg,用户可以发送这些Msg来和应用程序状态进行交互:SetName和BuyName。它们各自同其Handler关联。