@@ -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,34 @@ 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
+ let result = 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
+
1445
+ debug_assert!(!matches!(self.phase, ChannelPhase::Undefined));
1446
+ result
1447
+ }
1428
1448
}
1429
1449
1430
1450
impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>
@@ -2073,8 +2093,8 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2073
2093
}
2074
2094
2075
2095
pub fn funding_tx_constructed<L: Deref>(
2076
- & mut self, signing_session: &mut InteractiveTxSigningSession, logger: &L
2077
- ) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
2096
+ mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2097
+ ) -> Result<(FundedChannel<SP>, msgs::CommitmentSigned, Option<Event>), (PendingV2Channel<SP>, ChannelError) >
2078
2098
where
2079
2099
L::Target: Logger
2080
2100
{
@@ -2090,7 +2110,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2090
2110
(
2091
2111
"Multiple outputs matched the expected script and value".to_owned(),
2092
2112
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2093
- )));
2113
+ ))).map_err(|e| (self, e)) ;
2094
2114
}
2095
2115
output_index = Some(idx as u16);
2096
2116
}
@@ -2102,7 +2122,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2102
2122
(
2103
2123
"No output matched the funding script_pubkey".to_owned(),
2104
2124
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2105
- )));
2125
+ ))).map_err(|e| (self, e)) ;
2106
2126
};
2107
2127
self.context.channel_transaction_parameters.funding_outpoint = Some(outpoint);
2108
2128
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
@@ -2117,6 +2137,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2117
2137
Err(err) => {
2118
2138
self.context.channel_transaction_parameters.funding_outpoint = None;
2119
2139
return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })))
2140
+ .map_err(|e| (self, e));
2120
2141
},
2121
2142
};
2122
2143
@@ -2151,7 +2172,24 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2151
2172
// Clear the interactive transaction constructor
2152
2173
self.interactive_tx_constructor.take();
2153
2174
2154
- Ok((commitment_signed, funding_ready_for_sig_event))
2175
+ match self.unfunded_context.holder_commitment_point {
2176
+ Some(holder_commitment_point) => {
2177
+ let funded_chan = FundedChannel {
2178
+ context: self.context,
2179
+ interactive_tx_signing_session: Some(signing_session),
2180
+ holder_commitment_point,
2181
+ };
2182
+ Ok((funded_chan, commitment_signed, funding_ready_for_sig_event))
2183
+ },
2184
+ None => {
2185
+ Err(ChannelError::close(
2186
+ format!(
2187
+ "Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
2188
+ self.context.channel_id(),
2189
+ )))
2190
+ .map_err(|e| (self, e))
2191
+ },
2192
+ }
2155
2193
}
2156
2194
}
2157
2195
@@ -9418,19 +9456,6 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9418
9456
pub fn get_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
9419
9457
self.generate_accept_channel_v2_message()
9420
9458
}
9421
-
9422
- pub fn into_channel(self, signing_session: InteractiveTxSigningSession) -> Result<FundedChannel<SP>, ChannelError>{
9423
- let holder_commitment_point = self.unfunded_context.holder_commitment_point.ok_or(ChannelError::close(
9424
- format!("Expected to have holder commitment points available upon finishing interactive tx construction for channel {}",
9425
- self.context.channel_id())))?;
9426
- let channel = FundedChannel {
9427
- context: self.context,
9428
- interactive_tx_signing_session: Some(signing_session),
9429
- holder_commitment_point,
9430
- };
9431
-
9432
- Ok(channel)
9433
- }
9434
9459
}
9435
9460
9436
9461
// Unfunded channel utilities
0 commit comments