@@ -1248,16 +1248,6 @@ impl<SP: Deref> Channel<SP> where
12481248 }
12491249 }
12501250
1251- pub fn pending_funding(&self) -> &[FundingScope] {
1252- match &self.phase {
1253- ChannelPhase::Undefined => unreachable!(),
1254- ChannelPhase::Funded(chan) => &chan.pending_funding,
1255- ChannelPhase::UnfundedOutboundV1(_) => &[],
1256- ChannelPhase::UnfundedInboundV1(_) => &[],
1257- ChannelPhase::UnfundedV2(_) => &[],
1258- }
1259- }
1260-
12611251 pub fn unfunded_context_mut(&mut self) -> Option<&mut UnfundedChannelContext> {
12621252 match &mut self.phase {
12631253 ChannelPhase::Undefined => unreachable!(),
@@ -1560,6 +1550,25 @@ impl<SP: Deref> Channel<SP> where
15601550 }
15611551 }
15621552 }
1553+
1554+ /// Get the available balances, see [`AvailableBalances`]'s fields for more info.
1555+ /// Doesn't bother handling the
1556+ /// if-we-removed-it-already-but-haven't-fully-resolved-they-can-still-send-an-inbound-HTLC
1557+ /// corner case properly.
1558+ pub fn get_available_balances<F: Deref>(
1559+ &self, fee_estimator: &LowerBoundedFeeEstimator<F>,
1560+ ) -> AvailableBalances
1561+ where
1562+ F::Target: FeeEstimator,
1563+ {
1564+ match &self.phase {
1565+ ChannelPhase::Undefined => unreachable!(),
1566+ ChannelPhase::Funded(chan) => chan.get_available_balances(fee_estimator),
1567+ ChannelPhase::UnfundedOutboundV1(chan) => chan.context.get_available_balances_for_scope(&chan.funding, fee_estimator),
1568+ ChannelPhase::UnfundedInboundV1(chan) => chan.context.get_available_balances_for_scope(&chan.funding, fee_estimator),
1569+ ChannelPhase::UnfundedV2(chan) => chan.context.get_available_balances_for_scope(&chan.funding, fee_estimator),
1570+ }
1571+ }
15631572}
15641573
15651574impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>
@@ -4133,31 +4142,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
41334142 outbound_details
41344143 }
41354144
4136- /// Get the available balances, see [`AvailableBalances`]'s fields for more info.
4137- /// Doesn't bother handling the
4138- /// if-we-removed-it-already-but-haven't-fully-resolved-they-can-still-send-an-inbound-HTLC
4139- /// corner case properly.
4140- pub fn get_available_balances<F: Deref>(
4141- &self, funding: &FundingScope, pending_funding: &[FundingScope],
4142- fee_estimator: &LowerBoundedFeeEstimator<F>,
4143- ) -> AvailableBalances
4144- where
4145- F::Target: FeeEstimator,
4146- {
4147- core::iter::once(funding)
4148- .chain(pending_funding.iter())
4149- .map(|funding| self.get_available_balances_for_scope(funding, fee_estimator))
4150- .reduce(|acc, e| {
4151- AvailableBalances {
4152- inbound_capacity_msat: acc.inbound_capacity_msat.min(e.inbound_capacity_msat),
4153- outbound_capacity_msat: acc.outbound_capacity_msat.min(e.outbound_capacity_msat),
4154- next_outbound_htlc_limit_msat: acc.next_outbound_htlc_limit_msat.min(e.next_outbound_htlc_limit_msat),
4155- next_outbound_htlc_minimum_msat: acc.next_outbound_htlc_minimum_msat.max(e.next_outbound_htlc_minimum_msat),
4156- }
4157- })
4158- .expect("At least one FundingScope is always provided")
4159- }
4160-
41614145 fn get_available_balances_for_scope<F: Deref>(
41624146 &self, funding: &FundingScope, fee_estimator: &LowerBoundedFeeEstimator<F>,
41634147 ) -> AvailableBalances
@@ -4949,7 +4933,7 @@ pub(super) struct DualFundingChannelContext {
49494933// Counterparty designates channel data owned by the another channel participant entity.
49504934pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
49514935 pub funding: FundingScope,
4952- pub(super) pending_funding: Vec<FundingScope>,
4936+ pending_funding: Vec<FundingScope>,
49534937 pub context: ChannelContext<SP>,
49544938 pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
49554939 holder_commitment_point: HolderCommitmentPoint,
@@ -8814,13 +8798,24 @@ impl<SP: Deref> FundedChannel<SP> where
88148798 Ok(Some(res))
88158799 }
88168800
8817- pub fn get_available_balances<F: Deref>(
8801+ pub(super) fn get_available_balances<F: Deref>(
88188802 &self, fee_estimator: &LowerBoundedFeeEstimator<F>,
88198803 ) -> AvailableBalances
88208804 where
88218805 F::Target: FeeEstimator,
88228806 {
8823- self.context.get_available_balances(&self.funding, &self.pending_funding, fee_estimator)
8807+ core::iter::once(&self.funding)
8808+ .chain(self.pending_funding.iter())
8809+ .map(|funding| self.context.get_available_balances_for_scope(funding, fee_estimator))
8810+ .reduce(|acc, e| {
8811+ AvailableBalances {
8812+ inbound_capacity_msat: acc.inbound_capacity_msat.min(e.inbound_capacity_msat),
8813+ outbound_capacity_msat: acc.outbound_capacity_msat.min(e.outbound_capacity_msat),
8814+ next_outbound_htlc_limit_msat: acc.next_outbound_htlc_limit_msat.min(e.next_outbound_htlc_limit_msat),
8815+ next_outbound_htlc_minimum_msat: acc.next_outbound_htlc_minimum_msat.max(e.next_outbound_htlc_minimum_msat),
8816+ }
8817+ })
8818+ .expect("At least one FundingScope is always provided")
88248819 }
88258820
88268821 fn build_commitment_no_status_check<L: Deref>(&mut self, logger: &L) -> ChannelMonitorUpdate where L::Target: Logger {
0 commit comments