@@ -2039,26 +2039,27 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2039
2039
) -> Result<Option<InteractiveTxMessageSend>, APIError>
2040
2040
where ES::Target: EntropySource
2041
2041
{
2042
- let mut funding_inputs = self.dual_funding_context.our_funding_inputs.take().unwrap_or_else(|| vec![]);
2042
+ let mut funding_inputs = Vec::new();
2043
+ mem::swap(&mut self.dual_funding_context.our_funding_inputs, &mut funding_inputs);
2043
2044
2044
2045
if let Some(prev_funding_input) = prev_funding_input {
2045
2046
funding_inputs.push(prev_funding_input);
2046
2047
}
2047
2048
2048
2049
let mut funding_inputs_prev_outputs: Vec<&TxOut> = Vec::with_capacity(funding_inputs.len());
2049
2050
// Check that vouts exist for each TxIn in provided transactions.
2050
- for (idx, input ) in funding_inputs.iter().enumerate() {
2051
- if let Some(output) = input.1. as_transaction().output.get(input.0 .previous_output.vout as usize) {
2052
- funding_inputs_prev_outputs.push(& output);
2051
+ for (idx, (txin, tx) ) in funding_inputs.iter().enumerate() {
2052
+ if let Some(output) = tx. as_transaction().output.get(txin .previous_output.vout as usize) {
2053
+ funding_inputs_prev_outputs.push(output);
2053
2054
} else {
2054
2055
return Err(APIError::APIMisuseError {
2055
2056
err: format!("Transaction with txid {} does not have an output with vout of {} corresponding to TxIn at funding_inputs[{}]",
2056
- input.1. as_transaction().compute_txid(), input.0 .previous_output.vout, idx) });
2057
+ tx. as_transaction().compute_txid(), txin .previous_output.vout, idx) });
2057
2058
}
2058
2059
}
2059
2060
2060
2061
let total_input_satoshis: u64 = funding_inputs.iter().map(
2061
- |input| input.1. as_transaction().output.get(input.0 .previous_output.vout as usize).map(|out| out.value.to_sat()).unwrap_or(0)
2062
+ |(txin, tx)| tx. as_transaction().output.get(txin .previous_output.vout as usize).map(|out| out.value.to_sat()).unwrap_or(0)
2062
2063
).sum();
2063
2064
if total_input_satoshis < self.dual_funding_context.our_funding_satoshis {
2064
2065
return Err(APIError::APIMisuseError {
@@ -2100,8 +2101,14 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2100
2101
|err| APIError::APIMisuseError {
2101
2102
err: format!("Failed to get change script as new destination script, {:?}", err),
2102
2103
})?;
2103
- add_funding_change_output(change_value, change_script,
2104
- &mut funding_outputs, self.dual_funding_context.funding_feerate_sat_per_1000_weight);
2104
+ let mut change_output = TxOut {
2105
+ value: Amount::from_sat(change_value),
2106
+ script_pubkey: change_script,
2107
+ };
2108
+ let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
2109
+ let change_output_fee = fee_for_weight(self.dual_funding_context.funding_feerate_sat_per_1000_weight, change_output_weight);
2110
+ change_output.value = Amount::from_sat(change_value.saturating_sub(change_output_fee));
2111
+ funding_outputs.push(OutputOwned::Single(change_output));
2105
2112
}
2106
2113
2107
2114
let constructor_args = InteractiveTxConstructorArgs {
@@ -2120,7 +2127,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2120
2127
.map_err(|_| APIError::APIMisuseError { err: "Incorrect shared output provided".into() })?;
2121
2128
let msg = tx_constructor.take_initiator_first_message();
2122
2129
2123
- self.interactive_tx_constructor.replace (tx_constructor);
2130
+ self.interactive_tx_constructor = Some (tx_constructor);
2124
2131
2125
2132
Ok(msg)
2126
2133
}
@@ -4563,21 +4570,6 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
4563
4570
cmp::min(channel_value_satoshis, cmp::max(q, dust_limit_satoshis))
4564
4571
}
4565
4572
4566
- #[allow(dead_code)] // TODO(dual_funding): Remove once begin_interactive_funding_tx_construction() is used
4567
- fn add_funding_change_output(
4568
- change_value: u64, change_script: ScriptBuf,
4569
- funding_outputs: &mut Vec<OutputOwned>, funding_feerate_sat_per_1000_weight: u32,
4570
- ) {
4571
- let mut change_output = TxOut {
4572
- value: Amount::from_sat(change_value),
4573
- script_pubkey: change_script,
4574
- };
4575
- let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
4576
- let change_output_fee = fee_for_weight(funding_feerate_sat_per_1000_weight, change_output_weight);
4577
- change_output.value = Amount::from_sat(change_value.saturating_sub(change_output_fee));
4578
- funding_outputs.push(OutputOwned::Single(change_output.clone()));
4579
- }
4580
-
4581
4573
pub(super) fn calculate_our_funding_satoshis(
4582
4574
is_initiator: bool, funding_inputs: &[(TxIn, TransactionU16LenLimited)],
4583
4575
total_witness_weight: Weight, funding_feerate_sat_per_1000_weight: u32,
@@ -4640,7 +4632,7 @@ pub(super) struct DualFundingChannelContext {
4640
4632
///
4641
4633
/// Note that this field may be emptied once the interactive negotiation has been started.
4642
4634
#[allow(dead_code)] // TODO(dual_funding): Remove once contribution to V2 channels is enabled.
4643
- pub our_funding_inputs: Option< Vec<(TxIn, TransactionU16LenLimited)> >,
4635
+ pub our_funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
4644
4636
}
4645
4637
4646
4638
impl DualFundingChannelContext {
@@ -9308,7 +9300,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9308
9300
their_funding_satoshis: None,
9309
9301
funding_tx_locktime,
9310
9302
funding_feerate_sat_per_1000_weight,
9311
- our_funding_inputs: Some( funding_inputs) ,
9303
+ our_funding_inputs: funding_inputs,
9312
9304
};
9313
9305
let chan = Self {
9314
9306
context,
@@ -9463,7 +9455,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9463
9455
their_funding_satoshis: Some(msg.common_fields.funding_satoshis),
9464
9456
funding_tx_locktime: LockTime::from_consensus(msg.locktime),
9465
9457
funding_feerate_sat_per_1000_weight: msg.funding_feerate_sat_per_1000_weight,
9466
- our_funding_inputs: Some( funding_inputs.clone() ),
9458
+ our_funding_inputs: funding_inputs.clone(),
9467
9459
};
9468
9460
9469
9461
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
0 commit comments