Skip to content

Commit 649b65c

Browse files
committed
f Account for BroadcasterInterface taking a slice
1 parent f05a7ca commit 649b65c

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ where
564564
&Secp256k1::new(),
565565
);
566566
match res {
567-
Ok(Some(spending_tx)) => self.wallet.broadcast_transaction(&spending_tx),
567+
Ok(Some(spending_tx)) => self.wallet.broadcast_transactions(&[&spending_tx]),
568568
Ok(None) => {
569569
log_debug!(self.logger, "Omitted spending static outputs: {:?}", outputs);
570570
}

src/wallet.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ where
249249
psbt.extract_tx()
250250
};
251251

252-
self.broadcast_transaction(&tx);
252+
self.broadcast_transactions(&[&tx]);
253253

254254
let txid = tx.txid();
255255

@@ -305,25 +305,36 @@ where
305305
D: BatchDatabase,
306306
L::Target: Logger,
307307
{
308-
fn broadcast_transaction(&self, tx: &Transaction) {
308+
fn broadcast_transactions(&self, txs: &[&Transaction]) {
309309
let locked_runtime = self.runtime.read().unwrap();
310310
if locked_runtime.as_ref().is_none() {
311311
log_error!(self.logger, "Failed to broadcast transaction: No runtime.");
312312
return;
313313
}
314314

315-
let res = tokio::task::block_in_place(move || {
316-
locked_runtime
317-
.as_ref()
318-
.unwrap()
319-
.block_on(async move { self.blockchain.broadcast(tx).await })
315+
let errors = tokio::task::block_in_place(move || {
316+
locked_runtime.as_ref().unwrap().block_on(async move {
317+
let mut handles = Vec::new();
318+
let mut errors = Vec::new();
319+
320+
for tx in txs {
321+
handles.push(self.blockchain.broadcast(tx));
322+
}
323+
324+
for handle in handles {
325+
match handle.await {
326+
Ok(_) => {}
327+
Err(e) => {
328+
errors.push(e);
329+
}
330+
}
331+
}
332+
errors
333+
})
320334
});
321335

322-
match res {
323-
Ok(_) => {}
324-
Err(err) => {
325-
log_error!(self.logger, "Failed to broadcast transaction: {}", err);
326-
}
336+
for e in errors {
337+
log_error!(self.logger, "Failed to broadcast transaction: {}", e);
327338
}
328339
}
329340
}

0 commit comments

Comments
 (0)