1

In the examples I've seen so far I can see that all the [pallet::*] definitions are within the #[frame_support::pallet] module.

Is there any way we can split these into separate modules? For example would it be possible to create a storage.rs module and add the storages there like so

#[pallet::storage]
pub(super) type TotalSupply<T: crate::Config> = StorageValue<_, u64, ValueQuery>;

The issue I'm facing is that I can't seem to find how to import the pallet::storage macro.

5
  • Can you describe what you want to do a bit more concretely and why?
    – Dan Shields
    Jun 29 at 4:53
  • @DanShields I think he wants to have a file (not lib.rs) where he can put all the #[pallet::storage] definitions. I think its not possible, or at least I was not able to do so, but sometimes you can have a lot of storage items, so it would be nice to move everything that is not an extrinsic outside of the lib.rs
    – andresvsm
    Jun 30 at 5:58
  • 2
    Exactly what @andresvsm wrote. Basically have more flexibility in terms of how you want to structure your code base.
    – ppoliani
    Jun 30 at 7:31
  • 1
    @ppoliani Although my lib.rs file is quite big, I have moved out auxiliar functions (the ones that are not under #[pallet::call]), custom data structures, custom enums and of course, tests, mocks and benchmarks. But I'm not sure you can remove things that are declared within the pub mod pallet {...} scope
    – andresvsm
    Jun 30 at 10:34
  • 1
    @andresvsm that's cool. I did the same exact thing as well
    – ppoliani
    Jun 30 at 18:40

1 Answer 1

2
For example would it be possible to create a storage.rs module and add the storages there like so

I think the answer is no. You can't split #[pallet::storage] from pallet module. When you go into the #[frame_support::pallet] macro's expand process, you'll see components in pallet are expanded as the whole.

The source code of expand pallet can be found here.

Your Answer

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

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