]> git.bitcoin.ninja Git - rust-lightning/commitdiff
f - Unwrap inside DirectedChannelInfoWithUpdate
authorJeffrey Czyz <jkczyz@gmail.com>
Mon, 31 Jan 2022 21:00:33 +0000 (15:00 -0600)
committerJeffrey Czyz <jkczyz@gmail.com>
Mon, 31 Jan 2022 21:11:26 +0000 (15:11 -0600)
lightning/src/routing/network_graph.rs
lightning/src/routing/router.rs

index ee0ca48a1647230fbe04606c87bef400e00c5926..ff95b5d5995c22a50a15c84ccf4a85991b685f0d 100644 (file)
@@ -756,10 +756,17 @@ pub(super) struct DirectedChannelInfoWithUpdate<'a: 'b, 'b> {
 }
 
 impl<'a: 'b, 'b> DirectedChannelInfoWithUpdate<'a, 'b> {
-       /// Returns the underlying [`DirectedChannelInfo`].
-       pub(super) fn inner(&self) -> &DirectedChannelInfo<'a, 'b> {
-               &self.inner
-       }
+       /// Returns information for the channel.
+       #[inline]
+       pub(super) fn channel(&self) -> &'a ChannelInfo { &self.inner.channel }
+
+       /// Returns information for the direction.
+       #[inline]
+       pub(super) fn direction(&self) -> &'b ChannelUpdateInfo { self.inner.direction.unwrap() }
+
+       /// Returns the [`EffectiveCapacity`] of the channel in the direction.
+       #[inline]
+       pub(super) fn effective_capacity(&self) -> EffectiveCapacity { self.inner.effective_capacity() }
 }
 
 /// The effective capacity of a channel for routing purposes.
index 671b4a12764fa6579f39f1e26b9ef3b31af9ed21..835fc91c99a9bc46f8dcb97d4dd80d49ba84982b 100644 (file)
@@ -376,7 +376,7 @@ impl<'a> CandidateRouteHop<'a> {
        fn features(&self) -> ChannelFeatures {
                match self {
                        CandidateRouteHop::FirstHop { details } => details.counterparty.features.to_context(),
-                       CandidateRouteHop::PublicHop { info, .. } => info.inner().channel().features.clone(),
+                       CandidateRouteHop::PublicHop { info, .. } => info.channel().features.clone(),
                        CandidateRouteHop::PrivateHop { .. } => ChannelFeatures::empty(),
                }
        }
@@ -384,9 +384,7 @@ impl<'a> CandidateRouteHop<'a> {
        fn cltv_expiry_delta(&self) -> u32 {
                match self {
                        CandidateRouteHop::FirstHop { .. } => 0,
-                       CandidateRouteHop::PublicHop { info, .. } => {
-                               info.inner().direction().unwrap().cltv_expiry_delta as u32
-                       },
+                       CandidateRouteHop::PublicHop { info, .. } => info.direction().cltv_expiry_delta as u32,
                        CandidateRouteHop::PrivateHop { hint } => hint.cltv_expiry_delta as u32,
                }
        }
@@ -394,9 +392,7 @@ impl<'a> CandidateRouteHop<'a> {
        fn htlc_minimum_msat(&self) -> u64 {
                match self {
                        CandidateRouteHop::FirstHop { .. } => 0,
-                       CandidateRouteHop::PublicHop { info, .. } => {
-                               info.inner().direction().unwrap().htlc_minimum_msat
-                       },
+                       CandidateRouteHop::PublicHop { info, .. } => info.direction().htlc_minimum_msat,
                        CandidateRouteHop::PrivateHop { hint } => hint.htlc_minimum_msat.unwrap_or(0),
                }
        }
@@ -406,7 +402,7 @@ impl<'a> CandidateRouteHop<'a> {
                        CandidateRouteHop::FirstHop { .. } => RoutingFees {
                                base_msat: 0, proportional_millionths: 0,
                        },
-                       CandidateRouteHop::PublicHop { info, .. } => info.inner().direction().unwrap().fees,
+                       CandidateRouteHop::PublicHop { info, .. } => info.direction().fees,
                        CandidateRouteHop::PrivateHop { hint } => hint.fees,
                }
        }
@@ -416,7 +412,7 @@ impl<'a> CandidateRouteHop<'a> {
                        CandidateRouteHop::FirstHop { details } => EffectiveCapacity::ExactLiquidity {
                                liquidity_msat: details.outbound_capacity_msat,
                        },
-                       CandidateRouteHop::PublicHop { info, .. } => info.inner().effective_capacity(),
+                       CandidateRouteHop::PublicHop { info, .. } => info.effective_capacity(),
                        CandidateRouteHop::PrivateHop { .. } => EffectiveCapacity::Infinite,
                }
        }