diff --git a/engine/src/eth/rpc.rs b/engine/src/eth/rpc.rs index 0a7399ec900..10d1b16da8a 100644 --- a/engine/src/eth/rpc.rs +++ b/engine/src/eth/rpc.rs @@ -211,7 +211,7 @@ use crate::eth::ConscientiousEthWebsocketBlockHeaderStream; impl ReconnectSubscribeApi for ReconnectSubscriptionClient { async fn subscribe_blocks(&self) -> Result { let web3 = web3::Web3::new( - web3::transports::WebSocket::new((&self.ws_node_endpoint).into()).await?, + web3::transports::WebSocket::new(self.ws_node_endpoint.as_ref()).await?, ); let mut poll_interval = make_periodic_tick(SYNC_POLL_INTERVAL, false); diff --git a/utilities/src/with_std/redact_endpoint_secret.rs b/utilities/src/with_std/redact_endpoint_secret.rs index ddb56a5d133..fddd24eb621 100644 --- a/utilities/src/with_std/redact_endpoint_secret.rs +++ b/utilities/src/with_std/redact_endpoint_secret.rs @@ -17,17 +17,14 @@ impl Display for SecretUrl { } } -// Only debug print the secret in debug mode -#[cfg(debug_assertions)] impl Debug for SecretUrl { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self.0) - } -} -#[cfg(not(debug_assertions))] -impl Debug for SecretUrl { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", redact_secret_node_endpoint(&self.0)) + // Only debug print the secret without redaction in debug mode + if cfg!(debug_assertions) { + write!(f, "{:?}", self.0) + } else { + write!(f, "{:?}", redact_secret_node_endpoint(&self.0)) + } } } @@ -49,12 +46,6 @@ impl From for String { } } -impl<'a> From<&'a SecretUrl> for &'a str { - fn from(s: &'a SecretUrl) -> Self { - &s.0 - } -} - impl AsRef for SecretUrl { fn as_ref(&self) -> &str { &self.0 @@ -64,13 +55,15 @@ impl AsRef for SecretUrl { /// Partially redacts the secret in the url of the node endpoint. /// eg: `wss://cdcd639308194d3f977a1a5a7ff0d545.rinkeby.ws.rivet.cloud/` -> /// `wss://cdc****.rinkeby.ws.rivet.cloud/` -#[allow(unused)] pub fn redact_secret_node_endpoint(endpoint: &str) -> String { - let re = Regex::new(r"[0-9a-fA-F]{32}").unwrap(); + const REGEX_ETH_SECRET: &str = "[0-9a-fA-F]{32}"; + const REGEX_BTC_SECRET: &str = + r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"; + let re = Regex::new(&format!("({})|({})", REGEX_ETH_SECRET, REGEX_BTC_SECRET)).unwrap(); if re.is_match(endpoint) { // A 32 character hex string was found, redact it let mut endpoint_redacted = endpoint.to_string(); - for capture in re.captures_iter(endpoint) { + if let Some(capture) = re.captures_iter(endpoint).next() { endpoint_redacted = endpoint_redacted.replace( &capture[0], &format!( @@ -153,5 +146,15 @@ mod tests { assert_eq!(format!("{}", SecretUrl("no.schema.com".to_string())), "no.****"); assert_eq!(format!("{:?}", SecretUrl("debug_print".to_string())), "\"debug_print\""); + + assert_eq!( + format!( + "{}", + SecretUrl( + "btc.getblock.io/de76678e-a489-4503-2ba2-81156c471220/mainnet".to_string() + ) + ), + "btc.getblock.io/de7****/mainnet" + ); } }