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

[jsonrpsee types]: provide macro for constructing JsonRpcParams #275

Closed
niklasad1 opened this issue Apr 20, 2021 · 2 comments · Fixed by #496
Closed

[jsonrpsee types]: provide macro for constructing JsonRpcParams #275

niklasad1 opened this issue Apr 20, 2021 · 2 comments · Fixed by #496

Comments

@niklasad1
Copy link
Member

niklasad1 commented Apr 20, 2021

The JsonRpcParams are a little boiler-platy to provide as we require the arguments to be serde_json::Value,

Example:

// MyType doesn't implement `Into<serde_json::Value>`
let x: = MyType { };
let inner: &[JsonValue] = &[0_u32.into(), "hoo".to_string().into(), serde_json::to_value(x).unwrap()];
let params =  JsonRpcParams::ArrayRef(inner);

So it would be nice is to provide a macro such as params_positional! and params_object to avoid that.
Perhaps just provide a wrapper on-top of serde_json::json!?

Note: Copy @kianenigma's stuff.

@dvdplm
Copy link
Contributor

dvdplm commented Jul 14, 2021

Maybe it's possible to unify the client JsonRpcParams with the servers'?

@niklasad1
Copy link
Member Author

niklasad1 commented Jul 14, 2021

Maybe it's possible to unify the client JsonRpcParams with the servers'?

The problem is that the server-side RpcParams is a wrapper over Cow<&str> and is used to deserialize the types within a request and JsonRpcParams is only used to serialize the types.

In order to unify them we would have to explicitly require to that user provide a &str/String for the params such as "[1, 2, "foo"]" which is very annoying in my experience. It could be possible to have that but we would still need some convenience method(s) to convert a Vec<T: serde::Serialize> to &str/String if that's possible to with a macro that would be awesome

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 a pull request may close this issue.

2 participants