From 18fd22788c326df593f98275ad356e51307cd184 Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Tue, 15 Oct 2024 10:41:12 -0700 Subject: [PATCH] add list_peer_channels to cln --- app/src/api/cln.ts | 4 ++++ app/src/api/cmd.ts | 2 ++ app/src/helpers/cln.ts | 1 + src/cmd.rs | 3 ++- src/conn/cln/mod.rs | 14 ++++++-------- src/handler.rs | 4 ++++ src/setup/mod.rs | 4 +++- 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/src/api/cln.ts b/app/src/api/cln.ts index 66b6eca6..526d55a1 100644 --- a/app/src/api/cln.ts +++ b/app/src/api/cln.ts @@ -23,6 +23,10 @@ export async function list_peers(tag: string) { return await clnCmd("ListPeers", tag); } +export async function list_peer_channels(tag: string) { + return await clnCmd("ListPeerChannels", tag); +} + export async function list_funds(tag: string) { return await clnCmd("ListFunds", tag); } diff --git a/app/src/api/cmd.ts b/app/src/api/cmd.ts index 1e72f5fe..4812384c 100644 --- a/app/src/api/cmd.ts +++ b/app/src/api/cmd.ts @@ -6,6 +6,7 @@ export let root = "/api"; if (IS_DEV) { root = "http://localhost:8000/api"; // root = "https://app.v2.sphinx.chat/api"; + // root = "https://app.router1.sphinx.chat/api"; } const mode = import.meta.env.MODE; @@ -34,6 +35,7 @@ export type Cmd = | "ListChannels" | "AddPeer" | "ListPeers" + | "ListPeerChannels" | "AddChannel" | "GetBalance" | "NewAddress" diff --git a/app/src/helpers/cln.ts b/app/src/helpers/cln.ts index 35cfca9a..1ff47d31 100644 --- a/app/src/helpers/cln.ts +++ b/app/src/helpers/cln.ts @@ -149,6 +149,7 @@ function getChannelStatus(status) { } function convertChannelArrayToObj(peerObj) { + console.log("=>", peerObj); const peers = peerObj.peers; const obj = {}; for (let i = 0; i < peers.length; i++) { diff --git a/src/cmd.rs b/src/cmd.rs index 56ceccaa..de7e46e6 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -151,7 +151,7 @@ pub enum SwarmCmd { UpdateUser(UpdateUserDetails), GetApiToken, SetGlobalMemLimit(u64), - GetSignedInUserDetails + GetSignedInUserDetails, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -251,6 +251,7 @@ pub enum LndCmd { pub enum ClnCmd { GetInfo, ListPeers, + ListPeerChannels, ListFunds, NewAddress, AddPeer(AddPeer), diff --git a/src/conn/cln/mod.rs b/src/conn/cln/mod.rs index 6d27b805..ed564174 100644 --- a/src/conn/cln/mod.rs +++ b/src/conn/cln/mod.rs @@ -116,15 +116,13 @@ impl ClnRPC { pub async fn list_peer_channels( &mut self, - peer_id: Vec, + peer_id: Option>, ) -> Result { - let response = self - .client - .list_peer_channels(pb::ListpeerchannelsRequest { - id: Some(peer_id), - ..Default::default() - }) - .await?; + let mut req = pb::ListpeerchannelsRequest::default(); + if let Some(peer_id) = peer_id { + req.id = Some(peer_id); + } + let response = self.client.list_peer_channels(req).await?; Ok(response.into_inner()) } diff --git a/src/handler.rs b/src/handler.rs index bd5a028e..c89a6a2e 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -536,6 +536,10 @@ pub async fn handle( let info = client.list_peers().await?; Some(serde_json::to_string(&info)?) } + ClnCmd::ListPeerChannels => { + let info = client.list_peer_channels(None).await?; + Some(serde_json::to_string(&info)?) + } ClnCmd::ListFunds => { let funds = client.list_funds().await?; Some(serde_json::to_string(&funds)?) diff --git a/src/setup/mod.rs b/src/setup/mod.rs index 566a89a3..9d3d6112 100644 --- a/src/setup/mod.rs +++ b/src/setup/mod.rs @@ -120,7 +120,9 @@ pub async fn new_chan_from_cln1( let mut ok = false; log::info!("wait for channel to confirm..."); while !ok { - let pc = cln1.list_peer_channels(hex::decode(peer_pubkey)?).await?; + let pc = cln1 + .list_peer_channels(Some(hex::decode(peer_pubkey)?)) + .await?; for c in pc.channels { // println!("{:?}", c.status); if let Some(status) = c.status.get(0) {