[C Bindings] Expose channel and nodes list in `ReadOnlyNetworkGraph` 2022-07-110-java-bindings
authorMatt Corallo <git@bluematt.me>
Fri, 5 Aug 2022 03:20:53 +0000 (03:20 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 5 Aug 2022 21:16:16 +0000 (21:16 +0000)
lightning/src/routing/gossip.rs

index 06c45575970a2ebd5cfe9a82baf584a124b07776..296476b33f7dc830c7e8e2b8d88199887464545d 100644 (file)
@@ -1796,6 +1796,12 @@ impl ReadOnlyNetworkGraph<'_> {
                self.channels.get(&short_channel_id)
        }
 
+       #[cfg(c_bindings)] // Non-bindings users should use `channels`
+       /// Returns the list of channels in the graph
+       pub fn list_channels(&self) -> Vec<u64> {
+               self.channels.keys().map(|c| *c).collect()
+       }
+
        /// Returns all known nodes' public keys along with announced node info.
        ///
        /// (C-not exported) because we have no mapping for `BTreeMap`s
@@ -1808,6 +1814,12 @@ impl ReadOnlyNetworkGraph<'_> {
                self.nodes.get(node_id)
        }
 
+       #[cfg(c_bindings)] // Non-bindings users should use `nodes`
+       /// Returns the list of nodes in the graph
+       pub fn list_nodes(&self) -> Vec<NodeId> {
+               self.nodes.keys().map(|n| *n).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.