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

Function path_to_rest_map_and_params

plugins/rest-plugin/src/shared.rs:88–135  ·  view source on GitHub ↗
(
    plugin: &Plugin<PluginState>,
    path: &str,
    http_method: &http::Method,
)

Source from the content-addressed store, hash-verified

86}
87
88pub fn path_to_rest_map_and_params(
89 plugin: &Plugin<PluginState>,
90 path: &str,
91 http_method: &http::Method,
92) -> Result<(ClnrestMap, serde_json::Map<String, serde_json::Value>), AppError> {
93 let mut rpc_params = serde_json::Map::new();
94 let dynamic_paths = plugin.state().dyn_router.lock().unwrap();
95 if let Ok(dyn_path) = dynamic_paths.at(path) {
96 for (name, value) in dyn_path.params.iter() {
97 rpc_params.insert(name.to_owned(), serde_json::Value::String(value.to_owned()));
98 }
99 if let Some(clnrest_map) = dyn_path.value.get(http_method) {
100 return Ok((clnrest_map.to_owned(), rpc_params));
101 }
102 return Err(AppError::MethodNotAllowed(RpcError {
103 code: Some(-32601),
104 message: format!("Dynamic path: {path} has no http_method:{http_method} registered"),
105 data: None,
106 }));
107 }
108 if let Some((prefix, suffix)) = path.split_once("v1/") {
109 if !prefix.is_empty() {
110 return Err(AppError::NotFound(RpcError {
111 code: Some(-32601),
112 message: "Path invalid, version missing for CLN methods".to_owned(),
113 data: None,
114 }));
115 }
116 if http_method != http::Method::POST {
117 return Err(AppError::MethodNotAllowed(RpcError {
118 code: Some(-32601),
119 message: "Path invalid, http_method must be POST for CLN methods".to_owned(),
120 data: None,
121 }));
122 }
123 let clnrest_map = ClnrestMap {
124 rpc_method: suffix.to_owned(),
125 rune_required: true,
126 rune_restrictions: None,
127 };
128 return Ok((clnrest_map, rpc_params));
129 }
130 Err(AppError::NotFound(RpcError {
131 code: Some(-32601),
132 message: "Path not found".to_owned(),
133 data: None,
134 }))
135}
136
137pub fn filter_json(value: &mut serde_json::Value) {
138 match value {

Callers 1

call_rpc_methodFunction · 0.85

Calls 5

StringClass · 0.85
stateMethod · 0.80
unwrapMethod · 0.45
insertMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected