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