@@ -200,7 +200,7 @@ pub fn calculate_waste(
200
200
) -> Result < Waste , Error > {
201
201
// Always consider the cost of spending an input now vs in the future.
202
202
let utxo_groups: Vec < OutputGroup > = selected
203
- . into_iter ( )
203
+ . iter ( )
204
204
. map ( |u| OutputGroup :: new ( u, fee_rate) )
205
205
. collect ( ) ;
206
206
@@ -342,16 +342,16 @@ impl<D: Database> CoinSelectionAlgorithm<D> for LargestFirstCoinSelection {
342
342
343
343
#[ derive( Debug , Clone ) ]
344
344
// Adds fee information to an UTXO.
345
- struct OutputGroup {
346
- weighted_utxo : WeightedUtxo ,
345
+ struct OutputGroup < ' u > {
346
+ weighted_utxo : & ' u WeightedUtxo ,
347
347
// Amount of fees for spending a certain utxo, calculated using a certain FeeRate
348
348
fee : u64 ,
349
349
// The effective value of the UTXO, i.e., the utxo value minus the fee for spending it
350
350
effective_value : i64 ,
351
351
}
352
352
353
- impl OutputGroup {
354
- fn new ( weighted_utxo : WeightedUtxo , fee_rate : FeeRate ) -> Self {
353
+ impl < ' u > OutputGroup < ' u > {
354
+ fn new ( weighted_utxo : & ' u WeightedUtxo , fee_rate : FeeRate ) -> Self {
355
355
let fee = fee_rate. fee_wu ( TXIN_BASE_WEIGHT + weighted_utxo. satisfaction_weight ) ;
356
356
let effective_value = weighted_utxo. utxo . txout ( ) . value as i64 - fee as i64 ;
357
357
OutputGroup {
@@ -399,14 +399,14 @@ impl<D: Database> CoinSelectionAlgorithm<D> for BranchAndBoundCoinSelection {
399
399
fee_amount : u64 ,
400
400
) -> Result < CoinSelectionResult , Error > {
401
401
// Mapping every (UTXO, usize) to an output group
402
- let required_utxos: Vec < OutputGroup > = required_utxos
403
- . into_iter ( )
402
+ let required_utxos: Vec < OutputGroup < ' _ > > = required_utxos
403
+ . iter ( )
404
404
. map ( |u| OutputGroup :: new ( u, fee_rate) )
405
405
. collect ( ) ;
406
406
407
407
// Mapping every (UTXO, usize) to an output group.
408
- let optional_utxos: Vec < OutputGroup > = optional_utxos
409
- . into_iter ( )
408
+ let optional_utxos: Vec < OutputGroup < ' _ > > = optional_utxos
409
+ . iter ( )
410
410
. map ( |u| OutputGroup :: new ( u, fee_rate) )
411
411
. collect ( ) ;
412
412
@@ -474,8 +474,8 @@ impl BranchAndBoundCoinSelection {
474
474
#[ allow( clippy:: too_many_arguments) ]
475
475
fn bnb (
476
476
& self ,
477
- required_utxos : Vec < OutputGroup > ,
478
- mut optional_utxos : Vec < OutputGroup > ,
477
+ required_utxos : Vec < OutputGroup < ' _ > > ,
478
+ mut optional_utxos : Vec < OutputGroup < ' _ > > ,
479
479
mut curr_value : i64 ,
480
480
mut curr_available_value : i64 ,
481
481
actual_target : i64 ,
@@ -583,8 +583,8 @@ impl BranchAndBoundCoinSelection {
583
583
584
584
fn single_random_draw (
585
585
& self ,
586
- required_utxos : Vec < OutputGroup > ,
587
- mut optional_utxos : Vec < OutputGroup > ,
586
+ required_utxos : Vec < OutputGroup < ' _ > > ,
587
+ mut optional_utxos : Vec < OutputGroup < ' _ > > ,
588
588
curr_value : i64 ,
589
589
actual_target : i64 ,
590
590
fee_amount : u64 ,
@@ -613,16 +613,16 @@ impl BranchAndBoundCoinSelection {
613
613
BranchAndBoundCoinSelection :: calculate_cs_result ( selected_utxos, required_utxos, fee_amount)
614
614
}
615
615
616
- fn calculate_cs_result (
617
- mut selected_utxos : Vec < OutputGroup > ,
618
- mut required_utxos : Vec < OutputGroup > ,
616
+ fn calculate_cs_result < ' u > (
617
+ mut selected_utxos : Vec < OutputGroup < ' u > > ,
618
+ mut required_utxos : Vec < OutputGroup < ' u > > ,
619
619
mut fee_amount : u64 ,
620
620
) -> CoinSelectionResult {
621
621
selected_utxos. append ( & mut required_utxos) ;
622
622
fee_amount += selected_utxos. iter ( ) . map ( |u| u. fee ) . sum :: < u64 > ( ) ;
623
623
let selected = selected_utxos
624
624
. into_iter ( )
625
- . map ( |u| u. weighted_utxo . utxo )
625
+ . map ( |u| u. weighted_utxo . utxo . clone ( ) )
626
626
. collect :: < Vec < _ > > ( ) ;
627
627
628
628
CoinSelectionResult :: new ( selected, fee_amount, None )
@@ -1030,8 +1030,8 @@ mod test {
1030
1030
#[ should_panic( expected = "BnBNoExactMatch" ) ]
1031
1031
fn test_bnb_function_no_exact_match ( ) {
1032
1032
let fee_rate = FeeRate :: from_sat_per_vb ( 10.0 ) ;
1033
- let utxos: Vec < OutputGroup > = get_test_utxos ( )
1034
- . into_iter ( )
1033
+ let utxos: Vec < OutputGroup < ' _ > > = get_test_utxos ( )
1034
+ . iter ( )
1035
1035
. map ( |u| OutputGroup :: new ( u, fee_rate) )
1036
1036
. collect ( ) ;
1037
1037
@@ -1057,7 +1057,7 @@ mod test {
1057
1057
fn test_bnb_function_tries_exceeded ( ) {
1058
1058
let fee_rate = FeeRate :: from_sat_per_vb ( 10.0 ) ;
1059
1059
let utxos: Vec < OutputGroup > = generate_same_value_utxos ( 100_000 , 100_000 )
1060
- . into_iter ( )
1060
+ . iter ( )
1061
1061
. map ( |u| OutputGroup :: new ( u, fee_rate) )
1062
1062
. collect ( ) ;
1063
1063
@@ -1087,7 +1087,7 @@ mod test {
1087
1087
let cost_of_change = size_of_change as f32 * fee_rate. as_sat_vb ( ) ;
1088
1088
1089
1089
let utxos: Vec < _ > = generate_same_value_utxos ( 50_000 , 10 )
1090
- . into_iter ( )
1090
+ . iter ( )
1091
1091
. map ( |u| OutputGroup :: new ( u, fee_rate) )
1092
1092
. collect ( ) ;
1093
1093
@@ -1123,7 +1123,7 @@ mod test {
1123
1123
1124
1124
for _ in 0 ..200 {
1125
1125
let optional_utxos: Vec < _ > = generate_random_utxos ( & mut rng, 40 )
1126
- . into_iter ( )
1126
+ . iter ( )
1127
1127
. map ( |u| OutputGroup :: new ( u, fee_rate) )
1128
1128
. collect ( ) ;
1129
1129
0 commit comments