Browse Source

rpc: Avoid a panic in TryFrom<&JsonValue> for JsonResponse

parazyd 2 years ago
parent
commit
6da3a4b637
1 changed files with 6 additions and 0 deletions
  1. 6 0
      src/rpc/jsonrpc.rs

+ 6 - 0
src/rpc/jsonrpc.rs

@@ -377,6 +377,12 @@ impl TryFrom<&JsonValue> for JsonResponse {
             ))
             ))
         }
         }
 
 
+        if !map.contains_key("result") {
+            return Err(RpcError::InvalidJson(
+                "Response does not contain valid \"result\" field".to_string(),
+            ))
+        }
+
         Ok(Self {
         Ok(Self {
             jsonrpc: "2.0",
             jsonrpc: "2.0",
             id: *map["id"].get::<f64>().unwrap() as u16,
             id: *map["id"].get::<f64>().unwrap() as u16,