@@ -650,44 +650,19 @@ pub struct ChannelInfo {
650
650
}
651
651
652
652
impl ChannelInfo {
653
- /// Returns a [`DirectedChannelInfo`] for the channel from `source` to `target`.
654
- ///
655
- /// # Panics
656
- ///
657
- /// Panics if `source` and `target` are not the channel's counterparties.
658
- pub fn as_directed ( & self , source : & NodeId , target : & NodeId ) -> DirectedChannelInfo {
659
- let ( direction, source, target) = {
660
- if source == & self . node_one && target == & self . node_two {
661
- ( self . one_to_two . as_ref ( ) , & self . node_one , & self . node_two )
662
- } else if source == & self . node_two && target == & self . node_one {
663
- ( self . two_to_one . as_ref ( ) , & self . node_two , & self . node_one )
664
- } else if source != & self . node_one && source != & self . node_two {
665
- panic ! ( "Unknown source node: {:?}" , source)
666
- } else if target != & self . node_one && target != & self . node_two {
667
- panic ! ( "Unknown target node: {:?}" , target)
668
- } else {
669
- unreachable ! ( )
670
- }
671
- } ;
672
- DirectedChannelInfo { channel : self , direction, source, target }
673
- }
674
-
675
- /// Returns a [`DirectedChannelInfo`] for the channel directed to the given `target`.
676
- ///
677
- /// # Panics
678
- ///
679
- /// Panics if `target` is not one of the channel's counterparties.
680
- pub fn directed_to ( & self , target : & NodeId ) -> DirectedChannelInfo {
653
+ /// Returns a [`DirectedChannelInfo`] for the channel directed to the given `target`, or `None`
654
+ /// if `target` is not one of the channel's counterparties.
655
+ pub fn as_directed_to ( & self , target : & NodeId ) -> Option < DirectedChannelInfo > {
681
656
let ( direction, source, target) = {
682
657
if target == & self . node_one {
683
658
( self . two_to_one . as_ref ( ) , & self . node_two , & self . node_one )
684
659
} else if target == & self . node_two {
685
660
( self . one_to_two . as_ref ( ) , & self . node_one , & self . node_two )
686
661
} else {
687
- panic ! ( "Unknown target node: {:?}" , target )
662
+ return None ;
688
663
}
689
664
} ;
690
- DirectedChannelInfo { channel : self , direction, source, target }
665
+ Some ( DirectedChannelInfo { channel : self , direction, source, target } )
691
666
}
692
667
}
693
668
0 commit comments