@@ -2219,54 +2219,67 @@ impl<SP: Deref> InitialRemoteCommitmentReceiver<SP> for FundedChannel<SP> where
22192219 }
22202220}
22212221
2222- impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2223- pub fn tx_add_input(&mut self, msg: &msgs::TxAddInput) -> InteractiveTxMessageSendResult {
2224- InteractiveTxMessageSendResult(match &mut self.interactive_tx_constructor {
2222+ // TODO Naming
2223+ pub(super) trait PendingV2ChannelTrait<SP: Deref> where SP::Target: SignerProvider {
2224+ fn context(&self) -> &ChannelContext<SP>;
2225+ fn context_mut(&mut self) -> &mut ChannelContext<SP>;
2226+ fn funding(&self) -> &FundingScope;
2227+ fn funding_mut(&mut self) -> &mut FundingScope;
2228+ fn funding_and_context_mut(&mut self) -> (&mut FundingScope, &mut ChannelContext<SP>);
2229+ fn dual_funding_context(&self) -> &DualFundingChannelContext;
2230+ fn unfunded_context(&self) -> &UnfundedChannelContext;
2231+ fn interactive_tx_constructor_mut(&mut self) -> Option<&mut InteractiveTxConstructor>;
2232+ fn clear_interactive_tx_constructor(&mut self);
2233+ fn set_interactive_tx_signing_session(&mut self, session: InteractiveTxSigningSession);
2234+
2235+ fn tx_add_input(&mut self, msg: &msgs::TxAddInput) -> InteractiveTxMessageSendResult {
2236+ InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
22252237 Some(ref mut tx_constructor) => tx_constructor.handle_tx_add_input(msg).map_err(
2226- |reason| reason.into_tx_abort_msg(self.context.channel_id())),
2238+ |reason| reason.into_tx_abort_msg(self.context() .channel_id())),
22272239 None => Err(msgs::TxAbort {
2228- channel_id: self.context.channel_id(),
2240+ channel_id: self.context() .channel_id(),
22292241 data: b"No interactive transaction negotiation in progress".to_vec()
22302242 }),
22312243 })
22322244 }
22332245
2234- pub fn tx_add_output(&mut self, msg: &msgs::TxAddOutput)-> InteractiveTxMessageSendResult {
2235- InteractiveTxMessageSendResult(match &mut self.interactive_tx_constructor {
2246+ fn tx_add_output(&mut self, msg: &msgs::TxAddOutput)-> InteractiveTxMessageSendResult {
2247+ InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
22362248 Some(ref mut tx_constructor) => tx_constructor.handle_tx_add_output(msg).map_err(
2237- |reason| reason.into_tx_abort_msg(self.context.channel_id())),
2249+ |reason| reason.into_tx_abort_msg(self.context() .channel_id())),
22382250 None => Err(msgs::TxAbort {
2239- channel_id: self.context.channel_id(),
2251+ channel_id: self.context() .channel_id(),
22402252 data: b"No interactive transaction negotiation in progress".to_vec()
22412253 }),
22422254 })
22432255 }
22442256
2245- pub fn tx_remove_input(&mut self, msg: &msgs::TxRemoveInput)-> InteractiveTxMessageSendResult {
2246- InteractiveTxMessageSendResult(match &mut self.interactive_tx_constructor {
2257+ fn tx_remove_input(&mut self, msg: &msgs::TxRemoveInput)-> InteractiveTxMessageSendResult {
2258+ InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
22472259 Some(ref mut tx_constructor) => tx_constructor.handle_tx_remove_input(msg).map_err(
2248- |reason| reason.into_tx_abort_msg(self.context.channel_id())),
2260+ |reason| reason.into_tx_abort_msg(self.context() .channel_id())),
22492261 None => Err(msgs::TxAbort {
2250- channel_id: self.context.channel_id(),
2262+ channel_id: self.context() .channel_id(),
22512263 data: b"No interactive transaction negotiation in progress".to_vec()
22522264 }),
22532265 })
22542266 }
22552267
2256- pub fn tx_remove_output(&mut self, msg: &msgs::TxRemoveOutput)-> InteractiveTxMessageSendResult {
2257- InteractiveTxMessageSendResult(match &mut self.interactive_tx_constructor {
2268+ fn tx_remove_output(&mut self, msg: &msgs::TxRemoveOutput)-> InteractiveTxMessageSendResult {
2269+ InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
22582270 Some(ref mut tx_constructor) => tx_constructor.handle_tx_remove_output(msg).map_err(
2259- |reason| reason.into_tx_abort_msg(self.context.channel_id())),
2271+ |reason| reason.into_tx_abort_msg(self.context() .channel_id())),
22602272 None => Err(msgs::TxAbort {
2261- channel_id: self.context.channel_id(),
2273+ channel_id: self.context() .channel_id(),
22622274 data: b"No interactive transaction negotiation in progress".to_vec()
22632275 }),
22642276 })
22652277 }
22662278
2267- pub fn tx_complete(&mut self, msg: &msgs::TxComplete) -> HandleTxCompleteResult {
2268- let tx_constructor = match &mut self.interactive_tx_constructor {
2269- Some(ref mut tx_constructor) => tx_constructor,
2279+ fn tx_complete(&mut self, msg: &msgs::TxComplete) -> HandleTxCompleteResult {
2280+ let interactive_tx_constructor = self.interactive_tx_constructor_mut();
2281+ let tx_constructor = match interactive_tx_constructor {
2282+ Some(tx_constructor) => tx_constructor,
22702283 None => {
22712284 let tx_abort = msgs::TxAbort {
22722285 channel_id: msg.channel_id,
@@ -2284,25 +2297,25 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22842297 };
22852298
22862299 if let HandleTxCompleteValue::SendTxComplete(_, ref signing_session) = tx_complete {
2287- self.context .next_funding_txid = Some(signing_session.unsigned_tx.compute_txid());
2300+ self.context_mut() .next_funding_txid = Some(signing_session.unsigned_tx.compute_txid());
22882301 };
22892302
22902303 HandleTxCompleteResult(Ok(tx_complete))
22912304 }
22922305
2293- pub fn funding_tx_constructed<L: Deref>(
2306+ fn funding_tx_constructed<L: Deref>(
22942307 &mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
22952308 ) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
22962309 where
22972310 L::Target: Logger
22982311 {
2299- let our_funding_satoshis = self.dual_funding_context.our_funding_satoshis;
2300- let transaction_number = self.unfunded_context.transaction_number();
2312+ let our_funding_satoshis = self.dual_funding_context() .our_funding_satoshis;
2313+ let transaction_number = self.unfunded_context() .transaction_number();
23012314
23022315 let mut output_index = None;
2303- let expected_spk = self.funding.get_funding_redeemscript().to_p2wsh();
2316+ let expected_spk = self.funding() .get_funding_redeemscript().to_p2wsh();
23042317 for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
2305- if outp.script_pubkey() == &expected_spk && outp.value() == self.funding.get_value_satoshis() {
2318+ if outp.script_pubkey() == &expected_spk && outp.value() == self.funding() .get_value_satoshis() {
23062319 if output_index.is_some() {
23072320 return Err(ChannelError::Close(
23082321 (
@@ -2322,24 +2335,25 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
23222335 ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
23232336 )));
23242337 };
2325- self.funding .channel_transaction_parameters.funding_outpoint = Some(outpoint);
2338+ self.funding_mut() .channel_transaction_parameters.funding_outpoint = Some(outpoint);
23262339
2327- self.context.assert_no_commitment_advancement(transaction_number, "initial commitment_signed");
2328- let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger);
2340+ self.context().assert_no_commitment_advancement(transaction_number, "initial commitment_signed");
2341+ let (funding_mut, context_mut) = self.funding_and_context_mut();
2342+ let commitment_signed = context_mut.get_initial_commitment_signed(&funding_mut, logger);
23292343 let commitment_signed = match commitment_signed {
23302344 Ok(commitment_signed) => {
2331- self.funding .funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
2345+ self.funding_mut() .funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
23322346 commitment_signed
23332347 },
23342348 Err(err) => {
2335- self.funding .channel_transaction_parameters.funding_outpoint = None;
2349+ self.funding_mut() .channel_transaction_parameters.funding_outpoint = None;
23362350 return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })));
23372351 },
23382352 };
23392353
23402354 let funding_ready_for_sig_event = if signing_session.local_inputs_count() == 0 {
23412355 debug_assert_eq!(our_funding_satoshis, 0);
2342- if signing_session.provide_holder_witnesses(self.context.channel_id, Vec::new()).is_err() {
2356+ if signing_session.provide_holder_witnesses(self.context() .channel_id, Vec::new()).is_err() {
23432357 debug_assert!(
23442358 false,
23452359 "Zero inputs were provided & zero witnesses were provided, but a count mismatch was somehow found",
@@ -2375,16 +2389,66 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
23752389 )));
23762390 };
23772391
2378- self.context .channel_state = ChannelState::FundingNegotiated;
2392+ self.context_mut() .channel_state = ChannelState::FundingNegotiated;
23792393
23802394 // Clear the interactive transaction constructor
2381- self.interactive_tx_constructor.take ();
2382- self.interactive_tx_signing_session = Some (signing_session);
2395+ self.clear_interactive_tx_constructor ();
2396+ self.set_interactive_tx_signing_session (signing_session);
23832397
23842398 Ok((commitment_signed, funding_ready_for_sig_event))
23852399 }
23862400}
23872401
2402+ impl<SP: Deref> PendingV2ChannelTrait<SP> for PendingV2Channel<SP> where SP::Target: SignerProvider {
2403+ #[inline]
2404+ fn context(&self) -> &ChannelContext<SP> {
2405+ &self.context
2406+ }
2407+
2408+ #[inline]
2409+ fn context_mut(&mut self) -> &mut ChannelContext<SP> {
2410+ &mut self.context
2411+ }
2412+
2413+ #[inline]
2414+ fn funding(&self) -> &FundingScope {
2415+ &self.funding
2416+ }
2417+
2418+ #[inline]
2419+ fn funding_mut(&mut self) -> &mut FundingScope {
2420+ &mut self.funding
2421+ }
2422+
2423+ #[inline]
2424+ fn funding_and_context_mut(&mut self) -> (&mut FundingScope, &mut ChannelContext<SP>) {
2425+ (&mut self.funding, &mut self.context)
2426+ }
2427+
2428+ #[inline]
2429+ fn dual_funding_context(&self) -> &DualFundingChannelContext {
2430+ &self.dual_funding_context
2431+ }
2432+
2433+ #[inline]
2434+ fn unfunded_context(&self) -> &UnfundedChannelContext {
2435+ &self.unfunded_context
2436+ }
2437+
2438+ #[inline]
2439+ fn interactive_tx_constructor_mut(&mut self) -> Option<&mut InteractiveTxConstructor> {
2440+ self.interactive_tx_constructor.as_mut()
2441+ }
2442+
2443+ fn clear_interactive_tx_constructor(&mut self) {
2444+ self.interactive_tx_constructor.take();
2445+ }
2446+
2447+ fn set_interactive_tx_signing_session(&mut self, session: InteractiveTxSigningSession) {
2448+ self.interactive_tx_signing_session = Some(session);
2449+ }
2450+ }
2451+
23882452impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
23892453 fn new_for_inbound_channel<'a, ES: Deref, F: Deref, L: Deref>(
23902454 fee_estimator: &'a LowerBoundedFeeEstimator<F>,
0 commit comments