@@ -39,7 +39,7 @@ use crate::ln::msgs;
39
39
use crate::ln::msgs::{ClosingSigned, ClosingSignedFeeRange, DecodeError};
40
40
use crate::ln::script::{self, ShutdownScript};
41
41
use 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};
43
43
use crate::ln::chan_utils::{
44
44
CounterpartyCommitmentSecrets, TxCreationKeys, HTLCOutputInCommitment, htlc_success_tx_weight,
45
45
htlc_timeout_tx_weight, make_funding_redeemscript, ChannelPublicKeys, CommitmentTransaction,
@@ -1242,6 +1242,43 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
1242
1242
ChannelPhase::UnfundedV2(_) => false,
1243
1243
}
1244
1244
}
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
+ }
1245
1282
}
1246
1283
1247
1284
/// Contains all state common to unfunded inbound/outbound channels.
0 commit comments