@@ -1243,14 +1243,6 @@ impl<SP: Deref> Channel<SP> where
1243
1243
}
1244
1244
}
1245
1245
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
-
1254
1246
pub fn signer_maybe_unblocked<L: Deref>(
1255
1247
&mut self, chain_hash: ChainHash, logger: &L,
1256
1248
) -> Option<SignerResumeUpdates> where L::Target: Logger {
@@ -1400,6 +1392,31 @@ impl<SP: Deref> Channel<SP> where
1400
1392
Err(ChannelError::NotFound("Failed to find corresponding channel".to_owned()))
1401
1393
}
1402
1394
}
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
+ }
1403
1420
}
1404
1421
1405
1422
impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>
@@ -2048,8 +2065,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2048
2065
}
2049
2066
2050
2067
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) >
2053
2070
where
2054
2071
L::Target: Logger
2055
2072
{
@@ -2065,7 +2082,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2065
2082
(
2066
2083
"Multiple outputs matched the expected script and value".to_owned(),
2067
2084
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2068
- )));
2085
+ ))).map_err(|e| (self, e)) ;
2069
2086
}
2070
2087
output_index = Some(idx as u16);
2071
2088
}
@@ -2077,7 +2094,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2077
2094
(
2078
2095
"No output matched the funding script_pubkey".to_owned(),
2079
2096
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2080
- )));
2097
+ ))).map_err(|e| (self, e)) ;
2081
2098
};
2082
2099
self.context.channel_transaction_parameters.funding_outpoint = Some(outpoint);
2083
2100
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 {
2092
2109
Err(err) => {
2093
2110
self.context.channel_transaction_parameters.funding_outpoint = None;
2094
2111
return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })))
2112
+ .map_err(|e| (self, e));
2095
2113
},
2096
2114
};
2097
2115
@@ -2126,7 +2144,24 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2126
2144
// Clear the interactive transaction constructor
2127
2145
self.interactive_tx_constructor.take();
2128
2146
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
+ }
2130
2165
}
2131
2166
}
2132
2167
@@ -9394,19 +9429,6 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9394
9429
pub fn get_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
9395
9430
self.generate_accept_channel_v2_message()
9396
9431
}
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
- }
9410
9432
}
9411
9433
9412
9434
// Unfunded channel utilities
0 commit comments