A low level method to call raw requests This method is private by intention. The caller is (implicitly) providing the `id` of the JsonRpcRequest. This is dangerous because the caller might pick a non-unique id. The request should serialize to a valid JsonRpcMessage. If the response is succesful the content of the "result" field is returned If the response is an error the content of the "error" f
(
&mut self,
request: serde_json::Value,
)
| 222 | /// ``` |
| 223 | /// |
| 224 | async fn call_raw_request( |
| 225 | &mut self, |
| 226 | request: serde_json::Value, |
| 227 | ) -> Result<serde_json::Value, RpcError> |
| 228 | where { |
| 229 | trace!("Sending request {:?}", request); |
| 230 | self.write.send(request).await.map_err(|e| RpcError { |
| 231 | code: None, |
| 232 | message: format!("Error passing request to lightningd: {}", e), |
| 233 | data: None, |
| 234 | })?; |
| 235 | |
| 236 | let mut response: serde_json::Value = self |
| 237 | .read |
| 238 | .next() |
| 239 | .await |
| 240 | .ok_or_else(|| RpcError { |
| 241 | code: None, |
| 242 | message: "no response from lightningd".to_string(), |
| 243 | data: None, |
| 244 | })? |
| 245 | .map_err(|_| RpcError { |
| 246 | code: None, |
| 247 | message: "reading response from socket".to_string(), |
| 248 | data: None, |
| 249 | })?; |
| 250 | |
| 251 | match response.get("result") { |
| 252 | Some(_) => Ok(response["result"].take()), |
| 253 | None => { |
| 254 | let _ = response.get("error").ok_or( |
| 255 | RpcError { |
| 256 | code : None, |
| 257 | message : "Invalid response from lightningd. Neither `result` or `error` field is present".to_string(), |
| 258 | data : None |
| 259 | })?; |
| 260 | let rpc_error: RpcError = serde_json::from_value(response["error"].take()) |
| 261 | .map_err(|e| RpcError { |
| 262 | code: None, |
| 263 | message: format!( |
| 264 | "Invalid response from lightningd. Failed to parse `error`. {:?}", |
| 265 | e |
| 266 | ), |
| 267 | data: None, |
| 268 | })?; |
| 269 | Err(rpc_error) |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | pub async fn call(&mut self, req: Request) -> Result<Response, RpcError> { |
| 275 | self.call_enum(req).await |