Low-level API to call the rpc. An interesting choice of `R` and `P` is [`serde_json::Value`] because it allows ad-hoc calls to custom RPC-methods If you are using a model such as [`crate::model::requests::GetinfoRequest`] you'd probably want to use [`Self::call_typed`] instead. Example: ```no_run use cln_rpc::ClnRpc; use cln_rpc::model::{requests::GetinfoRequest, responses::GetinfoResponse, res
(&mut self, method: &str, params: &P)
| 169 | /// }) |
| 170 | /// ``` |
| 171 | pub async fn call_raw<R, P>(&mut self, method: &str, params: &P) -> Result<R, RpcError> |
| 172 | where |
| 173 | P: Serialize + Debug, |
| 174 | R: DeserializeOwned + Debug, |
| 175 | { |
| 176 | trace!("Sending request {} with params {:?}", method, ¶ms); |
| 177 | let id = self.next_id.fetch_add(1, Ordering::SeqCst); |
| 178 | |
| 179 | // TODO: Can we make this nicer |
| 180 | // I don't want to have this json_rpc : 2.0 floating everywhere |
| 181 | let req = serde_json::json!({ |
| 182 | "jsonrpc" : "2.0", |
| 183 | "id" : id, |
| 184 | "method" : method, |
| 185 | "params" : params, |
| 186 | }); |
| 187 | |
| 188 | let response: serde_json::Value = self.call_raw_request(req).await?; |
| 189 | |
| 190 | serde_json::from_value(response).map_err(|e| RpcError { |
| 191 | code: None, |
| 192 | message: format!("Failed to parse response {:?}", e), |
| 193 | data: None, |
| 194 | }) |
| 195 | } |
| 196 | |
| 197 | /// A low level method to call raw requests |
| 198 | /// |