3

我在运行时模块中定义了以下数据类型

#[derive(Encode, Decode, Clone, PartialEq, Debug)]
pub enum AuctionStatus {
  Ongoing,
  Cancelled,
  ToBeClaimed,
  Closed
}

// This is necessary so that other structs depend on this enum can be encode/decode with default value.
impl Default for AuctionStatus {
  fn default() -> Self { AuctionStatus::Ongoing }
}

#[derive(Encode, Decode, Default, Clone, PartialEq, Debug)]
pub struct Auction<Hash, Balance, Moment, AuctionTx> {
  id: Hash,
  kitty_id: Hash,
  base_price: Balance,
  start_time: Moment,
  end_time: Moment,
  status: AuctionStatus,
  tx: Option<AuctionTx>,
}

#[derive(Encode, Decode, Default, Clone, PartialEq, Debug)]
pub struct AuctionTx<Hash, AccountId, Balance, Moment> {
  auction_id: Hash,
  tx_time: Moment,
  buyer: AccountId,
  tx_price: Balance,
}

现在在 polkadot UI 中,要导入的正确 JSON 类型定义应该是什么?

我尝试了以下但 polkadotUI 仍然说未知类型。

{
  "AuctionStatus": "u32",
  "AuctionTx": {
    "auction_id": "Hash",
    "tx_time": "Moment",
    "buyer": "AccountId",
    "tx_price": "Balance"
  },
  "Auction": {
    "id": "Hash",
    "kitty_id": "Hash",
    "base_price": "Balance",
    "start_time": "Moment",
    "end_time": "Moment",
    "status": "AuctionStatus",
    "tx": "Option<AuctionTx>"
  }
}

更新01

以下是浏览器控制台错误消息:

第一条消息:

Unable to decode storage catAuction.auctions: createType(Auction):: Encoding for input doesn't match output, created 0xa9531feb7f4eb8a888e1eedf72e812e26e32a53a2e379ef79bb2e8f7d883f2462e1cd9ea24d53ce565292a9e56458943554c7c13b6aef70c00079076650bdd8f983a0000000000000000000000000000f6491c5d0000000060ce1e5d00000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 from 0xa9531feb7f4eb8a888e1eedf72e812e26e32a53a2e379ef79bb2e8f7d883f2462e1cd9ea24d53ce565292a9e56458943554c7c13b6aef70c00079076650bdd8f983a0000000000000000000000000000f6491c5d0000000060ce1e5d000000000000

第二条消息:

2019-07-03 14:24:40        RPC-CORE: subscribeStorage (keys: Vec<StorageKey>): StorageChangeSet:: createType(Auction):: Encoding for input doesn't match output, created 0xa9531feb7f4eb8a888e1eedf72e812e26e32a53a2e379ef79bb2e8f7d883f2462e1cd9ea24d53ce565292a9e56458943554c7c13b6aef70c00079076650bdd8f983a0000000000000000000000000000f6491c5d0000000060ce1e5d00000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 from 0xa9531feb7f4eb8a888e1eedf72e812e26e32a53a2e379ef79bb2e8f7d883f2462e1cd9ea24d53ce565292a9e56458943554c7c13b6aef70c00079076650bdd8f983a0000000000000000000000000000f6491c5d0000000060ce1e5d000000000000

不知道这是否有任何帮助......

4

1 回答 1

2

我认为这里的问题是您已将枚举定义为 au32并且它搞砸了解析编码数据。

来自 Polkadot UI 帮助文本:

请注意,这些类型是按照它们在此处出现的顺序注册的。由于上面的 Transaction 需要 TransactionInput 和 TransactionOutput,它是在它们的定义可用之后定义的。(此处不支持循环部门)。对于一个稍微复杂的示例,同时使用类型和枚举,将使用以下内容 -

{
  "SimpleEnum": {
    "_enum": ["One", "Two", "Three"]
  },
  "TypeEnum": {
    "_enum": {
      "One": "u32",
      "Two": "u64",
      "Three": null
    }
  }.
  "MyNumber": "u32",
  "Thing": {
    "count_enum": "SimpleEnum",
    "type_enum": "TypeEnum",
    "counter": "MyNumber",
    "ids": "Vec<AccountId>"
  },
  "ArrayThing": "Vec<Thing>"
}

因此,请尝试正确定义您的枚举,看看是否能解决您的问题。让我知道这是否有帮助。

于 2019-07-03T08:41:39.373 回答