美文网首页区块链研习社
Cosmos-- 三.教程 -- 5.Msg和Handler

Cosmos-- 三.教程 -- 5.Msg和Handler

作者: 糙米薏仁汤 | 来源:发表于2019-02-26 15:54 被阅读0次

    cosmos主网即将上线,对文档做了大量更新。特地翻译了一下,方便小伙伴们阅览, 之后会持续更新

    第三章教程:

    1. 开始
    2. 程序目标
    3. 开始编写你的程序
    4. Keeper
    5. Msg和Handler
    6. SetName
    7. BuyName
    8. Querier
    9. Codec文件
    10. Nameservice模块的CLI
    11. nameservice模块的REST接口
    12. 引入你的模块并完成程序
    13. Entrypoint
    14. 编译你的程序
    15. 编译并运行程序
    16. 运行REST路由

    Msg和Handler

    现在你已经设置了Keeper,是时候构建实际上允许用户购买域名和设置解析值的MsgHandler了。

    Msg

    Msg触发状态转变。Msgs被包裹在客户端提交至网络的Txs中。Cosmos SDK从Txs中打包和解包来自Msgs,这就意味着,作为一个应用开发者,你只需要去定义MsgsMsgs必须要满足下面的接口(我们会在下一小节实现):

    // 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定义了在接收到一个特定Msg时,需要采取的操作(哪些存储需要更新,怎样更新及要满足什么条件)。

    在此模块中,你有两种类型的Msg,用户可以发送这些Msg来和应用程序状态进行交互:SetNameBuyName。它们各自同其Handler关联。

    相关文章

      网友评论

        本文标题:Cosmos-- 三.教程 -- 5.Msg和Handler

        本文链接:https://www.haomeiwen.com/subject/ienayqtx.html