Look-up functions for ReadOnlyNetworkGraph
authorJeffrey Czyz <jkczyz@gmail.com>
Tue, 14 Jun 2022 23:05:25 +0000 (18:05 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Thu, 14 Jul 2022 15:26:42 +0000 (10:26 -0500)
ReadOnlyNetworkGraph uses BTreeMap to store its nodes and channels, but
these data structures are not supported by C bindings. Expose look-up
functions on these maps in lieu of such support.

lightning/src/routing/gossip.rs

index f404e77b2b825ba894e4a193d693eb222cbbf769..1a030e9ddd360b5c27b9a2199d83c0675f0cbbfb 100644 (file)
@@ -1602,6 +1602,11 @@ impl ReadOnlyNetworkGraph<'_> {
                &*self.channels
        }
 
+       /// Returns information on a channel with the given id.
+       pub fn channel(&self, short_channel_id: u64) -> Option<&ChannelInfo> {
+               self.channels.get(&short_channel_id)
+       }
+
        /// Returns all known nodes' public keys along with announced node info.
        ///
        /// (C-not exported) because we have no mapping for `BTreeMap`s
@@ -1609,6 +1614,11 @@ impl ReadOnlyNetworkGraph<'_> {
                &*self.nodes
        }
 
+       /// Returns information on a node with the given id.
+       pub fn node(&self, node_id: &NodeId) -> Option<&NodeInfo> {
+               self.nodes.get(node_id)
+       }
+
        /// 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.