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

Function check_peer_lsp_status

plugins/lsps-plugin/src/client.rs:769–803  ·  view source on GitHub ↗

Returns the `PeerLspStatus`, containing information about the connectivity and the LSP feature bit.

(
    cln_client: &mut ClnRpc,
    peer_id: &str,
)

Source from the content-addressed store, hash-verified

767/// Returns the `PeerLspStatus`, containing information about the connectivity
768/// and the LSP feature bit.
769async fn check_peer_lsp_status(
770 cln_client: &mut ClnRpc,
771 peer_id: &str,
772) -> Result<PeerLspStatus, anyhow::Error> {
773 let res = cln_client
774 .call_typed(&ListpeersRequest {
775 id: Some(PublicKey::from_str(peer_id)?),
776 level: None,
777 })
778 .await?;
779
780 let peer = match res.peers.first() {
781 None => {
782 return Ok(PeerLspStatus {
783 connected: false,
784 has_lsp_feature: false,
785 });
786 }
787 Some(p) => p,
788 };
789
790 let connected = peer.connected;
791 let has_lsp_feature = if let Some(f_str) = &peer.features {
792 let feature_bits = hex::decode(f_str)
793 .map_err(|e| anyhow!("Invalid feature bits hex for peer {peer_id}, {f_str}: {e}"))?;
794 is_feature_bit_set_reversed(&feature_bits, LSP_FEATURE_BIT)
795 } else {
796 false
797 };
798
799 Ok(PeerLspStatus {
800 connected,
801 has_lsp_feature,
802 })
803}
804
805pub fn gen_rand_preimage_hex<R: Rng + CryptoRng>(rng: &mut R) -> String {
806 let mut pre = [0u8; 32];

Callers 3

on_lsps_lsps2_getinfoFunction · 0.85
on_lsps_lsps2_buyFunction · 0.85
on_lsps_listprotocolsFunction · 0.85

Calls 3

call_typedMethod · 0.80
decodeFunction · 0.50

Tested by

no test coverage detected