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

Notify should allow Obj Params #675

Open
sampaioletti opened this issue Jun 29, 2022 · 0 comments
Open

Notify should allow Obj Params #675

sampaioletti opened this issue Jun 29, 2022 · 0 comments

Comments

@sampaioletti
Copy link

I can't find in the json-rpc 2.0 spec where a notify params can't be objects. Current implementation only allows null or array.

pub fn notify<T: Serialize>(&self, method: &str, args: T) -> RpcResult<()> {
let args =
serde_json::to_value(args).expect("Only types with infallible serialisation can be used for JSON-RPC");
let params = match args {
Value::Array(vec) => Params::Array(vec),
Value::Null => Params::None,
_ => {
return Err(RpcError::Client(
"RPC params should serialize to a JSON array, or null".into(),
))

I believe it should implement the same logic as the call_method implementation above it

pub fn call_method<T: Serialize, R: DeserializeOwned>(
&self,
method: &str,
returns: &str,
args: T,
) -> impl Future<Output = RpcResult<R>> {
let returns = returns.to_owned();
let args =
serde_json::to_value(args).expect("Only types with infallible serialisation can be used for JSON-RPC");
let params = match args {
Value::Array(vec) => Ok(Params::Array(vec)),
Value::Null => Ok(Params::None),
Value::Object(map) => Ok(Params::Map(map)),
_ => Err(RpcError::Client(
"RPC params should serialize to a JSON array, JSON object or null".into(),
)),

I can do a PR if I'm correct in my research.

Wonderful project. Thank you.

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

No branches or pull requests

1 participant