When building my pallet, I run into the error:
error[E0277]: the trait bound `T: parity_scale_codec::MaxEncodedLen` is not satisfied
--> pallets/template/src/lib.rs:42:15
|
42 | #[pallet::pallet]
| ^^^^^^ the trait `parity_scale_codec::MaxEncodedLen` is not implemented for `T`
|
note: required because of the requirements on the impl of `parity_scale_codec::MaxEncodedLen` for `Kitty<T>`
--> pallets/template/src/lib.rs:25:69
|
25 | #[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
| ^^^^^^^^^^^^^
26 | #[scale_info(skip_type_params(T))]
27 | pub struct Kitty<T: Config> {
| ^^^^^^^^^^^^^^^^
= note: required because of the requirements on the impl of `StorageInfoTrait` for `frame_support::pallet_prelude::StorageMap<_GeneratedPrefixForStorageKitties<T>, frame_support::Twox64Concat, <T as frame_system::Config>::Hash, Kitty<T>>`
= note: this error originates in the derive macro `MaxEncodedLen` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting this bound
|
42 | #[pallet::pallet + parity_scale_codec::MaxEncodedLen]
| +++++++++++++++++++++++++++++++++++
For more information about this error, try `rustc --explain E0277`.
error: could not compile `pallet-template` due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed
The custom type definitions are:
// Struct for holding Kitty information.
#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
#[scale_info(skip_type_params(T))]
pub struct Kitty<T: Config> {
pub dna: [u8; 16], // Using 16 bytes to represent a kitty DNA
pub price: Option<BalanceOf<T>>,
pub gender: Gender,
pub owner: AccountOf<T>,
}
// Enum declaration for Gender.
#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum Gender {
Male,
Female,
}
As far as I know, MaxEncodedLen
should work for Kitty
since all of its fields are also bounded in length.
How do I resolve this issue?