Skip to content

Commit a4cd059

Browse files
committed
Add type alias for the return type
1 parent cc5c279 commit a4cd059

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/branch_and_bound.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use bitcoin::amount::CheckedSum;
88
use bitcoin::{Amount, FeeRate, SignedAmount};
99

10-
use crate::WeightedUtxo;
10+
use crate::{Return, WeightedUtxo};
1111

1212
/// Performs a deterministic depth first branch and bound search for a changeless solution.
1313
///
@@ -152,7 +152,7 @@ pub fn select_coins_bnb<Utxo: WeightedUtxo>(
152152
fee_rate: FeeRate,
153153
long_term_fee_rate: FeeRate,
154154
weighted_utxos: &[Utxo],
155-
) -> Option<(u32, Vec<&Utxo>)> {
155+
) -> Return<Utxo> {
156156
// Total_Tries in Core:
157157
// https://github.com/bitcoin/bitcoin/blob/1d9da8da309d1dbf9aef15eb8dc43b4a2dc3d309/src/wallet/coinselection.cpp#L74
158158
const ITERATION_LIMIT: u32 = 100_000;

src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use rand::thread_rng;
2020
pub use crate::branch_and_bound::select_coins_bnb;
2121
pub use crate::single_random_draw::select_coins_srd;
2222

23+
pub(crate) type Return<'a, Utxo> = Option<(u32, Vec<&'a Utxo>)>;
24+
2325
// https://github.com/bitcoin/bitcoin/blob/f722a9bd132222d9d5cd503b5af25c905b205cdb/src/wallet/coinselection.h#L20
2426
const CHANGE_LOWER: Amount = Amount::from_sat(50_000);
2527

@@ -114,7 +116,7 @@ pub fn select_coins<Utxo: WeightedUtxo>(
114116
fee_rate: FeeRate,
115117
long_term_fee_rate: FeeRate,
116118
weighted_utxos: &[Utxo],
117-
) -> Option<(u32, Vec<&Utxo>)> {
119+
) -> Return<Utxo> {
118120
let bnb =
119121
select_coins_bnb(target, cost_of_change, fee_rate, long_term_fee_rate, weighted_utxos);
120122

src/single_random_draw.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bitcoin::blockdata::transaction::effective_value;
88
use bitcoin::{Amount, FeeRate};
99
use rand::seq::SliceRandom;
1010

11-
use crate::{WeightedUtxo, CHANGE_LOWER};
11+
use crate::{Return, WeightedUtxo, CHANGE_LOWER};
1212

1313
/// Randomize the input set and select coins until the target is reached.
1414
///
@@ -38,7 +38,7 @@ pub fn select_coins_srd<'a, R: rand::Rng + ?Sized, Utxo: WeightedUtxo>(
3838
fee_rate: FeeRate,
3939
weighted_utxos: &'a [Utxo],
4040
rng: &mut R,
41-
) -> Option<(u32, Vec<&'a Utxo>)> {
41+
) -> Return<'a, Utxo> {
4242
if target > Amount::MAX_MONEY {
4343
return None;
4444
}

0 commit comments

Comments
 (0)