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

rpc: Permit JSON-RPC IDs to be non-strings #9341

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions zebra-rpc/src/server/rpc_call_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ impl<'a> RpcServiceT<'a> for FixRpcResponseMiddleware {
let json: serde_json::Value =
serde_json::from_str(response.into_parts().0.as_str())
.expect("response string should be valid json");
let id = json["id"]
.as_str()
.expect("response json should have an id")
.to_string();
let id = match &json["id"] {
serde_json::Value::Null => Some(jsonrpsee::types::Id::Null),
serde_json::Value::Number(n) => {
n.as_u64().map(jsonrpsee::types::Id::Number)
}
serde_json::Value::String(s) => Some(jsonrpsee::types::Id::Str(s.into())),
_ => None,
}
.expect("response json should have an id");

return MethodResponse::error(
jsonrpsee_types::Id::Str(id.into()),
id,
ErrorObject::borrowed(new_error_code, "Invalid params", None),
);
}
Expand Down
Loading