【问题标题】:the trait `parity_scale_codec::Encode` is not implemented for `std::collections::BTreeMap<u128, T>`没有为 `std::collections::BTreeMap<u128, T>` 实现特征 `parity_scale_codec::Encode`
【发布时间】:2021-12-02 07:39:22
【问题描述】:

这是我的结构:

#[derive(PartialEq, Eq, PartialOrd, Ord, Default, Clone, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct SortitionSumTree<AccountId> {
    pub k: u128,
    pub stack: Vec<u128>,
    pub nodes: Vec<u128>,
    pub ids_to_tree_indexes: BTreeMap<AccountId, u128>,
    pub node_indexes_to_ids: BTreeMap<u128, AccountId>,
}

我的存储空间:

#[pallet::storage]
#[pallet::getter(fn sortition_sum_trees)]
pub type SortitionSumTrees<T> = StorageMap<_, Blake2_128Concat, Vec<u8>, SortitionSumTree<T>>;

但它给出的错误:

特征 parity_scale_codec::Encode 未针对 std::collections::BTreeMap&lt;u128, T&gt; 实现

【问题讨论】:

    标签: substrate polkadot


    【解决方案1】:

    你需要使用这个:

    #[pallet::getter(fn sortition_sum_trees)]
    pub type SortitionSumTrees<T> = StorageMap<
      _, 
      Blake2_128Concat,
      Vec<u8>,
      SortitionSumTree<T::AccountId>
    >;
    

    确保在SortitionSumTree&lt;T::AccountId&gt; 中使用T::AccountId

    【讨论】:

      猜你喜欢
      • 2017-12-05
      • 1970-01-01
      • 2020-03-24
      • 1970-01-01
      • 1970-01-01
      • 2018-05-24
      • 2021-07-06
      • 1970-01-01
      相关资源
      最近更新 更多