Amiya Behera
Amiya Behera

Reputation: 2270

Error: the trait bound `types::DepartmentDetails: scale_info::TypeInfo` is not satisfied

After upgrading to the latest substrate version, I am getting error:

the trait bound `types::DepartmentDetails: scale_info::TypeInfo` is not satisfied

Here is my storage:

#[pallet::storage]
#[pallet::getter(fn department_profile)]
pub type Department<T> = StorageMap<_, Blake2_128Concat, u128, DepartmentDetails>;

DepartmentDetails is a struct

#[derive(PartialEq, Eq, PartialOrd, Ord, Default, Clone, Encode, Decode, RuntimeDebug)]
pub struct DepartmentDetails {
    pub name: Vec<u8>,
    pub location: Vec<u8>,
    pub details: Vec<u8>,
    pub departmentid: u128,
}

Version:
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-10'
version = '4.0.0-dev'

Upvotes: 0

Views: 183

Answers (1)

gui
gui

Reputation: 516

The storage needs to declare its metadata. To do so it requires the key and value types to implement the trait TypeInfo: https://docs.rs/scale-info/1.0.0/scale_info/trait.TypeInfo.html

In order to implement it easily you can use the derive macro: TypeInfo https://docs.rs/scale-info-derive/1.0.0/scale_info_derive/derive.TypeInfo.html

Usually you add the feature derive to scale_info crate dependencie in order to have this derive macro accessible from scale_info. And then you can write:

#[derive(PartialEq, Eq, PartialOrd, Ord, Default, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)]
pub struct DepartmentDetails {
    pub name: Vec<u8>,
    pub location: Vec<u8>,
    pub details: Vec<u8>,
    pub departmentid: u128,
}

Upvotes: 1

Related Questions