paritytech / substrate

Substrate: The platform for blockchain innovators
Apache License 2.0
8.39k stars 2.65k forks source link

Frame: Give Referendum `SubmitOrigin` argument #14326

Closed gavofyork closed 1 year ago

gavofyork commented 1 year ago

When determining whether a submission origin should be allowed, it is useful to be able to inspect the track they are submitting for, since it may be desired to have less-privileged origins be valid for some tracks but not others.

This alters the type bound accordingly. To minimise breakage across the ecosystem, all type bounders in Substrate are updated to support the EnsureOriginWithArg trait as well as the EnsureOrigin trait. To facilitate this support both in Substrate and downstream repos, a macro allowing EnsureOrigin implementors to naively support EnsureOriginWithArg is introduced.

🚨 Code Changes

If you are using Referenda pallet and find a build error around the SubmitOrigin (which is probably a custom origin), then simply wrap the type with frame_support::AsEnsureOriginWithArg to get an EnsureOriginWithArg impl. E.g.

impl pallet_referenda::Config for Runtime {
    type SubmitOrigin = MyEnsureOriginImpl;
    // snip
}

Would become:

impl pallet_referenda::Config for Runtime {
    type SubmitOrigin = frame_support::AsEnsureOriginWithArg<MyEnsureOriginImpl>;
    // snip
}