-
Notifications
You must be signed in to change notification settings - Fork 176
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
[proc_macro] Support named RPC parameters with naming conventions #920
Comments
To elaborate currently jsonrpsee is using the naming of the variable in the trait and adds it directly as the name of the key of that Object when trying to decode the params. Thus, it's possible to support Ideally, we just try to decode it with the most common naming conventions and if all fails then return InvalidParams. |
Just wondering; why is this feature needed for paritytech/substrate#12544? I can see that we'd want to be able to rename methods from their rust function names, because the new spec has a bit of a mashup of snake and camel case, but it feels a little magical to do as https://github.com/paritytech/jsonrpsee/pull/921/files does and just support two different conventions out of the box. Like, I guess I like the more explicit approach of |
won't work because one might have arbitrary number of params where the naming convention should apply. however, we could also have
I think the spec specifies that the #[rpc(client, server, namespace = "foo")]
pub trait Rpc {
#[method(name = "foo")]
fn hey(param_one: String) -> String;
} The param will only accepted by So folks could actually do: #[rpc(client, server, namespace = "foo")]
pub trait Rpc {
#[method(name = "foo")]
fn hey(paramOne: String) -> String;
} but it will generate a rust compile warning. I'm just a bit concerned about the complexity of the the configurations of the RPC trait but yeye. |
Aah yes it's about param names and not method names! Hmmm; I guess especially since param names are somewhat optional as it is, I think maybe I'm actually ok with your general solution of accepting either casing. It is a bit magical but then they are already optional, so yeah I'm good, ignore me :) |
The RPC server can receive the parameters as named, or unnamed.
The spec does not enforce any naming conventions on those parameters:
The current implementation provides a 1-to-1 match, meaning that the definition of the method / subscription
is driving the deserialization of parameters.
The following form accepts only snake case named parameters.
Suggestion:
The
param_convention
attribute will be applied to each parameter in order to findthe expected name for deserialization.
Note: This applies only to named parameters.
camelCase(one_one) == "oneOne"
- the method expects "oneOne" and "twoTwo" parametersFeature needed for: paritytech/substrate#12544.
The text was updated successfully, but these errors were encountered: