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