(
http_method: http::Method,
Path(path): Path<String>,
headers: axum::http::HeaderMap,
Extension(plugin): Extension<Plugin<PluginState>>,
body: Request<Body>,
)
| 226 | security(("api_key" = [])) |
| 227 | )] |
| 228 | pub async fn call_rpc_method( |
| 229 | http_method: http::Method, |
| 230 | Path(path): Path<String>, |
| 231 | headers: axum::http::HeaderMap, |
| 232 | Extension(plugin): Extension<Plugin<PluginState>>, |
| 233 | body: Request<Body>, |
| 234 | ) -> Result<Response, AppError> { |
| 235 | let rune = headers |
| 236 | .get("rune") |
| 237 | .and_then(|v| v.to_str().ok()) |
| 238 | .map(String::from); |
| 239 | |
| 240 | let request_bytes = match to_bytes(body.into_body(), MAX_BODY_SIZE).await { |
| 241 | Ok(o) => o, |
| 242 | Err(e) => { |
| 243 | if is_body_too_large(&e) { |
| 244 | return Err(AppError::PayloadTooLarge(RpcError { |
| 245 | code: Some(-32600), |
| 246 | data: None, |
| 247 | message: format!( |
| 248 | "Request body exceeds the maximum allowed size of {MAX_BODY_SIZE} bytes" |
| 249 | ), |
| 250 | })); |
| 251 | } |
| 252 | return Err(AppError::InternalServerError(RpcError { |
| 253 | code: Some(-32700), |
| 254 | data: None, |
| 255 | message: format!("Could not read request body: {}", e), |
| 256 | })); |
| 257 | } |
| 258 | }; |
| 259 | |
| 260 | let (mut rest_map, mut rpc_params) = path_to_rest_map_and_params(&plugin, &path, &http_method)?; |
| 261 | |
| 262 | request_body_to_rpc_params( |
| 263 | &mut rpc_params, |
| 264 | &headers, |
| 265 | &rest_map.rpc_method, |
| 266 | request_bytes, |
| 267 | )?; |
| 268 | |
| 269 | fill_rune_restrictions(&mut rest_map, &rpc_params); |
| 270 | |
| 271 | let mut rpc_params_value = json!(rpc_params); |
| 272 | |
| 273 | filter_json(&mut rpc_params_value); |
| 274 | |
| 275 | if rest_map.rune_required || http_method != http::Method::GET { |
| 276 | verify_rune(&plugin, rune, &rest_map.rune_restrictions.unwrap()).await?; |
| 277 | } |
| 278 | |
| 279 | let cln_result = match call_rpc(&plugin, &rest_map.rpc_method, rpc_params_value).await { |
| 280 | Ok(result) => result, |
| 281 | Err(err) => { |
| 282 | if let Some(code) = err.code { |
| 283 | if code == -32601 { |
| 284 | return Err(AppError::NotFound(err)); |
| 285 | } |
nothing calls this directly
no test coverage detected