@@ -2219,54 +2219,67 @@ impl<SP: Deref> InitialRemoteCommitmentReceiver<SP> for FundedChannel<SP> where
2219
2219
}
2220
2220
}
2221
2221
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() {
2225
2237
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())),
2227
2239
None => Err(msgs::TxAbort {
2228
- channel_id: self.context.channel_id(),
2240
+ channel_id: self.context() .channel_id(),
2229
2241
data: b"No interactive transaction negotiation in progress".to_vec()
2230
2242
}),
2231
2243
})
2232
2244
}
2233
2245
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() {
2236
2248
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())),
2238
2250
None => Err(msgs::TxAbort {
2239
- channel_id: self.context.channel_id(),
2251
+ channel_id: self.context() .channel_id(),
2240
2252
data: b"No interactive transaction negotiation in progress".to_vec()
2241
2253
}),
2242
2254
})
2243
2255
}
2244
2256
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() {
2247
2259
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())),
2249
2261
None => Err(msgs::TxAbort {
2250
- channel_id: self.context.channel_id(),
2262
+ channel_id: self.context() .channel_id(),
2251
2263
data: b"No interactive transaction negotiation in progress".to_vec()
2252
2264
}),
2253
2265
})
2254
2266
}
2255
2267
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() {
2258
2270
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())),
2260
2272
None => Err(msgs::TxAbort {
2261
- channel_id: self.context.channel_id(),
2273
+ channel_id: self.context() .channel_id(),
2262
2274
data: b"No interactive transaction negotiation in progress".to_vec()
2263
2275
}),
2264
2276
})
2265
2277
}
2266
2278
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,
2270
2283
None => {
2271
2284
let tx_abort = msgs::TxAbort {
2272
2285
channel_id: msg.channel_id,
@@ -2284,25 +2297,25 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2284
2297
};
2285
2298
2286
2299
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());
2288
2301
};
2289
2302
2290
2303
HandleTxCompleteResult(Ok(tx_complete))
2291
2304
}
2292
2305
2293
- pub fn funding_tx_constructed<L: Deref>(
2306
+ fn funding_tx_constructed<L: Deref>(
2294
2307
&mut self, mut signing_session: InteractiveTxSigningSession, logger: &L
2295
2308
) -> Result<(msgs::CommitmentSigned, Option<Event>), ChannelError>
2296
2309
where
2297
2310
L::Target: Logger
2298
2311
{
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();
2301
2314
2302
2315
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();
2304
2317
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() {
2306
2319
if output_index.is_some() {
2307
2320
return Err(ChannelError::Close(
2308
2321
(
@@ -2322,24 +2335,25 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2322
2335
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2323
2336
)));
2324
2337
};
2325
- self.funding .channel_transaction_parameters.funding_outpoint = Some(outpoint);
2338
+ self.funding_mut() .channel_transaction_parameters.funding_outpoint = Some(outpoint);
2326
2339
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);
2329
2343
let commitment_signed = match commitment_signed {
2330
2344
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());
2332
2346
commitment_signed
2333
2347
},
2334
2348
Err(err) => {
2335
- self.funding .channel_transaction_parameters.funding_outpoint = None;
2349
+ self.funding_mut() .channel_transaction_parameters.funding_outpoint = None;
2336
2350
return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })));
2337
2351
},
2338
2352
};
2339
2353
2340
2354
let funding_ready_for_sig_event = if signing_session.local_inputs_count() == 0 {
2341
2355
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() {
2343
2357
debug_assert!(
2344
2358
false,
2345
2359
"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 {
2375
2389
)));
2376
2390
};
2377
2391
2378
- self.context .channel_state = ChannelState::FundingNegotiated;
2392
+ self.context_mut() .channel_state = ChannelState::FundingNegotiated;
2379
2393
2380
2394
// 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);
2383
2397
2384
2398
Ok((commitment_signed, funding_ready_for_sig_event))
2385
2399
}
2386
2400
}
2387
2401
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
+
2388
2452
impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2389
2453
fn new_for_inbound_channel<'a, ES: Deref, F: Deref, L: Deref>(
2390
2454
fee_estimator: &'a LowerBoundedFeeEstimator<F>,
0 commit comments