Add a random per-path CLTV offset for privacy.
[rust-lightning] / lightning / src / routing / network_graph.rs
index 5a84f35c28dd4f1990ef0eda4611c53a139cb615..a5e497bb1cf0f279137fd3f5e923e8972317181d 100644 (file)
@@ -674,6 +674,21 @@ impl ChannelInfo {
                };
                Some((DirectedChannelInfo { channel: self, direction }, source))
        }
+
+       /// Returns a [`DirectedChannelInfo`] for the channel directed from the given `source` to a
+       /// returned `target`, or `None` if `source` is not one of the channel's counterparties.
+       pub fn as_directed_from(&self, source: &NodeId) -> Option<(DirectedChannelInfo, &NodeId)> {
+               let (direction, target) = {
+                       if source == &self.node_one {
+                               (self.one_to_two.as_ref(), &self.node_two)
+                       } else if source == &self.node_two {
+                               (self.two_to_one.as_ref(), &self.node_one)
+                       } else {
+                               return None;
+                       }
+               };
+               Some((DirectedChannelInfo { channel: self, direction }, target))
+       }
 }
 
 impl fmt::Display for ChannelInfo {