@@ -2766,20 +2766,25 @@ where
27662766 /// default destination address is used.
27672767 /// If error occurs, it is caused by our side, not the counterparty.
27682768 #[allow(dead_code)] // TODO(dual_funding): Remove once contribution to V2 channels is enabled
2769- #[rustfmt::skip]
27702769 fn begin_interactive_funding_tx_construction<ES: Deref>(
27712770 &mut self, signer_provider: &SP, entropy_source: &ES, holder_node_id: PublicKey,
2772- change_destination_opt: Option<ScriptBuf>,
2771+ is_initiator: bool, change_destination_opt: Option<ScriptBuf>,
2772+ prev_funding_input: Option<(TxIn, TransactionU16LenLimited)>,
27732773 ) -> Result<Option<InteractiveTxMessageSend>, AbortReason>
2774- where ES::Target: EntropySource
2774+ where
2775+ ES::Target: EntropySource,
27752776 {
27762777 debug_assert!(matches!(self.context.channel_state, ChannelState::NegotiatingFunding(_)));
27772778 debug_assert!(self.interactive_tx_constructor.is_none());
27782779
27792780 let mut funding_inputs = Vec::new();
27802781 mem::swap(&mut self.funding_negotiation_context.our_funding_inputs, &mut funding_inputs);
27812782
2782- // TODO(splicing): Add prev funding tx as input, must be provided as a parameter
2783+ if is_initiator {
2784+ if let Some(prev_funding_input) = prev_funding_input {
2785+ funding_inputs.push(prev_funding_input);
2786+ }
2787+ }
27832788
27842789 // Add output for funding tx
27852790 // Note: For the error case when the inputs are insufficient, it will be handled after
@@ -2795,23 +2800,28 @@ where
27952800 let change_script = if let Some(script) = change_destination_opt {
27962801 script
27972802 } else {
2798- signer_provider.get_destination_script(self.context.channel_keys_id)
2803+ signer_provider
2804+ .get_destination_script(self.context.channel_keys_id)
27992805 .map_err(|_err| AbortReason::InternalError("Error getting destination script"))?
28002806 };
28012807 let change_value_opt = calculate_change_output_value(
2802- self.funding.is_outbound(), self.funding_negotiation_context.our_funding_satoshis,
2803- &funding_inputs, None,
2804- &shared_funding_output.script_pubkey, &funding_outputs,
2808+ is_initiator,
2809+ self.funding_negotiation_context.our_funding_satoshis,
2810+ &funding_inputs,
2811+ None,
2812+ &shared_funding_output.script_pubkey,
2813+ &funding_outputs,
28052814 self.funding_negotiation_context.funding_feerate_sat_per_1000_weight,
28062815 change_script.minimal_non_dust().to_sat(),
28072816 )?;
28082817 if let Some(change_value) = change_value_opt {
2809- let mut change_output = TxOut {
2810- value: Amount::from_sat(change_value),
2811- script_pubkey: change_script,
2812- };
2818+ let mut change_output =
2819+ TxOut { value: Amount::from_sat(change_value), script_pubkey: change_script };
28132820 let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
2814- let change_output_fee = fee_for_weight(self.funding_negotiation_context.funding_feerate_sat_per_1000_weight, change_output_weight);
2821+ let change_output_fee = fee_for_weight(
2822+ self.funding_negotiation_context.funding_feerate_sat_per_1000_weight,
2823+ change_output_weight,
2824+ );
28152825 let change_value_decreased_with_fee = change_value.saturating_sub(change_output_fee);
28162826 // Check dust limit again
28172827 if change_value_decreased_with_fee > self.context.holder_dust_limit_satoshis {
@@ -2825,8 +2835,10 @@ where
28252835 holder_node_id,
28262836 counterparty_node_id: self.context.counterparty_node_id,
28272837 channel_id: self.context.channel_id(),
2828- feerate_sat_per_kw: self.funding_negotiation_context.funding_feerate_sat_per_1000_weight,
2829- is_initiator: self.funding.is_outbound(),
2838+ feerate_sat_per_kw: self
2839+ .funding_negotiation_context
2840+ .funding_feerate_sat_per_1000_weight,
2841+ is_initiator,
28302842 funding_tx_locktime: self.funding_negotiation_context.funding_tx_locktime,
28312843 inputs_to_contribute: funding_inputs,
28322844 shared_funding_input: None,
0 commit comments