MCPcopy Create free account
hub / github.com/ElementsProject/lightning / call_enum

Method call_enum

cln-rpc/src/lib.rs:279–303  ·  view source on GitHub ↗

Performs an rpc-call

(&mut self, req: Request)

Source from the content-addressed store, hash-verified

277
278 /// Performs an rpc-call
279 pub async fn call_enum(&mut self, req: Request) -> Result<Response, RpcError> {
280 trace!("call : Serialize and deserialize request {:?}", req);
281 // A little bit hacky. But serialize the request to get the method name
282 let mut ser = serde_json::to_value(&req).unwrap();
283 let method: String = if let serde_json::Value::String(method) = ser["method"].take() {
284 method
285 } else {
286 panic!("Method should be string")
287 };
288 let params: serde_json::Value = ser["params"].take();
289
290 let response: serde_json::Value = self.call_raw(&method, &params).await?;
291 let response = serde_json::json!({
292 "method" : method,
293 "result" : response
294 });
295
296 // Parse the response
297 // We add the `method` here because the Response-enum uses it to determine the type
298 serde_json::from_value(response).map_err(|e| RpcError {
299 code: None,
300 message: format!("Failed to deserialize response : {}", e),
301 data: None,
302 })
303 }
304
305 /// Performs an rpc-call and performs type-checking.
306 ///

Callers 1

callMethod · 0.80

Calls 2

call_rawMethod · 0.80
unwrapMethod · 0.45

Tested by

no test coverage detected