From e05da9546c172d0d0671cbfa7732e32e3b93a860 Mon Sep 17 00:00:00 2001 From: rustaceanrob Date: Sun, 27 Oct 2024 14:59:04 -0400 Subject: [PATCH] feat: make `lib` types more robust --- src/lib.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9526dba..4a4e048 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -204,6 +204,14 @@ impl TxBroadcast { broadcast_policy, } } + + /// Prepare a transaction to be broadcasted to a random connection. + pub fn random_broadcast(tx: Transaction) -> Self { + Self { + tx, + broadcast_policy: TxBroadcastPolicy::RandomPeer, + } + } } /// The strategy for how this transaction should be shared with the network. @@ -273,8 +281,8 @@ impl TrustedPeer { } /// Create a new trusted peer using the default port for the network. - pub fn from_ip(ip_addr: IpAddr) -> Self { - let address = match ip_addr { + pub fn from_ip(ip_addr: impl Into) -> Self { + let address = match ip_addr.into() { IpAddr::V4(ip) => AddrV2::Ipv4(ip), IpAddr::V6(ip) => AddrV2::Ipv6(ip), }; @@ -286,7 +294,8 @@ impl TrustedPeer { } /// Create a new peer from a known address and port. - pub fn from_socket_addr(socket_addr: SocketAddr) -> Self { + pub fn from_socket_addr(socket_addr: impl Into) -> Self { + let socket_addr: SocketAddr = socket_addr.into(); let address = match socket_addr { SocketAddr::V4(ip) => AddrV2::Ipv4(*ip.ip()), SocketAddr::V6(ip) => AddrV2::Ipv6(*ip.ip()),