File tree 1 file changed +16
-11
lines changed
1 file changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,7 @@ use rand::seq::SliceRandom;
109
109
use rand:: thread_rng;
110
110
#[ cfg( test) ]
111
111
use rand:: { rngs:: StdRng , SeedableRng } ;
112
+ use std:: cell:: Cell ;
112
113
use std:: convert:: TryInto ;
113
114
114
115
/// Default coin selection algorithm used by [`TxBuilder`](super::tx_builder::TxBuilder) if not
@@ -131,7 +132,7 @@ pub struct CoinSelectionResult {
131
132
/// Total fee amount in satoshi
132
133
pub fee_amount : u64 ,
133
134
/// Waste value of current coin selection
134
- waste : Option < Waste > ,
135
+ waste : Cell < Option < Waste > > ,
135
136
}
136
137
137
138
impl CoinSelectionResult {
@@ -140,7 +141,7 @@ impl CoinSelectionResult {
140
141
CoinSelectionResult {
141
142
selected : selected_utxos,
142
143
fee_amount,
143
- waste : selection_waste,
144
+ waste : Cell :: new ( selection_waste) ,
144
145
}
145
146
}
146
147
@@ -168,16 +169,20 @@ impl CoinSelectionResult {
168
169
fee_rate : FeeRate ,
169
170
long_term_fee_rate : FeeRate ,
170
171
) -> Waste {
171
- match self . waste {
172
+ match self . waste . get ( ) {
172
173
Some ( waste) => waste,
173
- None => calculate_waste (
174
- selected,
175
- cost_of_change,
176
- target,
177
- fee_rate,
178
- long_term_fee_rate,
179
- )
180
- . unwrap ( ) ,
174
+ None => {
175
+ let calculated_waste = calculate_waste (
176
+ selected,
177
+ cost_of_change,
178
+ target,
179
+ fee_rate,
180
+ long_term_fee_rate,
181
+ )
182
+ . unwrap ( ) ;
183
+ self . waste . set ( Some ( calculated_waste) ) ;
184
+ calculated_waste
185
+ }
181
186
}
182
187
}
183
188
}
You can’t perform that action at this time.
0 commit comments