@@ -1243,14 +1243,6 @@ impl<SP: Deref> Channel<SP> where
12431243 }
12441244 }
12451245
1246- pub fn into_unfunded_v2(self) -> Option<PendingV2Channel<SP>> {
1247- if let ChannelPhase::UnfundedV2(channel) = self.phase {
1248- Some(channel)
1249- } else {
1250- None
1251- }
1252- }
1253-
12541246 pub fn signer_maybe_unblocked<L: Deref>(
12551247 &mut self, chain_hash: ChainHash, logger: &L,
12561248 ) -> Option<SignerResumeUpdates> where L::Target: Logger {
@@ -1400,6 +1392,31 @@ impl<SP: Deref> Channel<SP> where
14001392 Err(ChannelError::NotFound("Failed to find corresponding channel".to_owned()))
14011393 }
14021394 }
1395+
1396+ pub fn funding_tx_constructed<L: Deref>(
1397+ &mut self, signing_session: InteractiveTxSigningSession, logger: &L
1398+ ) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
1399+ where
1400+ L::Target: Logger
1401+ {
1402+ let phase = core::mem::replace(&mut self.phase, ChannelPhase::Intermediate);
1403+ if let ChannelPhase::UnfundedV2(chan) = phase {
1404+ let logger = WithChannelContext::from(logger, &chan.context, None);
1405+ match chan.funding_tx_constructed(signing_session, &&logger) {
1406+ Ok((chan, commitment_signed, event)) => {
1407+ self.phase = ChannelPhase::Funded(chan);
1408+ Ok((commitment_signed, event))
1409+ },
1410+ Err((chan, e)) => {
1411+ self.phase = ChannelPhase::UnfundedV2(chan);
1412+ Err(e)
1413+ },
1414+ }
1415+ } else {
1416+ self.phase = phase;
1417+ Err(ChannelError::Warn("Got a tx_complete message with no interactive transaction construction expected or in-progress".to_owned()))
1418+ }
1419+ }
14031420}
14041421
14051422impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>
@@ -2048,8 +2065,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
20482065 }
20492066
20502067 pub fn funding_tx_constructed<L: Deref>(
2051- & mut self, signing_session: &mut InteractiveTxSigningSession, logger: &L
2052- ) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
2068+ mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2069+ ) -> Result<(FundedChannel<SP>, msgs::CommitmentSigned, Option<Event>), (PendingV2Channel<SP>, ChannelError) >
20532070 where
20542071 L::Target: Logger
20552072 {
@@ -2065,7 +2082,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
20652082 (
20662083 "Multiple outputs matched the expected script and value".to_owned(),
20672084 ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2068- )));
2085+ ))).map_err(|e| (self, e)) ;
20692086 }
20702087 output_index = Some(idx as u16);
20712088 }
@@ -2077,7 +2094,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
20772094 (
20782095 "No output matched the funding script_pubkey".to_owned(),
20792096 ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2080- )));
2097+ ))).map_err(|e| (self, e)) ;
20812098 };
20822099 self.context.channel_transaction_parameters.funding_outpoint = Some(outpoint);
20832100 self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
@@ -2092,6 +2109,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
20922109 Err(err) => {
20932110 self.context.channel_transaction_parameters.funding_outpoint = None;
20942111 return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })))
2112+ .map_err(|e| (self, e));
20952113 },
20962114 };
20972115
@@ -2126,7 +2144,24 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
21262144 // Clear the interactive transaction constructor
21272145 self.interactive_tx_constructor.take();
21282146
2129- Ok((commitment_signed, funding_ready_for_sig_event))
2147+ match self.unfunded_context.holder_commitment_point {
2148+ Some(holder_commitment_point) => {
2149+ let funded_chan = FundedChannel {
2150+ context: self.context,
2151+ interactive_tx_signing_session: Some(signing_session),
2152+ holder_commitment_point,
2153+ };
2154+ Ok((funded_chan, commitment_signed, funding_ready_for_sig_event))
2155+ },
2156+ None => {
2157+ Err(ChannelError::close(
2158+ format!(
2159+ "Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
2160+ self.context.channel_id(),
2161+ )))
2162+ .map_err(|e| (self, e))
2163+ },
2164+ }
21302165 }
21312166}
21322167
@@ -9394,19 +9429,6 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
93949429 pub fn get_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
93959430 self.generate_accept_channel_v2_message()
93969431 }
9397-
9398- pub fn into_channel(self, signing_session: InteractiveTxSigningSession) -> Result<FundedChannel<SP>, ChannelError>{
9399- let holder_commitment_point = self.unfunded_context.holder_commitment_point.ok_or(ChannelError::close(
9400- format!("Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
9401- self.context.channel_id())))?;
9402- let channel = FundedChannel {
9403- context: self.context,
9404- interactive_tx_signing_session: Some(signing_session),
9405- holder_commitment_point,
9406- };
9407-
9408- Ok(channel)
9409- }
94109432}
94119433
94129434// Unfunded channel utilities
0 commit comments