Skip to content

Commit

Permalink
Expose nodes and channels in C bindings
Browse files Browse the repository at this point in the history
ReadOnlyNetworkGraph uses BTreeMap to store its nodes and channels, but
these data structures are not supported by C bindings. Expose them as
Vecs instead.
  • Loading branch information
jkczyz committed Jun 14, 2022
1 parent 22dc964 commit 2d50c17
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lightning/src/routing/gossip.rs
Expand Up @@ -1602,13 +1602,25 @@ impl ReadOnlyNetworkGraph<'_> {
&*self.channels
}

#[cfg(c_bindings)]
/// Returns all known valid channels' short ids along with announced channel info.
pub fn channels_vec(&self) -> Vec<(u64, ChannelInfo)> {
self.channels.iter().map(|(id, info)| (*id, info.clone())).collect()
}

/// Returns all known nodes' public keys along with announced node info.
///
/// (C-not exported) because we have no mapping for `BTreeMap`s
pub fn nodes(&self) -> &BTreeMap<NodeId, NodeInfo> {
&*self.nodes
}

#[cfg(c_bindings)]
/// Returns all known nodes' public keys along with announced node info.
pub fn nodes_vec(&'_ self) -> Vec<(NodeId, NodeInfo)> {
self.nodes.iter().map(|(id, info)| (*id, info.clone())).collect()
}

/// Get network addresses by node id.
/// Returns None if the requested node is completely unknown,
/// or if node announcement for the node was never received.
Expand Down

0 comments on commit 2d50c17

Please sign in to comment.