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

Function register_path

plugins/rest-plugin/src/main.rs:210–263  ·  view source on GitHub ↗
(
    plugin: Plugin<PluginState>,
    mut args: serde_json::Value,
)

Source from the content-addressed store, hash-verified

208}
209
210async fn register_path(
211 plugin: Plugin<PluginState>,
212 mut args: serde_json::Value,
213) -> Result<serde_json::Value, anyhow::Error> {
214 filter_json(&mut args);
215
216 let (path_input, http_method, clnrest_map) = parse_register_path_args(args)?;
217
218 if path_input.eq("/") {
219 return Err(anyhow!("Path must not be root"));
220 }
221
222 let path = path_input.trim_matches('/');
223
224 if path.is_empty() {
225 return Err(anyhow!("Path must not be empty"));
226 }
227 if path.contains("{*") {
228 return Err(anyhow!("Wildcards not supported"));
229 }
230
231 let mut dyn_router = plugin.state().dyn_router.lock().unwrap();
232 if let Ok(p) = dyn_router.at_mut(path) {
233 if p.value.contains_key(&http_method) {
234 return Err(anyhow!(
235 "Conflicting path '{}' already exists with http_method: {}",
236 path,
237 http_method,
238 ));
239 }
240
241 p.value.insert(http_method.clone(), clnrest_map.clone());
242 } else {
243 let mut new_map = HashMap::new();
244 new_map.insert(http_method.clone(), clnrest_map.clone());
245 dyn_router.insert(path, new_map)?;
246 }
247
248 log::debug!(
249 "Registered path: {} with http_method: {} to rpc_method: {} with rune_required:{} \
250 and rune_restrictions:{}",
251 path,
252 http_method,
253 clnrest_map.rpc_method,
254 clnrest_map.rune_required,
255 if let Some(restr) = clnrest_map.rune_restrictions {
256 restr.to_string()
257 } else {
258 "{}".to_owned()
259 },
260 );
261
262 Ok(json!({}))
263}
264
265async fn notification_background_task(io: SocketIo, mut receiver: Receiver<serde_json::Value>) {
266 log::debug!("Background task spawned");

Callers

nothing calls this directly

Calls 7

filter_jsonFunction · 0.85
parse_register_path_argsFunction · 0.85
eqMethod · 0.80
containsMethod · 0.80
stateMethod · 0.80
unwrapMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected