(
args: serde_json::Value,
)
| 6 | use crate::structs::{CheckRuneParams, ClnrestMap}; |
| 7 | |
| 8 | pub fn parse_register_path_args( |
| 9 | args: serde_json::Value, |
| 10 | ) -> Result<(String, http::Method, ClnrestMap), anyhow::Error> { |
| 11 | let (path_input, http_method, clnrest_map) = match args { |
| 12 | serde_json::Value::Array(args_arr) => { |
| 13 | let path_input = args_arr |
| 14 | .first() |
| 15 | .ok_or_else(|| anyhow!("path is required"))? |
| 16 | .as_str() |
| 17 | .ok_or_else(|| anyhow!("path must be a string"))? |
| 18 | .to_owned(); |
| 19 | let rpc_method = args_arr |
| 20 | .get(1) |
| 21 | .ok_or_else(|| anyhow!("rpc_method is required"))? |
| 22 | .as_str() |
| 23 | .ok_or_else(|| anyhow!("rpc_method must be a string"))? |
| 24 | .to_owned(); |
| 25 | let http_method = if let Some(h) = args_arr.get(2) { |
| 26 | http::Method::from_str( |
| 27 | &h.as_str() |
| 28 | .ok_or_else(|| anyhow!("http_method must be a string"))? |
| 29 | .to_ascii_uppercase(), |
| 30 | )? |
| 31 | } else { |
| 32 | http::Method::POST |
| 33 | }; |
| 34 | let rune_required = if let Some(r) = args_arr.get(3) { |
| 35 | r.as_bool() |
| 36 | .ok_or_else(|| anyhow!("rune_required must be a boolean"))? |
| 37 | } else { |
| 38 | true |
| 39 | }; |
| 40 | let rune_restrictions: Option<CheckRuneParams> = if let Some(r) = args_arr.get(4) { |
| 41 | Some(serde_json::from_value(r.clone())?) |
| 42 | } else { |
| 43 | None |
| 44 | }; |
| 45 | let clnrest_map = ClnrestMap { |
| 46 | rpc_method, |
| 47 | rune_required, |
| 48 | rune_restrictions, |
| 49 | }; |
| 50 | (path_input, http_method, clnrest_map) |
| 51 | } |
| 52 | serde_json::Value::Object(map) => { |
| 53 | let path_input = map |
| 54 | .get("path") |
| 55 | .ok_or_else(|| anyhow!("path is required"))? |
| 56 | .as_str() |
| 57 | .ok_or_else(|| anyhow!("path must be a string"))? |
| 58 | .to_owned(); |
| 59 | let rpc_method = map |
| 60 | .get("rpc_method") |
| 61 | .ok_or_else(|| anyhow!("rpc_method is required"))? |
| 62 | .as_str() |
| 63 | .ok_or_else(|| anyhow!("rpc_method must be a string"))? |
| 64 | .to_owned(); |
| 65 | let http_method = if let Some(h) = map.get("http_method") { |
no test coverage detected