@@ -924,6 +924,17 @@ where
924
924
} ;
925
925
926
926
let selection = coin_selection. coin_select ( & raw_candidates, selector) ?;
927
+ let ( _, excess_strategy) = selection. best_strategy ( ) ;
928
+ println ! (
929
+ "create_tx: weight={}, fee={}, feerate={}sats/wu" ,
930
+ excess_strategy. weight,
931
+ excess_strategy. fee,
932
+ excess_strategy. feerate( )
933
+ ) ;
934
+ println ! (
935
+ "create_tx: feerate={}sats/vb" ,
936
+ excess_strategy. feerate( ) * 4.0
937
+ ) ;
927
938
928
939
// fee_amount += coin_selection.fee_amount;
929
940
// let excess = &coin_selection.excess;
@@ -938,8 +949,6 @@ where
938
949
} )
939
950
. collect ( ) ;
940
951
941
- let ( _, excess_strategy) = selection. best_strategy ( ) ;
942
-
943
952
if let Some ( drain_value) = excess_strategy. drain_value {
944
953
tx. output . push ( TxOut {
945
954
value : drain_value,
@@ -1016,23 +1025,27 @@ where
1016
1025
. map ( |utxo| utxo. utxo . clone ( ) )
1017
1026
. collect :: < Vec < _ > > ( ) ;
1018
1027
1019
- let sent = selected. iter ( ) . map ( |utxo| utxo. txout ( ) . value ) . sum :: < u64 > ( ) ;
1028
+ let sent = selected
1029
+ . iter ( )
1030
+ . filter ( |utxo| {
1031
+ self . database
1032
+ . borrow ( )
1033
+ . is_mine ( & utxo. txout ( ) . script_pubkey )
1034
+ . unwrap_or ( false )
1035
+ } )
1036
+ . map ( |utxo| utxo. txout ( ) . value )
1037
+ . sum :: < u64 > ( ) ;
1020
1038
1021
1039
let received = tx
1022
1040
. output
1023
1041
. iter ( )
1024
- . map ( |txo| {
1025
- if self
1026
- . database
1042
+ . filter ( |txo| {
1043
+ self . database
1027
1044
. borrow ( )
1028
1045
. is_mine ( & txo. script_pubkey )
1029
1046
. unwrap_or ( false )
1030
- {
1031
- txo. value
1032
- } else {
1033
- 0
1034
- }
1035
1047
} )
1048
+ . map ( |txo| txo. value )
1036
1049
. sum :: < u64 > ( ) ;
1037
1050
1038
1051
let psbt = self . complete_transaction ( tx, selected, params) ?;
@@ -2748,7 +2761,7 @@ pub(crate) mod test {
2748
2761
}
2749
2762
2750
2763
#[ test]
2751
- #[ should_panic( expected = "InsufficientFunds" ) ]
2764
+ // #[should_panic(expected = "InsufficientFunds")]
2752
2765
fn test_create_tx_absolute_high_fee ( ) {
2753
2766
let ( wallet, _, _) = get_funded_wallet ( get_test_wpkh ( ) ) ;
2754
2767
let addr = wallet. get_address ( New ) . unwrap ( ) ;
@@ -2757,7 +2770,10 @@ pub(crate) mod test {
2757
2770
. drain_to ( addr. script_pubkey ( ) )
2758
2771
. drain_wallet ( )
2759
2772
. fee_absolute ( 60_000 ) ;
2760
- let ( _psbt, _details) = builder. finish ( ) . unwrap ( ) ;
2773
+ // let (_psbt, _details) = builder.finish().unwrap();
2774
+ assert ! (
2775
+ matches!( builder. finish( ) , Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" ) )
2776
+ ) ;
2761
2777
}
2762
2778
2763
2779
#[ test]
@@ -2794,7 +2810,7 @@ pub(crate) mod test {
2794
2810
}
2795
2811
2796
2812
#[ test]
2797
- #[ should_panic( expected = "InsufficientFunds" ) ]
2813
+ // #[should_panic(expected = "InsufficientFunds")]
2798
2814
fn test_create_tx_drain_to_dust_amount ( ) {
2799
2815
let ( wallet, _, _) = get_funded_wallet ( get_test_wpkh ( ) ) ;
2800
2816
let addr = wallet. get_address ( New ) . unwrap ( ) ;
@@ -2804,7 +2820,10 @@ pub(crate) mod test {
2804
2820
. drain_to ( addr. script_pubkey ( ) )
2805
2821
. drain_wallet ( )
2806
2822
. fee_rate ( FeeRate :: from_sat_per_vb ( 455.0 ) ) ;
2807
- builder. finish ( ) . unwrap ( ) ;
2823
+ // builder.finish().unwrap();
2824
+ assert ! (
2825
+ matches!( builder. finish( ) , Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" ) )
2826
+ ) ;
2808
2827
}
2809
2828
2810
2829
#[ test]
@@ -3050,7 +3069,7 @@ pub(crate) mod test {
3050
3069
}
3051
3070
3052
3071
#[ test]
3053
- #[ should_panic( expected = "InsufficientFunds" ) ]
3072
+ // #[should_panic(expected = "InsufficientFunds")]
3054
3073
fn test_create_tx_manually_selected_insufficient ( ) {
3055
3074
let ( wallet, descriptors, _) = get_funded_wallet ( get_test_wpkh ( ) ) ;
3056
3075
let small_output_txid = crate :: populate_test_db!(
@@ -3069,7 +3088,10 @@ pub(crate) mod test {
3069
3088
} )
3070
3089
. unwrap ( )
3071
3090
. manually_selected_only ( ) ;
3072
- builder. finish ( ) . unwrap ( ) ;
3091
+ // builder.finish().unwrap();
3092
+ assert ! (
3093
+ matches!( builder. finish( ) , Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" ) )
3094
+ ) ;
3073
3095
}
3074
3096
3075
3097
#[ test]
@@ -3788,7 +3810,7 @@ pub(crate) mod test {
3788
3810
}
3789
3811
3790
3812
#[ test]
3791
- #[ should_panic( expected = "InsufficientFunds" ) ]
3813
+ // #[should_panic(expected = "InsufficientFunds")]
3792
3814
fn test_bump_fee_remove_output_manually_selected_only ( ) {
3793
3815
let ( wallet, descriptors, _) = get_funded_wallet ( get_test_wpkh ( ) ) ;
3794
3816
// receive an extra tx so that our wallet has two utxos. then we manually pick only one of
@@ -3836,11 +3858,15 @@ pub(crate) mod test {
3836
3858
builder
3837
3859
. manually_selected_only ( )
3838
3860
. fee_rate ( FeeRate :: from_sat_per_vb ( 255.0 ) ) ;
3839
- builder. finish ( ) . unwrap ( ) ;
3861
+ // builder.finish().unwrap();
3862
+ assert ! (
3863
+ matches!( builder. finish( ) , Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" ) )
3864
+ ) ;
3840
3865
}
3841
3866
3842
3867
#[ test]
3843
3868
fn test_bump_fee_add_input ( ) {
3869
+ // funded wallet already has 50_000 utxo
3844
3870
let ( wallet, descriptors, _) = get_funded_wallet ( get_test_wpkh ( ) ) ;
3845
3871
crate :: populate_test_db!(
3846
3872
wallet. database. borrow_mut( ) ,
@@ -4262,7 +4288,7 @@ pub(crate) mod test {
4262
4288
}
4263
4289
4264
4290
#[ test]
4265
- #[ should_panic( expected = "InsufficientFunds" ) ]
4291
+ // #[should_panic(expected = "InsufficientFunds")]
4266
4292
fn test_bump_fee_unconfirmed_inputs_only ( ) {
4267
4293
// We try to bump the fee, but:
4268
4294
// - We can't reduce the change, as we have no change
@@ -4304,7 +4330,10 @@ pub(crate) mod test {
4304
4330
4305
4331
let mut builder = wallet. build_fee_bump ( txid) . unwrap ( ) ;
4306
4332
builder. fee_rate ( FeeRate :: from_sat_per_vb ( 25.0 ) ) ;
4307
- builder. finish ( ) . unwrap ( ) ;
4333
+ assert ! (
4334
+ matches!( builder. finish( ) , Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" ) )
4335
+ ) ;
4336
+ // builder.finish().unwrap();
4308
4337
}
4309
4338
4310
4339
#[ test]
@@ -5564,25 +5593,33 @@ pub(crate) mod test {
5564
5593
. add_recipient ( addr. script_pubkey ( ) , balance. immature / 2 )
5565
5594
. current_height ( confirmation_time) ;
5566
5595
assert ! ( matches!(
5567
- builder. finish( ) . unwrap_err( ) ,
5568
- Error :: InsufficientFunds {
5569
- needed: _,
5570
- available: 0
5571
- }
5596
+ builder. finish( ) ,
5597
+ Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" )
5572
5598
) ) ;
5599
+ // assert!(matches!(
5600
+ // builder.finish().unwrap_err(),
5601
+ // Error::InsufficientFunds {
5602
+ // needed: _,
5603
+ // available: 0
5604
+ // }
5605
+ // ));
5573
5606
5574
5607
// Still unspendable...
5575
5608
let mut builder = wallet. build_tx ( ) ;
5576
5609
builder
5577
5610
. add_recipient ( addr. script_pubkey ( ) , balance. immature / 2 )
5578
5611
. current_height ( not_yet_mature_time) ;
5579
5612
assert ! ( matches!(
5580
- builder. finish( ) . unwrap_err( ) ,
5581
- Error :: InsufficientFunds {
5582
- needed: _,
5583
- available: 0
5584
- }
5613
+ builder. finish( ) ,
5614
+ Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" )
5585
5615
) ) ;
5616
+ // assert!(matches!(
5617
+ // builder.finish().unwrap_err(),
5618
+ // Error::InsufficientFunds {
5619
+ // needed: _,
5620
+ // available: 0
5621
+ // }
5622
+ // ));
5586
5623
5587
5624
// ...Now the coinbase is mature :)
5588
5625
let sync_time = SyncTime {
0 commit comments