Skip to content

Notify should allow Obj Params #675

@sampaioletti

Description

@sampaioletti

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions