【问题标题】:How do I define a custom type with the oo7 Substrate library?如何使用 oo7 Substrate 库定义自定义类型?
【发布时间】:2019-05-21 22:44:44
【问题描述】:

我正在使用 Substrate Bonds 库 (oo7) 为我的自定义 Substrate 运行时模块生成自定义 UI。

为了在 Substrate UI 中支持我的自定义模块,我需要定义一个自定义类型。我该怎么做?

【问题讨论】:

    标签: blockchain substrate


    【解决方案1】:

    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 函数需要它之前调用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-15
      相关资源
      最近更新 更多