@@ -1665,8 +1665,10 @@ impl InteractiveTxConstructor {
16651665/// Determine whether a change output should be added or not, and if so, of what size,
16661666/// considering our given inputs, outputs, and intended contribution.
16671667/// Computes and takes into account fees.
1668+ /// Return value is the value computed for the change output (in satoshis),
1669+ /// or None if a change is not needed/possible.
16681670#[allow(dead_code)] // TODO(dual_funding): Remove once begin_interactive_funding_tx_construction() is used
1669- pub(super) fn need_to_add_funding_change_output (
1671+ pub(super) fn calculate_change_output_value (
16701672 is_initiator: bool, our_contribution: u64, funding_inputs_prev_outputs: &Vec<TxOut>,
16711673 funding_outputs: &Vec<OutputOwned>, funding_feerate_sat_per_1000_weight: u32,
16721674 holder_dust_limit_satoshis: u64,
@@ -1707,7 +1709,7 @@ mod tests {
17071709 use crate::chain::chaininterface::{fee_for_weight, FEERATE_FLOOR_SATS_PER_KW};
17081710 use crate::ln::channel::TOTAL_BITCOIN_SUPPLY_SATOSHIS;
17091711 use crate::ln::interactivetxs::{
1710- generate_holder_serial_id, need_to_add_funding_change_output , AbortReason,
1712+ generate_holder_serial_id, calculate_change_output_value , AbortReason,
17111713 HandleTxCompleteValue, InteractiveTxConstructor, InteractiveTxConstructorArgs,
17121714 InteractiveTxMessageSend, MAX_INPUTS_OUTPUTS_COUNT, MAX_RECEIVED_TX_ADD_INPUT_COUNT,
17131715 MAX_RECEIVED_TX_ADD_OUTPUT_COUNT,
@@ -2637,7 +2639,7 @@ mod tests {
26372639 }
26382640
26392641 #[test]
2640- fn test_need_to_add_funding_change_output_open () {
2642+ fn test_calculate_change_output_value_open () {
26412643 let input_prevouts = vec![
26422644 TxOut { value: Amount::from_sat(70_000), script_pubkey: ScriptBuf::new() },
26432645 TxOut { value: Amount::from_sat(60_000), script_pubkey: ScriptBuf::new() },
@@ -2653,7 +2655,7 @@ mod tests {
26532655 let common_fees = 126;
26542656 {
26552657 // There is leftover for change
2656- let res = need_to_add_funding_change_output (
2658+ let res = calculate_change_output_value (
26572659 true,
26582660 our_contributed,
26592661 &input_prevouts,
@@ -2665,7 +2667,7 @@ mod tests {
26652667 }
26662668 {
26672669 // There is leftover for change, without common fees
2668- let res = need_to_add_funding_change_output (
2670+ let res = calculate_change_output_value (
26692671 false,
26702672 our_contributed,
26712673 &input_prevouts,
@@ -2677,7 +2679,7 @@ mod tests {
26772679 }
26782680 {
26792681 // Larger fee, smaller change
2680- let res = need_to_add_funding_change_output (
2682+ let res = calculate_change_output_value (
26812683 true,
26822684 our_contributed,
26832685 &input_prevouts,
@@ -2689,7 +2691,7 @@ mod tests {
26892691 }
26902692 {
26912693 // Insufficient inputs, no leftover
2692- let res = need_to_add_funding_change_output (
2694+ let res = calculate_change_output_value (
26932695 false,
26942696 130_000,
26952697 &input_prevouts,
@@ -2701,7 +2703,7 @@ mod tests {
27012703 }
27022704 {
27032705 // Very small leftover
2704- let res = need_to_add_funding_change_output (
2706+ let res = calculate_change_output_value (
27052707 false,
27062708 128_100,
27072709 &input_prevouts,
@@ -2713,7 +2715,7 @@ mod tests {
27132715 }
27142716 {
27152717 // Small leftover, but not dust
2716- let res = need_to_add_funding_change_output (
2718+ let res = calculate_change_output_value (
27172719 false,
27182720 128_100,
27192721 &input_prevouts,
@@ -2726,7 +2728,7 @@ mod tests {
27262728 }
27272729
27282730 #[test]
2729- fn test_need_to_add_funding_change_output_splice () {
2731+ fn test_calculate_change_output_value_splice () {
27302732 let input_prevouts = vec![
27312733 TxOut { value: Amount::from_sat(70_000), script_pubkey: ScriptBuf::new() },
27322734 TxOut { value: Amount::from_sat(60_000), script_pubkey: ScriptBuf::new() },
@@ -2742,7 +2744,7 @@ mod tests {
27422744 let common_fees = 126;
27432745 {
27442746 // There is leftover for change
2745- let res = need_to_add_funding_change_output (
2747+ let res = calculate_change_output_value (
27462748 true,
27472749 our_contributed,
27482750 &input_prevouts,
@@ -2754,7 +2756,7 @@ mod tests {
27542756 }
27552757 {
27562758 // Very small leftover
2757- let res = need_to_add_funding_change_output (
2759+ let res = calculate_change_output_value (
27582760 false,
27592761 128_100,
27602762 &input_prevouts,
@@ -2766,7 +2768,7 @@ mod tests {
27662768 }
27672769 {
27682770 // Small leftover, but not dust
2769- let res = need_to_add_funding_change_output (
2771+ let res = calculate_change_output_value (
27702772 false,
27712773 128_100,
27722774 &input_prevouts,
0 commit comments