From e3e3d066f68201ef7aac8067b7cffbfe1fb5580e Mon Sep 17 00:00:00 2001 From: Rob N Date: Wed, 18 Dec 2024 08:32:15 -1000 Subject: [PATCH] feat(client): add random broadcast method --- src/core/client.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/core/client.rs b/src/core/client.rs index 75a8353..9b19858 100644 --- a/src/core/client.rs +++ b/src/core/client.rs @@ -3,6 +3,7 @@ use bitcoin::block::Header; use bitcoin::BlockHash; #[cfg(not(feature = "filter-control"))] use bitcoin::ScriptBuf; +use bitcoin::Transaction; use std::time::Duration; use tokio::sync::broadcast; pub use tokio::sync::broadcast::Receiver; @@ -149,6 +150,19 @@ macro_rules! impl_core_client { .map_err(|_| ClientError::SendError) } + /// Broadcast a new transaction to the network to a random peer. + /// + /// # Errors + /// + /// If the node has stopped running. + pub async fn broadcast_random(&self, tx: Transaction) -> Result<(), ClientError> { + let tx_broadcast = TxBroadcast::random_broadcast(tx); + self.ntx + .send(ClientMessage::Broadcast(tx_broadcast)) + .await + .map_err(|_| ClientError::SendError) + } + /// Broadcast a new transaction to the network from a synchronus context. /// /// # Errors