【发布时间】:2021-11-08 13:24:08
【问题描述】:
下面的数据结构如何声明类型?
一个产品可以有很多候选人,每个候选人都有股份。但同一候选人可以留在不止一种产品中,具有不同的利害关系。我还需要从候选 ID 中查询权益,并从产品 ID 中查询候选 ID。
#[pallet::storage]
#[pallet::getter(fn governor_group)]
pub type ProductId<T> = StorageMap<_, Blake2_128Concat, ProductId, Vec<CandidateId>>;
#[pallet::storage]
#[pallet::getter(fn candidate_nominee)]
pub type Stakes<T> = StorageMap<_, Blake2_128Concat, CandidateId, Stake>;
在上述代码中,每个候选人只能拥有一个股份。
在基板中不允许嵌套存储映射:
#[pallet::storage]
#[pallet::getter(fn governor_group)]
pub type ProductId<T> = StorageMap<_, Blake2_128Concat, ProductId, Stakes>;
【问题讨论】: