Skip to content

Commit 23f6e7c

Browse files
committed
Add cost_of_change to coin_select parameters
1 parent 6d3552c commit 23f6e7c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/wallet/coin_selection.rs

+17
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
//! fee_rate: FeeRate,
4343
//! amount_needed: u64,
4444
//! fee_amount: u64,
45+
//! cost_of_change: Option<u64>,
4546
//! ) -> Result<CoinSelectionResult, bdk::Error> {
4647
//! let mut selected_amount = 0;
4748
//! let mut additional_weight = 0;
@@ -237,6 +238,7 @@ pub trait CoinSelectionAlgorithm<D: Database>: std::fmt::Debug {
237238
fee_rate: FeeRate,
238239
amount_needed: u64,
239240
fee_amount: u64,
241+
cost_of_change: Option<u64>,
240242
) -> Result<CoinSelectionResult, Error>;
241243
}
242244

@@ -256,6 +258,7 @@ impl<D: Database> CoinSelectionAlgorithm<D> for LargestFirstCoinSelection {
256258
fee_rate: FeeRate,
257259
amount_needed: u64,
258260
mut fee_amount: u64,
261+
cost_of_change: Option<u64>,
259262
) -> Result<CoinSelectionResult, Error> {
260263
log::debug!(
261264
"amount_needed = `{}`, fee_amount = `{}`, fee_rate = `{:?}`",
@@ -370,6 +373,7 @@ impl<D: Database> CoinSelectionAlgorithm<D> for BranchAndBoundCoinSelection {
370373
fee_rate: FeeRate,
371374
amount_needed: u64,
372375
fee_amount: u64,
376+
cost_of_change: Option<u64>,
373377
) -> Result<CoinSelectionResult, Error> {
374378
// Mapping every (UTXO, usize) to an output group
375379
let required_utxos: Vec<OutputGroup<'_>> = required_utxos
@@ -735,6 +739,7 @@ mod test {
735739
FeeRate::from_sat_per_vb(1.0),
736740
250_000,
737741
FEE_AMOUNT,
742+
None,
738743
)
739744
.unwrap();
740745

@@ -756,6 +761,7 @@ mod test {
756761
FeeRate::from_sat_per_vb(1.0),
757762
20_000,
758763
FEE_AMOUNT,
764+
None,
759765
)
760766
.unwrap();
761767

@@ -777,6 +783,7 @@ mod test {
777783
FeeRate::from_sat_per_vb(1.0),
778784
20_000,
779785
FEE_AMOUNT,
786+
None,
780787
)
781788
.unwrap();
782789

@@ -799,6 +806,7 @@ mod test {
799806
FeeRate::from_sat_per_vb(1.0),
800807
500_000,
801808
FEE_AMOUNT,
809+
None,
802810
)
803811
.unwrap();
804812
}
@@ -817,6 +825,7 @@ mod test {
817825
FeeRate::from_sat_per_vb(1000.0),
818826
250_000,
819827
FEE_AMOUNT,
828+
None,
820829
)
821830
.unwrap();
822831
}
@@ -837,6 +846,7 @@ mod test {
837846
FeeRate::from_sat_per_vb(1.0),
838847
250_000,
839848
FEE_AMOUNT,
849+
None,
840850
)
841851
.unwrap();
842852

@@ -858,6 +868,7 @@ mod test {
858868
FeeRate::from_sat_per_vb(1.0),
859869
20_000,
860870
FEE_AMOUNT,
871+
None,
861872
)
862873
.unwrap();
863874

@@ -879,6 +890,7 @@ mod test {
879890
FeeRate::from_sat_per_vb(1.0),
880891
299756,
881892
FEE_AMOUNT,
893+
None,
882894
)
883895
.unwrap();
884896

@@ -910,6 +922,7 @@ mod test {
910922
FeeRate::from_sat_per_vb(1.0),
911923
150_000,
912924
FEE_AMOUNT,
925+
None,
913926
)
914927
.unwrap();
915928

@@ -932,6 +945,7 @@ mod test {
932945
FeeRate::from_sat_per_vb(1.0),
933946
500_000,
934947
FEE_AMOUNT,
948+
None,
935949
)
936950
.unwrap();
937951
}
@@ -950,6 +964,7 @@ mod test {
950964
FeeRate::from_sat_per_vb(1000.0),
951965
250_000,
952966
FEE_AMOUNT,
967+
None,
953968
)
954969
.unwrap();
955970
}
@@ -967,6 +982,7 @@ mod test {
967982
FeeRate::from_sat_per_vb(1.0),
968983
99932, // first utxo's effective value
969984
0,
985+
None,
970986
)
971987
.unwrap();
972988

@@ -994,6 +1010,7 @@ mod test {
9941010
FeeRate::from_sat_per_vb(0.0),
9951011
target_amount,
9961012
0,
1013+
None,
9971014
)
9981015
.unwrap();
9991016
assert_eq!(result.selected_amount(), target_amount);

src/wallet/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,8 @@ where
751751
fee_rate,
752752
outgoing,
753753
fee_amount,
754+
// REVIEW: Add cost_of_change to TxParams
755+
None,
754756
)?;
755757
let mut fee_amount = coin_selection.fee_amount;
756758

0 commit comments

Comments
 (0)