【问题标题】:Substrate extrinsic complex (struct) types支持外部复杂(结构)类型
【发布时间】:2021-10-14 10:02:22
【问题描述】:

我正在尝试在外部参数声明中使用以下结构:

pub struct PriceUpdate {
    pub source_currency: Vec<u8>,
    pub target_currency: Vec<u8>,
    pub provider: Vec<u8>,
    pub price: i64,
}

这是外部声明:

pub fn new_price(origin: OriginFor<T>, price_update: PriceUpdate) -> DispatchResult {

这会导致编译错误:

^^^^^^^^^^^ the trait `WrapperTypeEncode` is not implemented for `PriceUpdate`

有人可以解释对于复杂类型(例如结构/vecs/vecs 等)的外部参数有什么要求吗?我看过 WrapperTypeEncode 文档https://docs.rs/parity-scale-codec/2.2.0/parity_scale_codec/trait.WrapperTypeEncode.html,但他们没有说明这些信息。

非常感谢!

【问题讨论】:

    标签: substrate extrinsic-parameters


    【解决方案1】:

    简单地从 parity-scale-codec 派生。

    use parity_scale_codec::{Encode, Decode};
    
    #[derive(Encode, Decode)]
    pub struct ...
    

    Extrinsic 是托盘级别的调用。在这里,它解释了调用参数需要这些特征绑定。 https://crates.parity.io/frame_support/attr.pallet.html#call-palletcall-optional

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-15
      • 1970-01-01
      • 2012-06-23
      • 2019-02-17
      • 2016-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多