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

Function on_lsps_listprotocols

plugins/lsps-plugin/src/client.rs:724–760  ·  view source on GitHub ↗
(
    p: cln_plugin::Plugin<State>,
    v: serde_json::Value,
)

Source from the content-addressed store, hash-verified

722}
723
724async fn on_lsps_listprotocols(
725 p: cln_plugin::Plugin<State>,
726 v: serde_json::Value,
727) -> Result<serde_json::Value, anyhow::Error> {
728 #[derive(Deserialize)]
729 struct Request {
730 lsp_id: String,
731 }
732 let dir = p.configuration().lightning_dir;
733 let rpc_path = Path::new(&dir).join(&p.configuration().rpc_file);
734 let mut cln_client = cln_rpc::ClnRpc::new(rpc_path.clone()).await?;
735
736 let req: Request = serde_json::from_value(v).context("Failed to parse request JSON")?;
737 let lsp_id = PublicKey::from_str(&req.lsp_id).context("lsp_id is not a valid public key")?;
738 let lsp_status = check_peer_lsp_status(&mut cln_client, &req.lsp_id).await?;
739
740 // Fail early: Check that we are connected to the peer.
741 if !lsp_status.connected {
742 bail!("Not connected to peer {}", &req.lsp_id);
743 };
744
745 // From Blip52: LSPs MAY set the features bit numbered 729
746 // (option_supports_lsps)...
747 // We only log that it is not set but don't fail.
748 if !lsp_status.has_lsp_feature {
749 debug!("Peer {} doesn't have the LSP feature bit set.", &req.lsp_id);
750 }
751
752 let client = p.state().client();
753 match client.list_protocols(&lsp_id).await?.as_result() {
754 Ok(i) => {
755 debug!("Received lsps0.list_protocols response: {:?}", i);
756 Ok(serde_json::to_value(i)?)
757 }
758 Err(e) => Ok(serde_json::to_value(e)?),
759 }
760}
761
762struct PeerLspStatus {
763 connected: bool,

Callers

nothing calls this directly

Calls 7

check_peer_lsp_statusFunction · 0.85
configurationMethod · 0.80
joinMethod · 0.80
clientMethod · 0.80
stateMethod · 0.80
as_resultMethod · 0.80
list_protocolsMethod · 0.80

Tested by

no test coverage detected