@@ -1666,8 +1666,10 @@ impl InteractiveTxConstructor {
16661666/// Determine whether a change output should be added or not, and if so, of what size,
16671667/// considering our given inputs, outputs, and intended contribution.
16681668/// Computes and takes into account fees.
1669+ /// Return value is the value computed for the change output (in satoshis),
1670+ /// or None if a change is not needed/possible.
16691671#[ allow( dead_code) ] // TODO(dual_funding): Remove once begin_interactive_funding_tx_construction() is used
1670- pub ( super ) fn need_to_add_funding_change_output (
1672+ pub ( super ) fn calculate_change_output_value (
16711673 is_initiator : bool , our_contribution : u64 , funding_inputs_prev_outputs : & Vec < TxOut > ,
16721674 funding_outputs : & Vec < OutputOwned > , funding_feerate_sat_per_1000_weight : u32 ,
16731675 holder_dust_limit_satoshis : u64 ,
@@ -1708,7 +1710,7 @@ mod tests {
17081710 use crate :: chain:: chaininterface:: { fee_for_weight, FEERATE_FLOOR_SATS_PER_KW } ;
17091711 use crate :: ln:: channel:: TOTAL_BITCOIN_SUPPLY_SATOSHIS ;
17101712 use crate :: ln:: interactivetxs:: {
1711- generate_holder_serial_id , need_to_add_funding_change_output , AbortReason ,
1713+ calculate_change_output_value , generate_holder_serial_id , AbortReason ,
17121714 HandleTxCompleteValue , InteractiveTxConstructor , InteractiveTxConstructorArgs ,
17131715 InteractiveTxMessageSend , MAX_INPUTS_OUTPUTS_COUNT , MAX_RECEIVED_TX_ADD_INPUT_COUNT ,
17141716 MAX_RECEIVED_TX_ADD_OUTPUT_COUNT ,
@@ -2638,7 +2640,7 @@ mod tests {
26382640 }
26392641
26402642 #[ test]
2641- fn test_need_to_add_funding_change_output_open ( ) {
2643+ fn test_calculate_change_output_value_open ( ) {
26422644 let input_prevouts = vec ! [
26432645 TxOut { value: Amount :: from_sat( 70_000 ) , script_pubkey: ScriptBuf :: new( ) } ,
26442646 TxOut { value: Amount :: from_sat( 60_000 ) , script_pubkey: ScriptBuf :: new( ) } ,
@@ -2654,7 +2656,7 @@ mod tests {
26542656 let common_fees = 126 ;
26552657 {
26562658 // There is leftover for change
2657- let res = need_to_add_funding_change_output (
2659+ let res = calculate_change_output_value (
26582660 true ,
26592661 our_contributed,
26602662 & input_prevouts,
@@ -2666,7 +2668,7 @@ mod tests {
26662668 }
26672669 {
26682670 // There is leftover for change, without common fees
2669- let res = need_to_add_funding_change_output (
2671+ let res = calculate_change_output_value (
26702672 false ,
26712673 our_contributed,
26722674 & input_prevouts,
@@ -2678,7 +2680,7 @@ mod tests {
26782680 }
26792681 {
26802682 // Larger fee, smaller change
2681- let res = need_to_add_funding_change_output (
2683+ let res = calculate_change_output_value (
26822684 true ,
26832685 our_contributed,
26842686 & input_prevouts,
@@ -2690,7 +2692,7 @@ mod tests {
26902692 }
26912693 {
26922694 // Insufficient inputs, no leftover
2693- let res = need_to_add_funding_change_output (
2695+ let res = calculate_change_output_value (
26942696 false ,
26952697 130_000 ,
26962698 & input_prevouts,
@@ -2702,7 +2704,7 @@ mod tests {
27022704 }
27032705 {
27042706 // Very small leftover
2705- let res = need_to_add_funding_change_output (
2707+ let res = calculate_change_output_value (
27062708 false ,
27072709 128_100 ,
27082710 & input_prevouts,
@@ -2714,7 +2716,7 @@ mod tests {
27142716 }
27152717 {
27162718 // Small leftover, but not dust
2717- let res = need_to_add_funding_change_output (
2719+ let res = calculate_change_output_value (
27182720 false ,
27192721 128_100 ,
27202722 & input_prevouts,
@@ -2727,7 +2729,7 @@ mod tests {
27272729 }
27282730
27292731 #[ test]
2730- fn test_need_to_add_funding_change_output_splice ( ) {
2732+ fn test_calculate_change_output_value_splice ( ) {
27312733 let input_prevouts = vec ! [
27322734 TxOut { value: Amount :: from_sat( 70_000 ) , script_pubkey: ScriptBuf :: new( ) } ,
27332735 TxOut { value: Amount :: from_sat( 60_000 ) , script_pubkey: ScriptBuf :: new( ) } ,
@@ -2743,7 +2745,7 @@ mod tests {
27432745 let common_fees = 126 ;
27442746 {
27452747 // There is leftover for change
2746- let res = need_to_add_funding_change_output (
2748+ let res = calculate_change_output_value (
27472749 true ,
27482750 our_contributed,
27492751 & input_prevouts,
@@ -2755,7 +2757,7 @@ mod tests {
27552757 }
27562758 {
27572759 // Very small leftover
2758- let res = need_to_add_funding_change_output (
2760+ let res = calculate_change_output_value (
27592761 false ,
27602762 128_100 ,
27612763 & input_prevouts,
@@ -2767,7 +2769,7 @@ mod tests {
27672769 }
27682770 {
27692771 // Small leftover, but not dust
2770- let res = need_to_add_funding_change_output (
2772+ let res = calculate_change_output_value (
27712773 false ,
27722774 128_100 ,
27732775 & input_prevouts,
0 commit comments