Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only convert struct names to camel case for Call variant structs #412

Merged
merged 3 commits into from
Jan 28, 2022

Conversation

ascjones
Copy link
Contributor

Fixes #410.

Unfortunately there are no tests (yet) for the Call struct codegen from variants so that aspect is not tested here.

@ascjones ascjones merged commit eb266b9 into master Jan 28, 2022
@ascjones ascjones deleted the aj/fix-struct-names branch January 28, 2022 09:28
@fewensa
Copy link
Contributor

fewensa commented Feb 8, 2022

I have a question for there. Why convert struct names to snake case for Call variant structs? This is not rust code style

@ascjones
Copy link
Contributor Author

ascjones commented Feb 8, 2022

Call variants are for a pallet are in snake case, so e.g. Balances::transfer_keep_alive, and from that we create a standalone struct TransferKeepAlive. Technically I think it is called PascalCase with the first letter capitalised but it seems to work that way in heck. Now that I mention it, I think we need to update heck because it is now called to_upper_camel_case: https://docs.rs/heck/latest/heck/trait.ToUpperCamelCase.html

@fewensa
Copy link
Contributor

fewensa commented Feb 8, 2022

Currently, All Call variant structs generated use snake case. it's ugly.

            #[derive(:: subxt :: codec :: Encode, :: subxt :: codec :: Decode, Debug, Clone)]
            pub struct as_multi {
                pub threshold: ::core::primitive::u16,
                pub other_signatories: ::std::vec::Vec<::subxt::sp_core::crypto::AccountId32>,
                pub maybe_timepoint: ::core::option::Option<
                    runtime_types::pallet_multisig::Timepoint<::core::primitive::u32>,
                >,
                pub call: ::std::vec::Vec<::core::primitive::u8>,
                pub store_call: ::core::primitive::bool,
                pub max_weight: ::core::primitive::u64,
            }
            impl ::subxt::Call for as_multi {
                const PALLET: &'static str = "Multisig";
                const FUNCTION: &'static str = "as_multi";
            }
            #[derive(:: subxt :: codec :: Encode, :: subxt :: codec :: Decode, Debug, Clone)]
            pub struct approve_as_multi {
                pub threshold: ::core::primitive::u16,
                pub other_signatories: ::std::vec::Vec<::subxt::sp_core::crypto::AccountId32>,
                pub maybe_timepoint: ::core::option::Option<
                    runtime_types::pallet_multisig::Timepoint<::core::primitive::u32>,
                >,
                pub call_hash: [::core::primitive::u8; 32usize],
                pub max_weight: ::core::primitive::u64,
            }
            impl ::subxt::Call for approve_as_multi {
                const PALLET: &'static str = "Multisig";
                const FUNCTION: &'static str = "approve_as_multi";
            }

@ascjones
Copy link
Contributor Author

ascjones commented Feb 8, 2022

This is a bug, they should be UpperCamelCase

@ascjones
Copy link
Contributor Author

ascjones commented Feb 8, 2022

#441

0623forbidden pushed a commit to DEIPworld/substrate-subxt that referenced this pull request Feb 15, 2022
…itytech#412)

* Only convert struct names to camel case for `Call` variant structs

* Use Cow for transform fn

* Use as_ref
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong struct name after #352 merged
3 participants