Skip to content

Commit

Permalink
add list_peer_channels to cln
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Oct 15, 2024
1 parent 1539cca commit 18fd227
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
4 changes: 4 additions & 0 deletions app/src/api/cln.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/api/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,6 +35,7 @@ export type Cmd =
| "ListChannels"
| "AddPeer"
| "ListPeers"
| "ListPeerChannels"
| "AddChannel"
| "GetBalance"
| "NewAddress"
Expand Down
1 change: 1 addition & 0 deletions app/src/helpers/cln.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
3 changes: 2 additions & 1 deletion src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub enum SwarmCmd {
UpdateUser(UpdateUserDetails),
GetApiToken,
SetGlobalMemLimit(u64),
GetSignedInUserDetails
GetSignedInUserDetails,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -251,6 +251,7 @@ pub enum LndCmd {
pub enum ClnCmd {
GetInfo,
ListPeers,
ListPeerChannels,
ListFunds,
NewAddress,
AddPeer(AddPeer),
Expand Down
14 changes: 6 additions & 8 deletions src/conn/cln/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,13 @@ impl ClnRPC {

pub async fn list_peer_channels(
&mut self,
peer_id: Vec<u8>,
peer_id: Option<Vec<u8>>,
) -> Result<pb::ListpeerchannelsResponse> {
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())
}

Expand Down
4 changes: 4 additions & 0 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?)
Expand Down
4 changes: 3 additions & 1 deletion src/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 18fd227

Please sign in to comment.