-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Use traits to fix and document API between a module and construct runtime. #3907
Comments
Looks like a really awesome direction @thiolliere
I agree with this point |
about inherents we can do:
The final trait woud look like pub trait ModuleInherentCall: ModuleCall {
fn create_inherent(_: &InherentData) -> Option<Self::Call> {
None
}
fn check_inherent(call: &Self::Call, data: &InherentData) -> result::Result<(), Self::Error> {
Err(RuntimeString::from("Default implementation doesn't allow any inherent").into())
}
} |
I already have some ideas to remove the requirement on giving the name of the other module. However, I'm strongly against introducing any associated types to make this possible. This always requires that you as a module author are aware that someone else maybe also wants to use your inherent. |
true, but I prefer having this someone else defined by associated type than by construct_runtime macro but maybe there is other solution. Also a side note currently Babe is checking a precise module implementation, that doesn't work with instantiable modules. |
I think the idea of using trait should still be useful for some places: like for #8743 |
Context
Often people don't really see what is implemented on modules and how output of our macros are used by construct_runtime. Not knowing what information is actually used by the construct_runtime macro makes it difficult to understand what is actually the outer API of a module.
For instance it is not straightforward looking at our macros what are actual information gather into the metadata.
Proposition
One solution would be to use traits to make this module interface documented and more understandable.
This will also improve construct_runtime itself as using those traits implemented by our macros will avoid some type issue (like
Config<T>
versusConfig
with the weird error saying that there is a wrong number of generic parameter for a certain type)As an example we can write the trait
and construct_runtime will just use
<Module as ModuleGenesisConfig>::GenesisConfig
to access the GenesisConfig typeDraft
we can create a new module in srml/support/src/module_interface.rs
Note:
in the draft you can see that GenesisConfig is now mandatory, I think it is fine to have those types mandatory, one can just make an empty implementation here.
But if we prefer to still have this struct optionnally implemented then we can just make some OptionalModuleInterface traits that is also fine
The text was updated successfully, but these errors were encountered: