paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.network/
1.68k stars 597 forks source link

Custom default configs using `derive_impl` #4827

Open gupnik opened 1 month ago

gupnik commented 1 month ago

As @kianenigma suggested in this comment, we should be able to provide custom default configs and use derive_impl to share those across runtimes.

The following could be possible way:

pub trait CustomDefaultConfigProvider {
    type RuntimeOrigin;
    type RuntimeCall;
    type RuntimeTask;
}

pub struct CustomDefaultConfig;

#[crate::register_default_impl(CustomDefaultConfig)]
impl CustomDefaultConfigProvider for CustomDefaultConfig {
    #[inject_runtime_type]
    type RuntimeOrigin = ();
    #[inject_runtime_type]
    type RuntimeCall = ();
    #[inject_runtime_type]
    type RuntimeTask = ();
}

struct Runtime;

#[derive_impl(CustomDefaultConfig, no_aggregated_types)
impl Config for Runtime {}

If this works, we should add some documentation (ideally using docify) on how to use it.

kianenigma commented 3 weeks ago

IMO What we foremost need is to be able to use these macros outside of the frame::pallet umbrella.