-
Notifications
You must be signed in to change notification settings - Fork 178
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
[types]: ID type instead of serde_json::RawValue #325
Conversation
@@ -157,16 +159,17 @@ impl From<SubscriptionId> for JsonValue { | |||
#[derive(Debug, PartialEq, Clone, Hash, Eq, Deserialize, Serialize)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clone should be cheap as deserialize just borrows the String AFAIU.
Then in the client code we just use Id::Number
for now.
Thus, should never allocate in server at least?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good cleanup here, and good riddance of those *Alloc
types. 👍
@@ -141,12 +141,12 @@ async fn background_task( | |||
let execute = move |tx: &MethodSink, req: JsonRpcRequest| { | |||
if let Some(method) = methods.get(&*req.method) { | |||
let params = RpcParams::new(req.params.map(|params| params.get())); | |||
if let Err(err) = (method)(req.id, params, &tx, conn_id) { | |||
if let Err(err) = (method)(req.id.clone(), params, &tx, conn_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So these clones are cheap then you say?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes 🙏
let err: JsonRpcErrorAlloc = serde_json::from_slice(&body).map_err(Error::ParseError)?; | ||
return Err(Error::Request(err)); | ||
let err: JsonRpcError = serde_json::from_slice(&body).map_err(Error::ParseError)?; | ||
return Err(Error::Request(err.to_string())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I changed the error type to a String in Error::Request
to get rid of the alloc type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I noticed that. I don't think there much else we can do right?
@@ -211,23 +212,27 @@ impl Server { | |||
// Our [issue](https://github.com/paritytech/jsonrpsee/issues/296). | |||
if let Ok(req) = serde_json::from_slice::<JsonRpcRequest>(&body) { | |||
execute(&tx, req); | |||
} else if let Ok(_req) = serde_json::from_slice::<JsonRpcNotification>(&body) { | |||
return Ok::<_, HyperError>(response::ok_response("".into())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
send empty response to notification,
currently we don't care if the method is registered or not (that API is not exposed)
} | ||
} else if let Ok(_batch) = serde_json::from_slice::<Vec<JsonRpcNotification>>(&body) { | ||
return Ok::<_, HyperError>(response::ok_response("".into())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
send empty response to batch notification,
currently we don't care if the method is registered or not (that API is not exposed)
…h/jsonrpsee into na-jsonrpc-types-id-and-params
/// Method | ||
pub method: &'a str, | ||
/// Params. | ||
pub params: JsonRpcNotificationParams<'a>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In another PR; merge JsonRpcNotificationParams
and JsonRpcNotificationParamsNotification
pub struct JsonRpcNotification<'a> { | ||
/// JSON-RPC version. | ||
pub jsonrpc: TwoPointZero, | ||
/// Name of the method to be invoked. | ||
pub method: &'a str, | ||
/// Parameter values of the request. | ||
pub params: JsonRpcNotificationParams<'a>, | ||
#[serde(borrow)] | ||
pub params: Option<&'a RawValue>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In another PR, hopefully merge JsonRpcParams/RpcParams and replace RawValue here,
That's the reason why some de-serialize tests still fail
…h/jsonrpsee into na-jsonrpc-types-id-and-params
http-server/src/tests.rs
Outdated
let response = http_request(req.into(), uri).await.unwrap(); | ||
assert_eq!(response.status, StatusCode::OK); | ||
// Note: this is *not* according to spec. Response should be the empty string, `""`. | ||
assert_eq!(response.body, r#"[{"jsonrpc":"2.0","result":"","id":null},{"jsonrpc":"2.0","result":"","id":null}]"#); | ||
// Note: on HTTP we ack the notification with an empty response. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does ack
mean here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK - acknowledge, maybe it's a bad term ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh makes sense, yea I wouldn't have been able to deduce that. But now that I know what it means I like it. For the general user, it would probably make sense to write out the whole word though in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, After a brief explanation from @niklasad1 I was able to follow along the type changes, and understand the direction of the PR. 👍
Similar should be done on
Params
andJsonRpcNotifParams
to work properly but this PR is large enough as it is.Further info see #292 (comment)