3

I'm trying to create a pallet that handles extrinsic and also runtime-api for the RPC endpoints. Since I plan to query storage items with RPC, I've created primitives for my pallet to use within my pallet and RPC.

I've taken a look at the Beefy Pallet and its primitives. I've implemented the code for my use case but got a bunch of errors about encodes and decodes.

I see that Beefy doesn't implement the traits specified in the error messages. Do I have to implement those? What causes these errors?

// ./profile/common/src/lib.rs

#[derive(Decode, Encode, Debug, PartialEq, Clone, TypeInfo)]
pub struct About<Hash> {
    pub option_one: Option<Vec<u8>>,
    pub option_two: Hash,
}
// ./profile/src/lib.rs

use pallet_profile_primitives::About;

...

#[pallet::storage]
#[pallet::getter(fn validator_set_id)]
pub(super) type ValidatorSetId<T: Config> = StorageValue<_, About<T::Hash>, OptionQuery>;
error[E0277]: the trait bound `About: WrapperTypeDecode` is not satisfied
  --> pallets/estatetial/profile/src/lib.rs:27:12
   |
27 |     #[pallet::pallet]
   |               ^^^^^^ the trait `WrapperTypeDecode` is not implemented for `About`
   |
   = note: required because of the requirements on the impl of `Decode` for `About`
   = note: required because of the requirements on the impl of `FullCodec` for `About`
   = note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageValidatorSetId<T>, About<<T as frame_system::Config>::Hash>>`

error[E0277]: the trait bound `About: EncodeLike` is not satisfied
  --> pallets/estatetial/profile/src/lib.rs:27:12
   |
27 |     #[pallet::pallet]
   |               ^^^^^^ the trait `EncodeLike` is not implemented for `About`
   |
   = note: required because of the requirements on the impl of `FullEncode` for `About`
   = note: required because of the requirements on the impl of `FullCodec` for `About`
   = note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageValidatorSetId<T>, About<<T as frame_system::Config>::Hash>>`

error[E0277]: the trait bound `About: WrapperTypeEncode` is not satisfied
  --> pallets/estatetial/profile/src/lib.rs:27:12
   |
27 |     #[pallet::pallet]
   |               ^^^^^^ the trait `WrapperTypeEncode` is not implemented for `About`
   |
   = note: required because of the requirements on the impl of `Encode` for `About`
   = note: required because of the requirements on the impl of `FullEncode` for `About`
   = note: required because of the requirements on the impl of `FullCodec` for `About`
   = note: required because of the requirements on the impl of `PartialStorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageValidatorSetId<T>, About<<T as frame_system::Config>::Hash>>`
5
  • what versions of substrate are you using? are they the same as you are using as an example? and uniform for your project?
    – Nuke
    Commented Mar 4, 2022 at 18:51
  • Also why look at Beefy, and not another pallet exactly?
    – Nuke
    Commented Mar 4, 2022 at 18:52
  • I'm on the devhub/latest tag. Yes, they are all the same. And, I just found a solution. Will post it here soon. Thanks for the comment.
    – Burak
    Commented Mar 4, 2022 at 21:41
  • 1
    Glad you figured this out! FYI if you are looking to be a parachain, Bounded Vec is the way to go, as it's required for parachains to have bounded storage items (base Vec is unbounded) - this then should not be annotated as such. paritytech.github.io/substrate/master/frame_support/storage/…
    – Nuke
    Commented Mar 5, 2022 at 4:40
  • Noticed that when MaxEncodedLen is required for Vec. Also, using WeakBoundedVec might be a workaround in my opinion.
    – Burak
    Commented Mar 5, 2022 at 6:39

1 Answer 1

0

I was looking through Substrate Frames and noticed that the frames using Vec<u8> have a macro #[pallet::without_storage_info].

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
pub struct Pallet<T>(_);
#[derive(Encode, Decode, Default, Clone, PartialEq, sp_core::RuntimeDebug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct About<Hash> {
    pub option_one: Option<Vec<u8>>,
    pub option_two: Hash,
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.