特性 `parity_scale_codec::Encode` 没有为 `std::collections::BTreeMap<u128, T>` 实现
the trait `parity_scale_codec::Encode` is not implemented for `std::collections::BTreeMap<u128, T>`
这是我的结构:
#[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<u128, T>
实现
你需要使用这个:
#[pallet::getter(fn sortition_sum_trees)]
pub type SortitionSumTrees<T> = StorageMap<
_,
Blake2_128Concat,
Vec<u8>,
SortitionSumTree<T::AccountId>
>;
确保在 SortitionSumTree<T::AccountId>
.
中使用 T::AccountId
这是我的结构:
#[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<u128, T>
你需要使用这个:
#[pallet::getter(fn sortition_sum_trees)]
pub type SortitionSumTrees<T> = StorageMap<
_,
Blake2_128Concat,
Vec<u8>,
SortitionSumTree<T::AccountId>
>;
确保在 SortitionSumTree<T::AccountId>
.