@@ -2240,6 +2240,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2240
2240
self.channel_transaction_parameters.funding_outpoint
2241
2241
}
2242
2242
2243
+ fn get_funding_transaction(&self) -> Option<Transaction> {
2244
+ self.funding_transaction.clone()
2245
+ }
2246
+
2243
2247
/// Returns the height in which our funding transaction was confirmed.
2244
2248
pub fn get_funding_tx_confirmation_height(&self) -> Option<u32> {
2245
2249
let conf_height = self.funding_tx_confirmation_height;
@@ -7375,7 +7379,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7375
7379
/// Note that channel_id changes during this call!
7376
7380
/// Do NOT broadcast the funding transaction until after a successful funding_signed call!
7377
7381
/// If an Err is returned, it is a ChannelError::Close.
7378
- pub fn get_funding_created<L: Deref>(&mut self, funding_transaction: Transaction, funding_txo: OutPoint, is_batch_funding: bool, logger: &L)
7382
+ pub fn get_funding_created<L: Deref>(&mut self, funding_transaction: Option< Transaction> , funding_txo: Option< OutPoint> , is_batch_funding: Option< bool> , logger: &L)
7379
7383
-> Result<Option<msgs::FundingCreated>, (Self, ChannelError)> where L::Target: Logger {
7380
7384
if !self.context.is_outbound() {
7381
7385
panic!("Tried to create outbound funding_created message on an inbound channel!");
@@ -7392,6 +7396,23 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7392
7396
panic!("Should not have advanced channel commitment tx numbers prior to funding_created");
7393
7397
}
7394
7398
7399
+ // This section of logic verifies if `funding_transaction` and `funding_txo` are provided.
7400
+ // If not, they are retrieved from the context. The decision to proceed with the logic
7401
+ // even when context values are available ensures consistent flow and passes through all
7402
+ // original sanity checks.
7403
+ let (funding_transaction, funding_txo, is_batch_funding) = match (funding_transaction, funding_txo, is_batch_funding) {
7404
+ (Some(tx), Some(txo), Some(batch)) => (tx, txo, batch),
7405
+ (None, None, None) => {
7406
+ let funding_tx = self.context.get_funding_transaction()
7407
+ .unwrap_or_else(|| panic!("Failed to get funding transaction from context"));
7408
+ let funding_txo = self.context.get_funding_txo()
7409
+ .unwrap_or_else(|| panic!("Failed to get funding txo from context"));
7410
+ let batch_funding = self.context.is_batch_funding.is_some();
7411
+ (funding_tx, funding_txo, batch_funding)
7412
+ }
7413
+ _ => panic!("Either all or None of funding_transaction, funding_txo, and is_batch_funding should be provided"),
7414
+ };
7415
+
7395
7416
self.context.channel_transaction_parameters.funding_outpoint = Some(funding_txo);
7396
7417
self.context.holder_signer.as_mut().provide_channel_parameters(&self.context.channel_transaction_parameters);
7397
7418
@@ -9511,7 +9532,7 @@ mod tests {
9511
9532
value: 10000000, script_pubkey: output_script.clone(),
9512
9533
}]};
9513
9534
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
9514
- let funding_created_msg = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
9535
+ let funding_created_msg = node_a_chan.get_funding_created(Some( tx.clone()), Some( funding_outpoint), Some( false) , &&logger).map_err(|_| ()).unwrap();
9515
9536
let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap(), best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
9516
9537
9517
9538
// Node B --> Node A: funding signed
@@ -9640,7 +9661,7 @@ mod tests {
9640
9661
value: 10000000, script_pubkey: output_script.clone(),
9641
9662
}]};
9642
9663
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
9643
- let funding_created_msg = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
9664
+ let funding_created_msg = node_a_chan.get_funding_created(Some( tx.clone()), Some( funding_outpoint), Some( false) , &&logger).map_err(|_| ()).unwrap();
9644
9665
let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap(), best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
9645
9666
9646
9667
// Node B --> Node A: funding signed
@@ -9829,7 +9850,7 @@ mod tests {
9829
9850
value: 10000000, script_pubkey: output_script.clone(),
9830
9851
}]};
9831
9852
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
9832
- let funding_created_msg = node_a_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap();
9853
+ let funding_created_msg = node_a_chan.get_funding_created(Some( tx.clone()), Some( funding_outpoint), Some( false) , &&logger).map_err(|_| ()).unwrap();
9833
9854
let (_, funding_signed_msg, _) = node_b_chan.funding_created(&funding_created_msg.unwrap(), best_block, &&keys_provider, &&logger).map_err(|_| ()).unwrap();
9834
9855
9835
9856
// Node B --> Node A: funding signed
@@ -9896,7 +9917,7 @@ mod tests {
9896
9917
value: 10000000, script_pubkey: outbound_chan.context.get_funding_redeemscript(),
9897
9918
}]};
9898
9919
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
9899
- let funding_created = outbound_chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap().unwrap();
9920
+ let funding_created = outbound_chan.get_funding_created(Some( tx.clone()), Some( funding_outpoint), Some( false) , &&logger).map_err(|_| ()).unwrap().unwrap();
9900
9921
let mut chan = match inbound_chan.funding_created(&funding_created, best_block, &&keys_provider, &&logger) {
9901
9922
Ok((chan, _, _)) => chan,
9902
9923
Err((_, e)) => panic!("{}", e),
@@ -11029,7 +11050,7 @@ mod tests {
11029
11050
]};
11030
11051
let funding_outpoint = OutPoint{ txid: tx.txid(), index: 0 };
11031
11052
let funding_created_msg = node_a_chan.get_funding_created(
11032
- tx.clone(), funding_outpoint, true, &&logger,
11053
+ Some( tx.clone()), Some( funding_outpoint), Some( true) , &&logger,
11033
11054
).map_err(|_| ()).unwrap();
11034
11055
let (mut node_b_chan, funding_signed_msg, _) = node_b_chan.funding_created(
11035
11056
&funding_created_msg.unwrap(),
0 commit comments