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

Function register_path

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

Source from the content-addressed store, hash-verified

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