cosmos主網(wǎng)即將上線庇配,對(duì)文檔做了大量更新剑逃。特地翻譯了一下誉尖,方便小伙伴們閱覽, 之后會(huì)持續(xù)更新
第三章教程:
Msg和Handler
現(xiàn)在你已經(jīng)設(shè)置了Keeper
消返,是時(shí)候構(gòu)建實(shí)際上允許用戶購(gòu)買域名和設(shè)置解析值的Msg
和Handler
了凝果。
Msg
Msg
觸發(fā)狀態(tài)轉(zhuǎn)變郁岩。Msgs
被包裹在客戶端提交至網(wǎng)絡(luò)的Txs
中婿奔。Cosmos SDK從Txs
中打包和解包來(lái)自Msgs
缺狠,這就意味著,作為一個(gè)應(yīng)用開(kāi)發(fā)者萍摊,你只需要去定義Msgs
挤茄。Msgs
必須要滿足下面的接口(我們會(huì)在下一小節(jié)實(shí)現(xiàn)):
// 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
}
Handler
Handler
定義了在接收到一個(gè)特定Msg
時(shí),需要采取的操作(哪些存儲(chǔ)需要更新冰木,怎樣更新及要滿足什么條件)穷劈。
在此模塊中,你有兩種類型的Msg
踊沸,用戶可以發(fā)送這些Msg
來(lái)和應(yīng)用程序狀態(tài)進(jìn)行交互:SetName
和BuyName
歇终。它們各自同其Handler
關(guān)聯(lián)。