Skip to content

Commit

Permalink
Merge pull request #242 from rustaceanrob/broadcast-random-12-18
Browse files Browse the repository at this point in the history
Add random broadcast method
  • Loading branch information
rustaceanrob authored Dec 18, 2024
2 parents 1b624a2 + e3e3d06 commit 37f8c5a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/core/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 37f8c5a

Please sign in to comment.