-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Pallet macro: support pallet::extra_constants
renaming
#8826
Comments
Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions. |
This is still useful |
I'll work on this. Might have some questions though. |
Questions:
pub fn expand_constants(def: &mut Def) -> proc_macro2::TokenStream within
Thanks for any help you can provide. |
cc @thiolliere @KiChjang |
Until recently there were only camel case constant, any cases were accepted but the convention was to use camel case. Maybe we should provide a way to rename the constant independently from the function name like:
Or maybe we can automatically convert to camel case in the metadata.
Both declares some constant to be part of the pallet metadata https://substrate.dev/rustdocs/latest/frame_metadata/struct.ModuleMetadata.html#structfield
extra_constant information is https://substrate.dev/rustdocs/latest/frame_support/attr.pallet.html#extra-constants-palletextra_constants-optional
I think by providing a way to rename the constant he meant have some additional syntax which allows to specify the name of the constant. like: #[pallet::extra_constant]
impl<T: Config> Pallet<T> {
#[pallet::constant_name(Foo)]
fn foo() -> u32 {..}
} |
After thinking about this, I like the idea of an inert attribute, as @thiolliere's last example demonstrates. This way, Plus, I don't like convention when you can be explicit. So if a user wants to break away from convention for some reason, that should probably be allowed. And it should be optional, so that if no inert attr is passed, the function name is taken. Let me know if you agree/disagree. I'll put out a PR in the meantime... |
yes I agree, I also think we can make this attribute optional so that we don't break existing pallets |
Added failing tests in draft above. I'll be adding logic to This will, of course, be optional. |
I've updated the draft PR and could use some feedback. I've passed the failed tests, but had to comment the code that explicitly initializes Most of the commented code should work in a final solution to this, but I think perhaps something weird is going on in the tests. |
The syntax for extra constants is as following, where the constants as function name should be snake cases according to Rust naming convention:
But pallet constants are typically camel cased, as defined in old
decl_module
and newpallet::constants
.pallet::extra_constants
should provide a way to rename the constants.The text was updated successfully, but these errors were encountered: