mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
Resolve JSON RPC 2.0 non-compliance (#3209)
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.
This commit is contained in:
parent
fb888a32d6
commit
15278021dc
1 changed files with 11 additions and 3 deletions
|
@ -52,9 +52,17 @@ type Tx = mpsc::UnboundedSender<String>;
|
||||||
// http://www.jsonrpc.org/specification
|
// http://www.jsonrpc.org/specification
|
||||||
// RPC Methods
|
// RPC Methods
|
||||||
|
|
||||||
|
/// Represents a compliant JSON RPC 2.0 id.
|
||||||
|
/// Valid id: Integer, String.
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
enum JsonId {
|
||||||
|
NumId(u32),
|
||||||
|
StrId(String),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct RpcRequest {
|
struct RpcRequest {
|
||||||
id: String,
|
id: JsonId,
|
||||||
jsonrpc: String,
|
jsonrpc: String,
|
||||||
method: String,
|
method: String,
|
||||||
params: Option<Value>,
|
params: Option<Value>,
|
||||||
|
@ -62,7 +70,7 @@ struct RpcRequest {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct RpcResponse {
|
struct RpcResponse {
|
||||||
id: String,
|
id: JsonId,
|
||||||
jsonrpc: String,
|
jsonrpc: String,
|
||||||
method: String,
|
method: String,
|
||||||
result: Option<Value>,
|
result: Option<Value>,
|
||||||
|
@ -501,7 +509,7 @@ impl Handler {
|
||||||
// Issue #1159 - use a serde_json Value type to avoid extra quoting
|
// 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_template_value: Value = serde_json::from_str(&job_template_json).unwrap();
|
||||||
let job_request = RpcRequest {
|
let job_request = RpcRequest {
|
||||||
id: String::from("Stratum"),
|
id: JsonId::StrId(String::from("Stratum")),
|
||||||
jsonrpc: String::from("2.0"),
|
jsonrpc: String::from("2.0"),
|
||||||
method: String::from("job"),
|
method: String::from("job"),
|
||||||
params: Some(job_template_value),
|
params: Some(job_template_value),
|
||||||
|
|
Loading…
Reference in a new issue