Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExcludedPallets per Grouping #15

Open
4meta5 opened this issue Oct 2, 2024 · 1 comment
Open

ExcludedPallets per Grouping #15

4meta5 opened this issue Oct 2, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@4meta5
Copy link
Collaborator

4meta5 commented Oct 2, 2024

Requirements include:

  1. a list of pallets configurable per pallet grouping that are excluded from their expansion
  2. the list must be no_std (no strings)

code from #1, may or may not be useful:

use frame_support::traits::Contains;
use sp_std::vec;
use sp_std::vec::Vec;

pub trait ExampleConfig {
    type ExcludedPallets: Contains<Vec<u8>>;
}

pub struct ExcludedPallets;
impl Contains<Vec<u8>> for ExcludedPallets {
    fn contains(i: &Vec<u8>) -> bool {
        vec!["frame_support".as_bytes().to_vec()].contains(&i)
    }
}

impl ExampleConfig for () {
    type ExcludedPallets = ExcludedPallets;
}

#[macro_export]
macro_rules! impl_for_runtime {
    ($pallet:ident, $t:ty) => {
        $crate::maybe_impl_config!($pallet, $t);
    };
}

#[macro_export]
macro_rules! maybe_impl_config {
    ($pallet_name:ident, $t:ty) => {{
        let config: Vec<u8> = stringify!($pallet_name).as_bytes().to_vec();
        let excluded = <<$t as ExampleConfig>::ExcludedPallets as ::frame_support::traits::Contains<_>>::contains(&config);
        if !excluded {
            $crate::impl_config!(pallet_timestamp)
        } else {
            //"EXCLUDED SUCCESSFULLY"
            {}
        }
    }};
}

#[macro_export]
macro_rules! impl_config {
    (pallet_timestamp) => {
        impl pallet_timestamp::Config for Runtime {
            type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>;
            /// A timestamp: milliseconds since the unix epoch.
            type Moment = u64;
            type OnTimestampSet = Aura;
            /// Rerun benchmarks if you are making changes to runtime configuration.
            type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
        }
    };
}
@4meta5
Copy link
Collaborator Author

4meta5 commented Oct 17, 2024

The problem with this approach is that control flow is not that well supported in declarative macros; haven't found it easy to conditionally implement traits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 🗒 Backlog
Development

No branches or pull requests

1 participant