瀏覽代碼

rpc: Add Clone implementation for structs, and use untagged enum.

parazyd 4 年之前
父節點
當前提交
a8941a7045
共有 2 個文件被更改,包括 8 次插入7 次删除
  1. 7 6
      src/rpc/jsonrpc.rs
  2. 1 1
      src/rpc/rpcserver.rs

+ 7 - 6
src/rpc/jsonrpc.rs

@@ -44,14 +44,15 @@ impl ErrorCode {
     }
 }
 
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Deserialize)]
+#[serde(untagged)]
 pub enum JsonResult {
     Resp(JsonResponse),
     Err(JsonError),
     Notif(JsonNotification),
 }
 
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Deserialize, Clone, Debug)]
 pub struct JsonRequest {
     pub jsonrpc: Value,
     pub method: Value,
@@ -59,27 +60,27 @@ pub struct JsonRequest {
     pub id: Value,
 }
 
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Deserialize, Clone, Debug)]
 pub struct JsonErrorVal {
     pub code: Value,
     pub message: Value,
 }
 
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Deserialize, Clone, Debug)]
 pub struct JsonError {
     pub jsonrpc: Value,
     pub error: JsonErrorVal,
     pub id: Value,
 }
 
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Deserialize, Clone, Debug)]
 pub struct JsonResponse {
     pub jsonrpc: Value,
     pub result: Value,
     pub id: Value,
 }
 
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Deserialize, Clone, Debug)]
 pub struct JsonNotification {
     pub jsonrpc: Value,
     pub method: Value,

+ 1 - 1
src/rpc/rpcserver.rs

@@ -94,7 +94,7 @@ async fn serve(
 
                 let reply = rh.handle_request(r).await;
                 let j = serde_json::to_string(&reply).unwrap();
-                debug!(target: "RPC", "<-- {:?}", j);
+                debug!(target: "RPC", "<-- {}", j);
 
                 if let Err(e) = stream.write_all(j.as_bytes()).await {
                     debug!(target: "RPC SERVER", "Failed to write to socket: {:#?}", e);