Skip to content

Commit 39d0dd4

Browse files
committed
f Account for BroadcasterInterface taking a slice
1 parent 36e06b1 commit 39d0dd4

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
@@ -565,7 +565,7 @@ where
565565
&Secp256k1::new(),
566566
);
567567
match res {
568-
Ok(spending_tx) => self.wallet.broadcast_transaction(&spending_tx),
568+
Ok(spending_tx) => self.wallet.broadcast_transactions(&[&spending_tx]),
569569
Err(err) => {
570570
log_error!(self.logger, "Error spending outputs: {:?}", err);
571571
}

src/wallet.rs

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

257-
self.broadcast_transaction(&tx);
257+
self.broadcast_transactions(&[&tx]);
258258

259259
let txid = tx.txid();
260260

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

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

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

0 commit comments

Comments
 (0)