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