Skip to content

Commit 9b46601

Browse files
committed
f Filter once, simplify spend_spendable_outputs
1 parent 80dffe9 commit 9b46601

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/sweep.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,29 @@ where
6262
Self { outputs, wallet, keys_manager, kv_store, best_block, logger }
6363
}
6464

65-
pub(crate) fn add_outputs(&self, output_descriptors: Vec<SpendableOutputDescriptor>) {
65+
pub(crate) fn add_outputs(&self, mut output_descriptors: Vec<SpendableOutputDescriptor>) {
66+
let non_static_outputs = output_descriptors
67+
.drain(..)
68+
.filter(|desc| !matches!(desc, SpendableOutputDescriptor::StaticOutput { .. }))
69+
.collect::<Vec<_>>();
70+
6671
let mut locked_outputs = self.outputs.lock().unwrap();
6772

6873
let cur_height = self.best_block.lock().unwrap().height();
6974

7075
let (spending_tx, broadcast_height) =
71-
match self.get_spending_tx(&output_descriptors, cur_height) {
72-
Ok(Some(spending_tx)) => {
76+
match self.get_spending_tx(&non_static_outputs, cur_height) {
77+
Ok(spending_tx) => {
7378
self.wallet.broadcast_transactions(&[&spending_tx]);
7479
(Some(spending_tx), Some(cur_height))
7580
}
76-
Ok(None) => {
77-
log_debug!(
78-
self.logger,
79-
"Omitted spending static outputs: {:?}",
80-
output_descriptors
81-
);
82-
(None, None)
83-
}
8481
Err(e) => {
8582
log_error!(self.logger, "Error spending outputs: {:?}", e);
8683
(None, None)
8784
}
8885
};
8986

90-
for descriptor in output_descriptors {
87+
for descriptor in non_static_outputs {
9188
let id = self.keys_manager.get_secure_random_bytes();
9289
let output_info = SpendableOutputInfo {
9390
id,
@@ -109,7 +106,7 @@ where
109106

110107
fn get_spending_tx(
111108
&self, output_descriptors: &Vec<SpendableOutputDescriptor>, cur_height: u32,
112-
) -> Result<Option<Transaction>, ()> {
109+
) -> Result<Transaction, ()> {
113110
let tx_feerate =
114111
self.wallet.get_est_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee);
115112

0 commit comments

Comments
 (0)