@@ -870,31 +870,31 @@ impl ChannelInfo {
870870 /// Returns a [`DirectedChannelInfo`] for the channel directed to the given `target` from a
871871 /// returned `source`, or `None` if `target` is not one of the channel's counterparties.
872872 pub fn as_directed_to ( & self , target : & NodeId ) -> Option < ( DirectedChannelInfo , & NodeId ) > {
873- let ( direction, source) = {
873+ let ( direction, source, outbound ) = {
874874 if target == & self . node_one {
875- ( self . two_to_one . as_ref ( ) , & self . node_two )
875+ ( self . two_to_one . as_ref ( ) , & self . node_two , false )
876876 } else if target == & self . node_two {
877- ( self . one_to_two . as_ref ( ) , & self . node_one )
877+ ( self . one_to_two . as_ref ( ) , & self . node_one , true )
878878 } else {
879879 return None ;
880880 }
881881 } ;
882- direction. map ( |dir| ( DirectedChannelInfo :: new ( self , dir) , source) )
882+ direction. map ( |dir| ( DirectedChannelInfo :: new ( self , dir, outbound ) , source) )
883883 }
884884
885885 /// Returns a [`DirectedChannelInfo`] for the channel directed from the given `source` to a
886886 /// returned `target`, or `None` if `source` is not one of the channel's counterparties.
887887 pub fn as_directed_from ( & self , source : & NodeId ) -> Option < ( DirectedChannelInfo , & NodeId ) > {
888- let ( direction, target) = {
888+ let ( direction, target, outbound ) = {
889889 if source == & self . node_one {
890- ( self . one_to_two . as_ref ( ) , & self . node_two )
890+ ( self . one_to_two . as_ref ( ) , & self . node_two , true )
891891 } else if source == & self . node_two {
892- ( self . two_to_one . as_ref ( ) , & self . node_one )
892+ ( self . two_to_one . as_ref ( ) , & self . node_one , false )
893893 } else {
894894 return None ;
895895 }
896896 } ;
897- direction. map ( |dir| ( DirectedChannelInfo :: new ( self , dir) , target) )
897+ direction. map ( |dir| ( DirectedChannelInfo :: new ( self , dir, outbound ) , target) )
898898 }
899899
900900 /// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
@@ -992,24 +992,32 @@ pub struct DirectedChannelInfo<'a> {
992992 direction : & ' a ChannelUpdateInfo ,
993993 htlc_maximum_msat : u64 ,
994994 effective_capacity : EffectiveCapacity ,
995+ /// Outbound from the perspective of `node_one`.
996+ ///
997+ /// If true, the channel is considered to be outbound from `node_one` perspective.
998+ /// If false, the channel is considered to be outbound from `node_two` perspective.
999+ ///
1000+ /// [`ChannelInfo::node_one`]
1001+ /// [`ChannelInfo::node_two`]
1002+ outbound : bool ,
9951003}
9961004
9971005impl < ' a > DirectedChannelInfo < ' a > {
9981006 #[ inline]
999- fn new ( channel : & ' a ChannelInfo , direction : & ' a ChannelUpdateInfo ) -> Self {
1007+ fn new ( channel : & ' a ChannelInfo , direction : & ' a ChannelUpdateInfo , outbound : bool ) -> Self {
10001008 let mut htlc_maximum_msat = direction. htlc_maximum_msat ;
10011009 let capacity_msat = channel. capacity_sats . map ( |capacity_sats| capacity_sats * 1000 ) ;
10021010
10031011 let effective_capacity = match capacity_msat {
10041012 Some ( capacity_msat) => {
10051013 htlc_maximum_msat = cmp:: min ( htlc_maximum_msat, capacity_msat) ;
1006- EffectiveCapacity :: Total { capacity_msat, htlc_maximum_msat : htlc_maximum_msat }
1014+ EffectiveCapacity :: Total { capacity_msat, htlc_maximum_msat }
10071015 } ,
10081016 None => EffectiveCapacity :: AdvertisedMaxHTLC { amount_msat : htlc_maximum_msat } ,
10091017 } ;
10101018
10111019 Self {
1012- channel, direction, htlc_maximum_msat, effective_capacity
1020+ channel, direction, htlc_maximum_msat, effective_capacity, outbound
10131021 }
10141022 }
10151023
@@ -1035,6 +1043,16 @@ impl<'a> DirectedChannelInfo<'a> {
10351043 /// Returns information for the direction.
10361044 #[ inline]
10371045 pub ( super ) fn direction ( & self ) -> & ' a ChannelUpdateInfo { self . direction }
1046+
1047+ /// Returns the `node_id` of the source hop.
1048+ ///
1049+ /// Refers to the `node_id` forwarding the payment to the next hop.
1050+ pub ( super ) fn source ( & self ) -> & ' a NodeId { if self . outbound { & self . channel . node_one } else { & self . channel . node_two } }
1051+
1052+ /// Returns the `node_id` of the target hop.
1053+ ///
1054+ /// Refers to the `node_id` receiving the payment from the previous hop.
1055+ pub ( super ) fn target ( & self ) -> & ' a NodeId { if self . outbound { & self . channel . node_two } else { & self . channel . node_one } }
10381056}
10391057
10401058impl < ' a > fmt:: Debug for DirectedChannelInfo < ' a > {
0 commit comments