正确的 JSON 类型定义与其他结构和枚举的运行时模块结构一起导入
Proper JSON type definition to import with a runtime module struct with other struct and enum
我在运行时模块中定义了以下数据类型
#[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>"
}
}
Update-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
不确定这是否有帮助...
我认为这里的问题是您将枚举定义为 u32
并且它在解析编码数据时搞砸了。
来自 Polkadot UI 帮助文本:
Be aware that the types are registered in the order they appear here.
Since Transaction above requires both TransactionInput and
TransactionOutput it is defined after the definitions for those are
available. (Circular deps are not supported here). For a slightly more
complex example, using both types and enums, the following would be
used -
{
"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>"
}
因此请尝试正确定义您的枚举,看看是否能解决您的问题。让我知道这是否有帮助。
我在运行时模块中定义了以下数据类型
#[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>"
}
}
Update-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
不确定这是否有帮助...
我认为这里的问题是您将枚举定义为 u32
并且它在解析编码数据时搞砸了。
来自 Polkadot UI 帮助文本:
Be aware that the types are registered in the order they appear here. Since Transaction above requires both TransactionInput and TransactionOutput it is defined after the definitions for those are available. (Circular deps are not supported here). For a slightly more complex example, using both types and enums, the following would be used -
{ "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>" }
因此请尝试正确定义您的枚举,看看是否能解决您的问题。让我知道这是否有帮助。