使用自定义类型(Substrate FRAME pallet + Polkadot/Substrate frontend)

Use custom types (Substrate FRAME pallet + Polkadot/Substrate frontend)

场景:您正在开发一个FRAME pallet for a custom Substrate node that uses custom types within Storage or Events. To interact with your custom Substrate node, you use the Polkadot/Substrate frontend

问题:

  1. 当您查询包含您的自定义类型的存储时,前端returns“未知" 作为
  2. 当您提交一个外部 以包含在一个块中时,应该使用 [=17] 导致事件 的发射=]custom type,Polkadot/Substrate frontend 似乎 stuck 而声明外部是 “准备好”加入区块。但是,情况并非如此,如果您检查应包含外部的块,您会看到以下错误消息:

Unable to retrieve the specified block details. createType(Vec):: Struct: failed on 'data':: Cannot construct unknown type YOUR_CUSTOM_TYPE

解决方案: 您必须在 Polkadot/Substrate 前端指定您的自定义类型。为此,select顶部菜单栏中的“设置”->“开发人员”:

您可以在下方看到标题为“作为 JSON 文件的其他类型”的文本字段。在此文本字段中,您必须为前端输入自定义类型才能正确解释这些类型。在右上角,版本号的正下方,应该可以看到一个灰色圆圈中的白色大问号。单击此问号,将滑入一个帮助对话框。

配置示例:我们以the pallet I learned this lesson with为例。在突出显示的行中,您会看到自定义枚举“States”:

pub enum States {
    Propose,
    VotePropose,
    Concern,
    VoteConcern,
    VoteCouncil,
}

使用帮助对话框(白色问号),结果是正确的配置 JSON 片段如下所示:

"States": {
    "_enum": [
        "Propose",
        "VotePropose",
        "Concern",
        "VoteConcern",
        "VoteCouncil"
    ]
}

现在可以从链上读取元数据,这个问题就不会发生了。