@@ -110,13 +110,16 @@ pub type DefaultCoinSelectionAlgorithm = LargestFirstCoinSelection; // make the
110
110
// prev_txid (32 bytes) + prev_vout (4 bytes) + sequence (4 bytes) + script_len (1 bytes)
111
111
pub ( crate ) const TXIN_BASE_WEIGHT : usize = ( 32 + 4 + 4 + 1 ) * 4 ;
112
112
113
+ pub type Waste = i64 ;
113
114
/// Result of a successful coin selection
114
115
#[ derive( Debug ) ]
115
116
pub struct CoinSelectionResult {
116
117
/// List of outputs selected for use as inputs
117
118
pub selected : Vec < Utxo > ,
118
119
/// Total fee amount in satoshi
119
120
pub fee_amount : u64 ,
121
+ /// Waste value of current coin selection
122
+ waste : Option < Waste > ,
120
123
}
121
124
122
125
impl CoinSelectionResult {
@@ -135,9 +138,28 @@ impl CoinSelectionResult {
135
138
} )
136
139
. sum ( )
137
140
}
138
- }
139
141
140
- type Waste = i64 ;
142
+ pub fn get_waste (
143
+ & self ,
144
+ selected : Vec < WeightedUtxo > ,
145
+ cost_of_change : Option < u64 > ,
146
+ target : u64 ,
147
+ fee_rate : FeeRate ,
148
+ long_term_fee_rate : FeeRate ,
149
+ ) -> Waste {
150
+ match self . waste {
151
+ Some ( waste) => waste,
152
+ None => calculate_waste (
153
+ selected,
154
+ cost_of_change,
155
+ target,
156
+ fee_rate,
157
+ long_term_fee_rate,
158
+ )
159
+ . unwrap ( ) ,
160
+ }
161
+ }
162
+ }
141
163
142
164
pub fn calculate_waste (
143
165
selected : Vec < WeightedUtxo > ,
@@ -152,7 +174,7 @@ pub fn calculate_waste(
152
174
. map ( |u| OutputGroup :: new ( u, fee_rate) )
153
175
. collect ( ) ;
154
176
155
- // if fee_rate < long_term_fee_rate timing cost can be negative
177
+ // If fee_rate < long_term_fee_rate timing cost can be negative
156
178
let timing_cost: i64 = utxo_groups. iter ( ) . fold ( 0 , |acc, utxo| {
157
179
let fee: i64 = utxo. fee as i64 ;
158
180
let long_term_fee: i64 = long_term_fee_rate
0 commit comments