【发布时间】:2019-05-21 22:44:44
【问题描述】:
我正在使用 Substrate Bonds 库 (oo7) 为我的自定义 Substrate 运行时模块生成自定义 UI。
为了在 Substrate UI 中支持我的自定义模块,我需要定义一个自定义类型。我该怎么做?
【问题讨论】:
标签: blockchain substrate
我正在使用 Substrate Bonds 库 (oo7) 为我的自定义 Substrate 运行时模块生成自定义 UI。
为了在 Substrate UI 中支持我的自定义模块,我需要定义一个自定义类型。我该怎么做?
【问题讨论】:
标签: blockchain substrate
oo7 Substrate 库公开了 addCodecTransform() 函数,使您能够定义自定义类型,然后您可以在 UI 中使用这些类型。
例如,给定在您的模块中定义的这个结构:
#[derive(Encode, Decode, Default, Clone, PartialEq)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Kitty<Hash, Balance> {
id: Hash,
dna: Hash,
price: Balance,
gen: u64,
}
您可以进行以下 JavaScript 调用:
addCodecTransform('Kitty<Hash,Balance>', {
id: 'Hash',
dna: 'Hash',
price: 'Balance',
gen: 'u64'
});
如果你在你的应用程序中添加这个constructor() 函数,你可以确保在你依赖的 React 函数需要它之前调用它。
【讨论】: