@@ -39,7 +39,7 @@ use crate::ln::msgs;
3939use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError};
4040use crate::ln::script::{self, ShutdownScript};
4141use crate::ln::channel_state::{ChannelShutdownState, CounterpartyForwardingInfo, InboundHTLCDetails, InboundHTLCStateDetails, OutboundHTLCDetails, OutboundHTLCStateDetails};
42- use crate::ln::channelmanager::{self, PendingHTLCStatus, HTLCSource, SentHTLCId, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentClaimDetails, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
42+ use crate::ln::channelmanager::{self, OpenChannelMessage, PendingHTLCStatus, HTLCSource, SentHTLCId, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentClaimDetails, BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA, MAX_LOCAL_BREAKDOWN_TIMEOUT};
4343use crate::ln::chan_utils::{
4444 CounterpartyCommitmentSecrets, TxCreationKeys, HTLCOutputInCommitment, htlc_success_tx_weight,
4545 htlc_timeout_tx_weight, make_funding_redeemscript, ChannelPublicKeys, CommitmentTransaction,
@@ -1242,6 +1242,43 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
12421242 ChannelPhase::UnfundedV2(_) => false,
12431243 }
12441244 }
1245+
1246+ pub fn maybe_get_open_channel<L: Deref>(
1247+ &mut self, chain_hash: ChainHash, logger: &L,
1248+ ) -> Option<OpenChannelMessage> where L::Target: Logger {
1249+ match self {
1250+ ChannelPhase::Funded(_) => None,
1251+ ChannelPhase::UnfundedOutboundV1(chan) => {
1252+ let logger = WithChannelContext::from(logger, &chan.context, None);
1253+ chan.get_open_channel(chain_hash, &&logger)
1254+ .map(|msg| OpenChannelMessage::V1(msg))
1255+ },
1256+ ChannelPhase::UnfundedInboundV1(_) => {
1257+ // Since unfunded inbound channel maps are cleared upon disconnecting a peer,
1258+ // they are not persisted and won't be recovered after a crash.
1259+ // Therefore, they shouldn't exist at this point.
1260+ debug_assert!(false);
1261+ None
1262+ },
1263+ #[cfg(dual_funding)]
1264+ ChannelPhase::UnfundedV2(chan) => {
1265+ if chan.context.is_outbound() {
1266+ Some(OpenChannelMessage::V2(chan.get_open_channel_v2(chain_hash)))
1267+ } else {
1268+ // Since unfunded inbound channel maps are cleared upon disconnecting a peer,
1269+ // they are not persisted and won't be recovered after a crash.
1270+ // Therefore, they shouldn't exist at this point.
1271+ debug_assert!(false);
1272+ None
1273+ }
1274+ },
1275+ #[cfg(not(dual_funding))]
1276+ ChannelPhase::UnfundedV2(_) => {
1277+ debug_assert!(false);
1278+ None
1279+ },
1280+ }
1281+ }
12451282}
12461283
12471284/// Contains all state common to unfunded inbound/outbound channels.
0 commit comments