Skip to content

Commit 26b8ea9

Browse files
committed
Expose list_peers to bindings
1 parent 291a36f commit 26b8ea9

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ interface Node {
4747
[Throws=NodeError]
4848
Invoice receive_variable_amount_payment([ByRef]string description, u32 expiry_secs);
4949
PaymentInfo? payment_info([ByRef]PaymentHash payment_hash);
50+
sequence<PublicKey> list_peers();
5051
};
5152

5253
[Error]

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,14 @@ impl Node {
11761176
pub fn payment_info(&self, payment_hash: &PaymentHash) -> Option<PaymentInfo> {
11771177
self.payment_store.get(payment_hash)
11781178
}
1179+
1180+
/// List node's connected peers.
1181+
pub fn list_peers(&self) -> Vec<PublicKey> {
1182+
self.peer_manager.get_peer_node_ids()
1183+
.iter()
1184+
.map(|(pubkey, _)| *pubkey)
1185+
.collect::<Vec<_>>()
1186+
}
11791187
}
11801188

11811189
async fn connect_peer_if_necessary(

src/tests/functional_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ fn channel_full_cycle() {
183183
let node_b_addr = format!("{}@{}", node_b.node_id(), node_b.listening_address().unwrap());
184184
node_a.connect_open_channel(&node_b_addr, 50000, true).unwrap();
185185

186+
assert_eq!(node_a.list_peers(), [node_b.node_id()]);
187+
186188
let funding_txo = loop {
187189
let details = node_a.list_channels();
188190

0 commit comments

Comments
 (0)