@@ -870,31 +870,31 @@ impl ChannelInfo {
870
870
/// Returns a [`DirectedChannelInfo`] for the channel directed to the given `target` from a
871
871
/// returned `source`, or `None` if `target` is not one of the channel's counterparties.
872
872
pub fn as_directed_to ( & self , target : & NodeId ) -> Option < ( DirectedChannelInfo , & NodeId ) > {
873
- let ( direction, source) = {
873
+ let ( direction, source, outbound ) = {
874
874
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 )
876
876
} 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 )
878
878
} else {
879
879
return None ;
880
880
}
881
881
} ;
882
- direction. map ( |dir| ( DirectedChannelInfo :: new ( self , dir) , source) )
882
+ direction. map ( |dir| ( DirectedChannelInfo :: new ( self , dir, outbound ) , source) )
883
883
}
884
884
885
885
/// Returns a [`DirectedChannelInfo`] for the channel directed from the given `source` to a
886
886
/// returned `target`, or `None` if `source` is not one of the channel's counterparties.
887
887
pub fn as_directed_from ( & self , source : & NodeId ) -> Option < ( DirectedChannelInfo , & NodeId ) > {
888
- let ( direction, target) = {
888
+ let ( direction, target, outbound ) = {
889
889
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 )
891
891
} 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 )
893
893
} else {
894
894
return None ;
895
895
}
896
896
} ;
897
- direction. map ( |dir| ( DirectedChannelInfo :: new ( self , dir) , target) )
897
+ direction. map ( |dir| ( DirectedChannelInfo :: new ( self , dir, outbound ) , target) )
898
898
}
899
899
900
900
/// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
@@ -992,24 +992,32 @@ pub struct DirectedChannelInfo<'a> {
992
992
direction : & ' a ChannelUpdateInfo ,
993
993
htlc_maximum_msat : u64 ,
994
994
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 ,
995
1003
}
996
1004
997
1005
impl < ' a > DirectedChannelInfo < ' a > {
998
1006
#[ inline]
999
- fn new ( channel : & ' a ChannelInfo , direction : & ' a ChannelUpdateInfo ) -> Self {
1007
+ fn new ( channel : & ' a ChannelInfo , direction : & ' a ChannelUpdateInfo , outbound : bool ) -> Self {
1000
1008
let mut htlc_maximum_msat = direction. htlc_maximum_msat ;
1001
1009
let capacity_msat = channel. capacity_sats . map ( |capacity_sats| capacity_sats * 1000 ) ;
1002
1010
1003
1011
let effective_capacity = match capacity_msat {
1004
1012
Some ( capacity_msat) => {
1005
1013
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 }
1007
1015
} ,
1008
1016
None => EffectiveCapacity :: AdvertisedMaxHTLC { amount_msat : htlc_maximum_msat } ,
1009
1017
} ;
1010
1018
1011
1019
Self {
1012
- channel, direction, htlc_maximum_msat, effective_capacity
1020
+ channel, direction, htlc_maximum_msat, effective_capacity, outbound
1013
1021
}
1014
1022
}
1015
1023
@@ -1035,6 +1043,16 @@ impl<'a> DirectedChannelInfo<'a> {
1035
1043
/// Returns information for the direction.
1036
1044
#[ inline]
1037
1045
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 } }
1038
1056
}
1039
1057
1040
1058
impl < ' a > fmt:: Debug for DirectedChannelInfo < ' a > {
0 commit comments