Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
ldk: list peers and connect peer
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Jul 14, 2023
1 parent 0c06ebd commit 5abba63
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions mint/src/ln/ldk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use cashu_crab::Sha256;
use ldk_node::bitcoin::Network;
use ldk_node::io::SqliteStore;
use ldk_node::lightning_invoice::Invoice;
use ldk_node::PeerDetails;
use ldk_node::{Builder, Config};
use ldk_node::{ChannelDetails, ChannelId, NetAddress};
use ldk_node::{Event, Node};
Expand Down Expand Up @@ -285,11 +286,28 @@ impl LnNodeManager for Ldk {
address: String,
port: u16,
) -> Result<responses::PeerInfo, Error> {
todo!()
let net_addr = NetAddress::from_str(&format!("{}:{}", address, port)).unwrap();

let pubkey = cln_rpc::primitives::PublicKey::from_slice(&public_key.serialize())?;
self.node.connect(pubkey, net_addr, true)?;

let peer_info = responses::PeerInfo {
peer_pubkey: public_key,
connected: true,
};

Ok(peer_info)
}

async fn list_peers(&self) -> Result<Vec<responses::PeerInfo>, Error> {
todo!()
let peers = self
.node
.list_peers()
.iter()
.flat_map(peer_info_from_details)
.collect();

Ok(peers)
}
}

Expand All @@ -312,3 +330,13 @@ fn channel_info_from_details(details: ChannelDetails) -> Result<ChannelInfo, Err
status,
})
}

fn peer_info_from_details(details: &PeerDetails) -> Result<responses::PeerInfo, Error> {
let peer_pubkey =
bitcoin::secp256k1::PublicKey::from_slice(&details.node_id.serialize()).unwrap();

Ok(responses::PeerInfo {
peer_pubkey,
connected: details.is_connected,
})
}

0 comments on commit 5abba63

Please sign in to comment.