@@ -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) ?;
@@ -2740,7 +2753,7 @@ pub(crate) mod test {
2740
2753
}
2741
2754
2742
2755
#[ test]
2743
- #[ should_panic( expected = "InsufficientFunds" ) ]
2756
+ // #[should_panic(expected = "InsufficientFunds")]
2744
2757
fn test_create_tx_absolute_high_fee ( ) {
2745
2758
let ( wallet, _, _) = get_funded_wallet ( get_test_wpkh ( ) ) ;
2746
2759
let addr = wallet. get_address ( New ) . unwrap ( ) ;
@@ -2749,7 +2762,10 @@ pub(crate) mod test {
2749
2762
. drain_to ( addr. script_pubkey ( ) )
2750
2763
. drain_wallet ( )
2751
2764
. fee_absolute ( 60_000 ) ;
2752
- let ( _psbt, _details) = builder. finish ( ) . unwrap ( ) ;
2765
+ // let (_psbt, _details) = builder.finish().unwrap();
2766
+ assert ! (
2767
+ matches!( builder. finish( ) , Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" ) )
2768
+ ) ;
2753
2769
}
2754
2770
2755
2771
#[ test]
@@ -2786,7 +2802,7 @@ pub(crate) mod test {
2786
2802
}
2787
2803
2788
2804
#[ test]
2789
- #[ should_panic( expected = "InsufficientFunds" ) ]
2805
+ // #[should_panic(expected = "InsufficientFunds")]
2790
2806
fn test_create_tx_drain_to_dust_amount ( ) {
2791
2807
let ( wallet, _, _) = get_funded_wallet ( get_test_wpkh ( ) ) ;
2792
2808
let addr = wallet. get_address ( New ) . unwrap ( ) ;
@@ -2796,7 +2812,10 @@ pub(crate) mod test {
2796
2812
. drain_to ( addr. script_pubkey ( ) )
2797
2813
. drain_wallet ( )
2798
2814
. fee_rate ( FeeRate :: from_sat_per_vb ( 455.0 ) ) ;
2799
- builder. finish ( ) . unwrap ( ) ;
2815
+ // builder.finish().unwrap();
2816
+ assert ! (
2817
+ matches!( builder. finish( ) , Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" ) )
2818
+ ) ;
2800
2819
}
2801
2820
2802
2821
#[ test]
@@ -3042,7 +3061,7 @@ pub(crate) mod test {
3042
3061
}
3043
3062
3044
3063
#[ test]
3045
- #[ should_panic( expected = "InsufficientFunds" ) ]
3064
+ // #[should_panic(expected = "InsufficientFunds")]
3046
3065
fn test_create_tx_manually_selected_insufficient ( ) {
3047
3066
let ( wallet, descriptors, _) = get_funded_wallet ( get_test_wpkh ( ) ) ;
3048
3067
let small_output_txid = crate :: populate_test_db!(
@@ -3061,7 +3080,10 @@ pub(crate) mod test {
3061
3080
} )
3062
3081
. unwrap ( )
3063
3082
. manually_selected_only ( ) ;
3064
- builder. finish ( ) . unwrap ( ) ;
3083
+ // builder.finish().unwrap();
3084
+ assert ! (
3085
+ matches!( builder. finish( ) , Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" ) )
3086
+ ) ;
3065
3087
}
3066
3088
3067
3089
#[ test]
@@ -3780,7 +3802,7 @@ pub(crate) mod test {
3780
3802
}
3781
3803
3782
3804
#[ test]
3783
- #[ should_panic( expected = "InsufficientFunds" ) ]
3805
+ // #[should_panic(expected = "InsufficientFunds")]
3784
3806
fn test_bump_fee_remove_output_manually_selected_only ( ) {
3785
3807
let ( wallet, descriptors, _) = get_funded_wallet ( get_test_wpkh ( ) ) ;
3786
3808
// receive an extra tx so that our wallet has two utxos. then we manually pick only one of
@@ -3828,11 +3850,15 @@ pub(crate) mod test {
3828
3850
builder
3829
3851
. manually_selected_only ( )
3830
3852
. fee_rate ( FeeRate :: from_sat_per_vb ( 255.0 ) ) ;
3831
- builder. finish ( ) . unwrap ( ) ;
3853
+ // builder.finish().unwrap();
3854
+ assert ! (
3855
+ matches!( builder. finish( ) , Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" ) )
3856
+ ) ;
3832
3857
}
3833
3858
3834
3859
#[ test]
3835
3860
fn test_bump_fee_add_input ( ) {
3861
+ // funded wallet already has 50_000 utxo
3836
3862
let ( wallet, descriptors, _) = get_funded_wallet ( get_test_wpkh ( ) ) ;
3837
3863
crate :: populate_test_db!(
3838
3864
wallet. database. borrow_mut( ) ,
@@ -4254,7 +4280,7 @@ pub(crate) mod test {
4254
4280
}
4255
4281
4256
4282
#[ test]
4257
- #[ should_panic( expected = "InsufficientFunds" ) ]
4283
+ // #[should_panic(expected = "InsufficientFunds")]
4258
4284
fn test_bump_fee_unconfirmed_inputs_only ( ) {
4259
4285
// We try to bump the fee, but:
4260
4286
// - We can't reduce the change, as we have no change
@@ -4296,7 +4322,10 @@ pub(crate) mod test {
4296
4322
4297
4323
let mut builder = wallet. build_fee_bump ( txid) . unwrap ( ) ;
4298
4324
builder. fee_rate ( FeeRate :: from_sat_per_vb ( 25.0 ) ) ;
4299
- builder. finish ( ) . unwrap ( ) ;
4325
+ assert ! (
4326
+ matches!( builder. finish( ) , Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" ) )
4327
+ ) ;
4328
+ // builder.finish().unwrap();
4300
4329
}
4301
4330
4302
4331
#[ test]
@@ -5556,25 +5585,33 @@ pub(crate) mod test {
5556
5585
. add_recipient ( addr. script_pubkey ( ) , balance. immature / 2 )
5557
5586
. current_height ( confirmation_time) ;
5558
5587
assert ! ( matches!(
5559
- builder. finish( ) . unwrap_err( ) ,
5560
- Error :: InsufficientFunds {
5561
- needed: _,
5562
- available: 0
5563
- }
5588
+ builder. finish( ) ,
5589
+ Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" )
5564
5590
) ) ;
5591
+ // assert!(matches!(
5592
+ // builder.finish().unwrap_err(),
5593
+ // Error::InsufficientFunds {
5594
+ // needed: _,
5595
+ // available: 0
5596
+ // }
5597
+ // ));
5565
5598
5566
5599
// Still unspendable...
5567
5600
let mut builder = wallet. build_tx ( ) ;
5568
5601
builder
5569
5602
. add_recipient ( addr. script_pubkey ( ) , balance. immature / 2 )
5570
5603
. current_height ( not_yet_mature_time) ;
5571
5604
assert ! ( matches!(
5572
- builder. finish( ) . unwrap_err( ) ,
5573
- Error :: InsufficientFunds {
5574
- needed: _,
5575
- available: 0
5576
- }
5605
+ builder. finish( ) ,
5606
+ Err ( Error :: Generic ( s) ) if s. contains( "insufficient coins" )
5577
5607
) ) ;
5608
+ // assert!(matches!(
5609
+ // builder.finish().unwrap_err(),
5610
+ // Error::InsufficientFunds {
5611
+ // needed: _,
5612
+ // available: 0
5613
+ // }
5614
+ // ));
5578
5615
5579
5616
// ...Now the coinbase is mature :)
5580
5617
let sync_time = SyncTime {
0 commit comments