3

I have a pallet pallet-a whose StorageItem should be read/written by other pallets. Let's say that StorageItem is

    #[pallet::storage]
    #[pallet::getter(fn get_commitments)]
    pub type Commits<T: Config<I>, I: 'static = ()> = StorageDoubleMap<
        _,
        Blake2_128Concat,
        T::AccountId,
        Blake2_128Concat,
        CommitKey
        Commitment<T::Hash>,
        OptionQuery,
    >;

In a separate pallet, pallet-b(and in the future, when others use this), the functions of this StorageItem, should be accessible under the namespace of one of pallet-b's Config associated types.

I'm trying to accomplish this result by having pallet-b's Config include some associated types that are bound on traits implemented in the instance of pallet-a. As of now, those traits just implement some functions that don't need to be elaborated on here. Just know there are impls for my Pallet for each. E.g. just imagine something like

    impl<T: Config<I>, I: 'static> Reveal<T::AccountId, T::Hash,> for Pallet<T, I> {
        fn does_thing(
            original_hash: T::Hash,
            random_seed: u64,
        ) -> <T as frame_system::Config>::Hash {
// ... implementation
        }

The relevant portion of pallet-b's config trait:

                    /* --snip-- */
type Commitments: Reveal<<Self as frame_system::Config>::AccountId, <Self as frame_system::Config>::Hash>
+ Commit<Self::AccountId, <Self as pallet::Config>::Hash>;
                    /* --snip-- */

And: relevant portion in Config trait implementation in runtime/lib.rs:

                    /* --snip-- */
    type Commitments = Commitments; // instance of our pallet implementing traits above
                    /* --snip-- */

Now, I'd like to be able to invoke functions on StorageItems inside of pallet-b like:

T::Commitments::Commits::<T, I>::contains_key(k1, k2);

But I'm skeptical of the approach based on errors when trying this like: help: use fully-qualified syntax: <<T as pallet::Config>::Commitments as Trait>::RevealWindow.

Bonus: I also tried adding the above-mentioned StorageItem to the trait like

    impl<T: Config<I>, I: 'static> Reveal<T::AccountId, T::Hash,> for Pallet<T, I> {
        type Commits = Commits<T, I>;
                    /* --snip-- */

And in pallet-b:

<<T as pallet::Config>::Commitments as Reveal<T::AccountId, <T as frame_system::Config>::Hash>>::Commits::contains_key(1, 2);

which gives: = note: the following trait bounds were not satisfied: `<<T as pallet::Config>::Commitments as pallet_commitments::Reveal<<T as frame_system::Config>::AccountId, <T as frame_system::Config>::Hash>>::Commits: frame_support::storage::generator::StorageMap<_, _>` which is required by `<<T as pallet::Config>::Commitments as pallet_commitments::Reveal<<T as frame_system::Config>::AccountId, <T as frame_system::Config>::Hash>>::Commits: frame_support::StorageMap<_, _>(Repeating for every type of StorageItem)

I would appreciate any guidance on what I'm trying to accomplish. Can it be done through some particular trait bounds in pallet-b's Config trait, or does it need to be an associated type on the trait in pallet-a? Or is a different approach recommended?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.