我正在做一个托盘,在切换到它停止构建的最新节点模板之后。这是声明
#[derive(Encode, Decode, Clone)]
pub struct VendorData<T :Config>
{
pub vendor : VendorId,
pub owner_account_id : T::AccountId,
}
impl<T:Config> Default for VendorData<T> {
fn default() -> Self {
Self {
vendor : Default::default(),
owner_account_id : Default::default(),
}
}
}
#[pallet::storage]
pub(super) type Vendors<T: Config> = StorageMap<_, Blake2_128Concat, VendorId, VendorData<T>, ValueQuery>;货物建造错误:
error[E0277]: the trait bound `VendorData<T>: TypeInfo` is not satisfied
...
#[pallet::storage]
^^^^^^^ the trait `TypeInfo` is not implemented for `VendorData<T>`我尝试以不同的方式声明结构,例如添加TypeInfo:
#[derive(Encode, Decode, Default, Eq, PartialEq, TypeInfo)]但每次出现另一个错误,就像这样:
error: cannot find macro `format` in this scope
--> /home/psu/.cargo/git/checkouts/substrate-7e08433d4c370a21/352c46a/primitives/consensus/aura/src/lib.rs:50:3
|
50 | app_crypto!(ed25519, AURA);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: consider importing this macro:
scale_info::prelude::format
= note: this error originates in the macro `$crate::app_crypto_public_common_if_std` (in Nightly builds, run with -Z macro-backtrace for more info)还有另一个存储项不会导致错误。
pub type Cid = Vec<u8>;
#[pallet::storage]
pub(super) type VendorModels<T: Config> = StorageMap<_, Blake2_128Concat, VendorId, Vec<Cid>, ValueQuery>;因此,它似乎仅仅是关于存储VendorData结构。请帮忙,经过几个小时的实验和谷歌搜索我迷路了
更新:在将TypeInfo添加到所有存储结构声明后,托盘将被编译,但会出现许多错误,如下面所示:
error: cannot find macro `format` in this scope
error: cannot find macro `vec` in this scope发布于 2022-01-06 16:03:24
您需要确保所有泛型类型都实现TypeInfo,或者显式跳过这些类型。基于基板中的此示例代码,您可以编写:
#[derive(Encode, Decode, Clone, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct VendorData<T :Config>
{
pub vendor : VendorId,
pub owner_account_id : T::AccountId,
}或者,另一种办法是,下列办法应有效:
#[derive(Encode, Decode, Clone, TypeInfo)]
pub struct VendorData<AccountId>
{
pub vendor : VendorId,
pub owner_account_id : AccountId,
}https://stackoverflow.com/questions/70607968
复制相似问题