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

Resolve JSON RPC 2.0 non-compliance (redo) #3213

Merged

Conversation

WhoNeedszZz
Copy link
Contributor

Currently, the JSON RPC requests and responses are not compliant with the spec as the server only accepts strings.
This change is non-breaking as it simply adds the ability to understand integers as expected.
Any old code continuing to only send string requests will continue to work as before.

Unit tests are included to ensure (de)serialization works on both strings and integers.

Resolves #2149

Currently, the JSON RPC requests and responses are not compliant with the spec as the server only accepts strings.
This change is *non-breaking* as it simply adds the ability to understand integers as expected.
Any old code continuing to only send string requests will continue to work as before.

Unit tests are included to ensure (de)serialization works on both strings and integers.
Copy link
Member

@quentinlesceller quentinlesceller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @WhoNeedszZz. Tested locally and looking good. LGTM.

@antiochp
Copy link
Member

antiochp commented Jan 29, 2020

Not to open a big can of worms but wondering if there is a more serde like way of handling this?

https://serde.rs/impl-deserialize.html#the-visitor-trait

Here is a Visitor that is able to deserialize a primitive i32 from a variety of types.

I think the JsonId wrapper enum is fine for now but it does introduce an additional layer that needs to be explicitly handled each time.

Copy link
Member

@antiochp antiochp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -501,7 +510,7 @@ impl Handler {
// Issue #1159 - use a serde_json Value type to avoid extra quoting
let job_template_value: Value = serde_json::from_str(&job_template_json).unwrap();
let job_request = RpcRequest {
id: String::from("Stratum"),
id: JsonId::StrId(String::from("Stratum")),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my point about an additional explicit layer - we need to remember to wrap values like this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way would be to use the #[serde(with = "secp_ser::string_or_u64")] like grin-wallet does.
https://github.com/mimblewimble/grin-wallet/blob/master/libwallet/src/slate_versions/v3.rs#L60

@quentinlesceller quentinlesceller merged commit b01ab44 into mimblewimble:master Jan 29, 2020
@WhoNeedszZz WhoNeedszZz deleted the #2149-jsonrpc2-compliance branch January 29, 2020 14:51
@antiochp antiochp mentioned this pull request Feb 24, 2020
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 this pull request may close these issues.

Stratum server accepts only string ids
3 participants