substrate icon indicating copy to clipboard operation
substrate copied to clipboard

Make construct_runtime macro more flexible

Open arrudagates opened this issue 2 years ago • 5 comments

Usually the assumptions made by the construct_runtime macro are correct and help keep the runtime boilerplate free, but sometimes it's desirable to override the implementations generated by the macro.

In my case, for example, I want to override the implementation of From<Origin> for Result<RawOrigin<AccountId>, Origin> so I can allow my custom origins to pass through the default ensure_signed assertions in most pallets' calls.

I would like to propose and get feedback/suggestions on how to make the construct_runtime macro more flexible, while still maintaining the minimum amount of boilerplate. The solution I currently have in mind is probably not the best possible, thus I'd like to brainstorm solutions.

I'll preface this with a note that I'm not super knowledgeable in Rust macros, so I'm not sure if this is possible to implement like this, but here's what I had in mind:

construct_runtime!(
    pub enum Runtime where
        Block = Block,
        NodeBlock = opaque::Block,
        UncheckedExtrinsic = UncheckedExtrinsic
    {
        System: frame_system::{Pallet, Call, Config, Storage, Event<T>} = 0,
        [...]
    }

    // Anything implemented manually here won't get generated by the macro automatically and instead will be passed through. 
    impl From<Origin> for Result<System::Origin, Origin> {
        // impl here
    }

Perhaps we could even break down the implementations from construct_runtime into multiple macros (like impl_call, impl_origin, etc...) and these could be used by themselves or if the runtime does not require any special implementations, we could have the overarching construct_runtime calling these within itself if they are declared in the macro.

arrudagates avatar Jan 13 '23 14:01 arrudagates