@@ -1666,8 +1666,10 @@ impl InteractiveTxConstructor {
1666
1666
/// Determine whether a change output should be added or not, and if so, of what size,
1667
1667
/// considering our given inputs, outputs, and intended contribution.
1668
1668
/// 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.
1669
1671
#[ 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 (
1671
1673
is_initiator : bool , our_contribution : u64 , funding_inputs_prev_outputs : & Vec < TxOut > ,
1672
1674
funding_outputs : & Vec < OutputOwned > , funding_feerate_sat_per_1000_weight : u32 ,
1673
1675
holder_dust_limit_satoshis : u64 ,
@@ -1708,7 +1710,7 @@ mod tests {
1708
1710
use crate :: chain:: chaininterface:: { fee_for_weight, FEERATE_FLOOR_SATS_PER_KW } ;
1709
1711
use crate :: ln:: channel:: TOTAL_BITCOIN_SUPPLY_SATOSHIS ;
1710
1712
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 ,
1712
1714
HandleTxCompleteValue , InteractiveTxConstructor , InteractiveTxConstructorArgs ,
1713
1715
InteractiveTxMessageSend , MAX_INPUTS_OUTPUTS_COUNT , MAX_RECEIVED_TX_ADD_INPUT_COUNT ,
1714
1716
MAX_RECEIVED_TX_ADD_OUTPUT_COUNT ,
@@ -2638,7 +2640,7 @@ mod tests {
2638
2640
}
2639
2641
2640
2642
#[ test]
2641
- fn test_need_to_add_funding_change_output_open ( ) {
2643
+ fn test_calculate_change_output_value_open ( ) {
2642
2644
let input_prevouts = vec ! [
2643
2645
TxOut { value: Amount :: from_sat( 70_000 ) , script_pubkey: ScriptBuf :: new( ) } ,
2644
2646
TxOut { value: Amount :: from_sat( 60_000 ) , script_pubkey: ScriptBuf :: new( ) } ,
@@ -2654,7 +2656,7 @@ mod tests {
2654
2656
let common_fees = 126 ;
2655
2657
{
2656
2658
// There is leftover for change
2657
- let res = need_to_add_funding_change_output (
2659
+ let res = calculate_change_output_value (
2658
2660
true ,
2659
2661
our_contributed,
2660
2662
& input_prevouts,
@@ -2666,7 +2668,7 @@ mod tests {
2666
2668
}
2667
2669
{
2668
2670
// There is leftover for change, without common fees
2669
- let res = need_to_add_funding_change_output (
2671
+ let res = calculate_change_output_value (
2670
2672
false ,
2671
2673
our_contributed,
2672
2674
& input_prevouts,
@@ -2678,7 +2680,7 @@ mod tests {
2678
2680
}
2679
2681
{
2680
2682
// Larger fee, smaller change
2681
- let res = need_to_add_funding_change_output (
2683
+ let res = calculate_change_output_value (
2682
2684
true ,
2683
2685
our_contributed,
2684
2686
& input_prevouts,
@@ -2690,7 +2692,7 @@ mod tests {
2690
2692
}
2691
2693
{
2692
2694
// Insufficient inputs, no leftover
2693
- let res = need_to_add_funding_change_output (
2695
+ let res = calculate_change_output_value (
2694
2696
false ,
2695
2697
130_000 ,
2696
2698
& input_prevouts,
@@ -2702,7 +2704,7 @@ mod tests {
2702
2704
}
2703
2705
{
2704
2706
// Very small leftover
2705
- let res = need_to_add_funding_change_output (
2707
+ let res = calculate_change_output_value (
2706
2708
false ,
2707
2709
128_100 ,
2708
2710
& input_prevouts,
@@ -2714,7 +2716,7 @@ mod tests {
2714
2716
}
2715
2717
{
2716
2718
// Small leftover, but not dust
2717
- let res = need_to_add_funding_change_output (
2719
+ let res = calculate_change_output_value (
2718
2720
false ,
2719
2721
128_100 ,
2720
2722
& input_prevouts,
@@ -2727,7 +2729,7 @@ mod tests {
2727
2729
}
2728
2730
2729
2731
#[ test]
2730
- fn test_need_to_add_funding_change_output_splice ( ) {
2732
+ fn test_calculate_change_output_value_splice ( ) {
2731
2733
let input_prevouts = vec ! [
2732
2734
TxOut { value: Amount :: from_sat( 70_000 ) , script_pubkey: ScriptBuf :: new( ) } ,
2733
2735
TxOut { value: Amount :: from_sat( 60_000 ) , script_pubkey: ScriptBuf :: new( ) } ,
@@ -2743,7 +2745,7 @@ mod tests {
2743
2745
let common_fees = 126 ;
2744
2746
{
2745
2747
// There is leftover for change
2746
- let res = need_to_add_funding_change_output (
2748
+ let res = calculate_change_output_value (
2747
2749
true ,
2748
2750
our_contributed,
2749
2751
& input_prevouts,
@@ -2755,7 +2757,7 @@ mod tests {
2755
2757
}
2756
2758
{
2757
2759
// Very small leftover
2758
- let res = need_to_add_funding_change_output (
2760
+ let res = calculate_change_output_value (
2759
2761
false ,
2760
2762
128_100 ,
2761
2763
& input_prevouts,
@@ -2767,7 +2769,7 @@ mod tests {
2767
2769
}
2768
2770
{
2769
2771
// Small leftover, but not dust
2770
- let res = need_to_add_funding_change_output (
2772
+ let res = calculate_change_output_value (
2771
2773
false ,
2772
2774
128_100 ,
2773
2775
& input_prevouts,
0 commit comments