Skip to content

Commit 9d0ab0b

Browse files
committed
f Account for BroadcasterInterface taking a slice
1 parent 6aa1be4 commit 9d0ab0b

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ where
560560
&Secp256k1::new(),
561561
);
562562
match res {
563-
Ok(spending_tx) => self.wallet.broadcast_transaction(&spending_tx),
563+
Ok(spending_tx) => self.wallet.broadcast_transactions(&[&spending_tx]),
564564
Err(err) => {
565565
log_error!(self.logger, "Error spending outputs: {:?}", err);
566566
}

src/wallet.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ where
252252
psbt.extract_tx()
253253
};
254254

255-
self.broadcast_transaction(&tx);
255+
self.broadcast_transactions(&[&tx]);
256256

257257
let txid = tx.txid();
258258

@@ -306,26 +306,31 @@ impl<D> BroadcasterInterface for Wallet<D>
306306
where
307307
D: BatchDatabase,
308308
{
309-
fn broadcast_transaction(&self, tx: &Transaction) {
309+
fn broadcast_transactions(&self, txs: &[&Transaction]) {
310310
let locked_runtime = self.runtime.read().unwrap();
311311
if locked_runtime.as_ref().is_none() {
312312
log_error!(self.logger, "Failed to broadcast transaction: No runtime.");
313313
return;
314314
}
315315

316-
let res = tokio::task::block_in_place(move || {
317-
locked_runtime
318-
.as_ref()
319-
.unwrap()
320-
.block_on(async move { self.blockchain.broadcast(tx).await })
321-
});
316+
let bcast_logger = Arc::clone(&self.logger);
317+
tokio::task::block_in_place(move || {
318+
locked_runtime.as_ref().unwrap().block_on(async move {
319+
let mut handles = Vec::new();
320+
for tx in txs {
321+
handles.push(self.blockchain.broadcast(tx));
322+
}
322323

323-
match res {
324-
Ok(_) => {}
325-
Err(err) => {
326-
log_error!(self.logger, "Failed to broadcast transaction: {}", err);
327-
}
328-
}
324+
for handle in handles {
325+
match handle.await {
326+
Ok(_) => {}
327+
Err(err) => {
328+
log_error!(bcast_logger, "Failed to broadcast transaction: {}", err);
329+
}
330+
}
331+
}
332+
})
333+
});
329334
}
330335
}
331336

0 commit comments

Comments
 (0)