Rpc Method handler for `lsps-lsps2-getinfo`.
(
p: cln_plugin::Plugin<State>,
v: serde_json::Value,
)
| 137 | |
| 138 | /// Rpc Method handler for `lsps-lsps2-getinfo`. |
| 139 | async fn on_lsps_lsps2_getinfo( |
| 140 | p: cln_plugin::Plugin<State>, |
| 141 | v: serde_json::Value, |
| 142 | ) -> Result<serde_json::Value, anyhow::Error> { |
| 143 | let req: ClnRpcLsps2GetinfoRequest = |
| 144 | serde_json::from_value(v).context("Failed to parse request JSON")?; |
| 145 | debug!( |
| 146 | "Requesting opening fee menu from lsp {} with token {:?}", |
| 147 | req.lsp_id, req.token |
| 148 | ); |
| 149 | |
| 150 | let lsp_id = PublicKey::from_str(&req.lsp_id).context("lsp_id is not a valid public key")?; |
| 151 | |
| 152 | let dir = p.configuration().lightning_dir; |
| 153 | let rpc_path = Path::new(&dir).join(&p.configuration().rpc_file); |
| 154 | let mut cln_client = cln_rpc::ClnRpc::new(rpc_path.clone()).await?; |
| 155 | |
| 156 | let lsp_status = check_peer_lsp_status(&mut cln_client, &req.lsp_id).await?; |
| 157 | |
| 158 | // Fail early: Check that we are connected to the peer. |
| 159 | if !lsp_status.connected { |
| 160 | bail!("Not connected to peer {}", &req.lsp_id); |
| 161 | }; |
| 162 | |
| 163 | // From Blip52: LSPs MAY set the features bit numbered 729 |
| 164 | // (option_supports_lsps)... |
| 165 | // We only log that it is not set but don't fail. |
| 166 | if !lsp_status.has_lsp_feature { |
| 167 | debug!("Peer {} doesn't have the LSP feature bit set.", &req.lsp_id); |
| 168 | } |
| 169 | |
| 170 | // 1. Call lsps2.get_info. |
| 171 | let client = p.state().client(); |
| 172 | match client.get_info(&lsp_id, req.token).await?.as_result() { |
| 173 | Ok(i) => Ok(serde_json::to_value(i)?), |
| 174 | Err(e) => Ok(serde_json::to_value(e)?), |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /// Rpc Method handler for `lsps-lsps2-buy`. |
| 179 | async fn on_lsps_lsps2_buy( |
nothing calls this directly
no test coverage detected