@@ -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 {
@@ -1425,6 +1417,31 @@ impl<SP: Deref> Channel<SP> where
1425
1417
1426
1418
debug_assert!(!matches!(self.phase, ChannelPhase::Undefined));
1427
1419
}
1420
+
1421
+ pub fn funding_tx_constructed<L: Deref>(
1422
+ &mut self, signing_session: InteractiveTxSigningSession, logger: &L
1423
+ ) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
1424
+ where
1425
+ L::Target: Logger
1426
+ {
1427
+ let phase = core::mem::replace(&mut self.phase, ChannelPhase::Undefined);
1428
+ if let ChannelPhase::UnfundedV2(chan) = phase {
1429
+ let logger = WithChannelContext::from(logger, &chan.context, None);
1430
+ match chan.funding_tx_constructed(signing_session, &&logger) {
1431
+ Ok((chan, commitment_signed, event)) => {
1432
+ self.phase = ChannelPhase::Funded(chan);
1433
+ Ok((commitment_signed, event))
1434
+ },
1435
+ Err((chan, e)) => {
1436
+ self.phase = ChannelPhase::UnfundedV2(chan);
1437
+ Err(e)
1438
+ },
1439
+ }
1440
+ } else {
1441
+ self.phase = phase;
1442
+ Err(ChannelError::Warn("Got a tx_complete message with no interactive transaction construction expected or in-progress".to_owned()))
1443
+ }
1444
+ }
1428
1445
}
1429
1446
1430
1447
impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>
@@ -2073,8 +2090,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2073
2090
}
2074
2091
2075
2092
pub fn funding_tx_constructed<L: Deref>(
2076
- & mut self, signing_session: &mut InteractiveTxSigningSession, logger: &L
2077
- ) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
2093
+ mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2094
+ ) -> Result<(FundedChannel<SP>, msgs::CommitmentSigned, Option<Event>), (PendingV2Channel<SP>, ChannelError) >
2078
2095
where
2079
2096
L::Target: Logger
2080
2097
{
@@ -2090,7 +2107,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2090
2107
(
2091
2108
"Multiple outputs matched the expected script and value".to_owned(),
2092
2109
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2093
- )));
2110
+ ))).map_err(|e| (self, e)) ;
2094
2111
}
2095
2112
output_index = Some(idx as u16);
2096
2113
}
@@ -2102,7 +2119,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2102
2119
(
2103
2120
"No output matched the funding script_pubkey".to_owned(),
2104
2121
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2105
- )));
2122
+ ))).map_err(|e| (self, e)) ;
2106
2123
};
2107
2124
self.context.channel_transaction_parameters.funding_outpoint = Some(outpoint);
2108
2125
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
@@ -2117,6 +2134,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2117
2134
Err(err) => {
2118
2135
self.context.channel_transaction_parameters.funding_outpoint = None;
2119
2136
return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })))
2137
+ .map_err(|e| (self, e));
2120
2138
},
2121
2139
};
2122
2140
@@ -2151,7 +2169,24 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2151
2169
// Clear the interactive transaction constructor
2152
2170
self.interactive_tx_constructor.take();
2153
2171
2154
- Ok((commitment_signed, funding_ready_for_sig_event))
2172
+ match self.unfunded_context.holder_commitment_point {
2173
+ Some(holder_commitment_point) => {
2174
+ let funded_chan = FundedChannel {
2175
+ context: self.context,
2176
+ interactive_tx_signing_session: Some(signing_session),
2177
+ holder_commitment_point,
2178
+ };
2179
+ Ok((funded_chan, commitment_signed, funding_ready_for_sig_event))
2180
+ },
2181
+ None => {
2182
+ Err(ChannelError::close(
2183
+ format!(
2184
+ "Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
2185
+ self.context.channel_id(),
2186
+ )))
2187
+ .map_err(|e| (self, e))
2188
+ },
2189
+ }
2155
2190
}
2156
2191
}
2157
2192
@@ -9419,19 +9454,6 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9419
9454
pub fn get_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
9420
9455
self.generate_accept_channel_v2_message()
9421
9456
}
9422
-
9423
- pub fn into_channel(self, signing_session: InteractiveTxSigningSession) -> Result<FundedChannel<SP>, ChannelError>{
9424
- let holder_commitment_point = self.unfunded_context.holder_commitment_point.ok_or(ChannelError::close(
9425
- format!("Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
9426
- self.context.channel_id())))?;
9427
- let channel = FundedChannel {
9428
- context: self.context,
9429
- interactive_tx_signing_session: Some(signing_session),
9430
- holder_commitment_point,
9431
- };
9432
-
9433
- Ok(channel)
9434
- }
9435
9457
}
9436
9458
9437
9459
// Unfunded channel utilities
0 commit comments