From 25b9eede6e24ac721f7ae46c03456b67eac7af7e Mon Sep 17 00:00:00 2001 From: Nicolas Villanueva <1890113+MexicanAce@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:37:15 +0100 Subject: [PATCH] fix: Resolve hashes now uses the new openchain.xyz endpoint (#342) * fix: Resolve hashes now uses the new openchain.xyz endpoint * fix lint --- src/resolver.rs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/resolver.rs b/src/resolver.rs index db4372e7..87e6179c 100644 --- a/src/resolver.rs +++ b/src/resolver.rs @@ -14,7 +14,7 @@ use std::{ use tokio::sync::RwLock; use tracing::warn; -static SELECTOR_DATABASE_URL: &str = "https://sig.eth.samczsun.com/api/v1/signatures"; +static SELECTOR_DATABASE_URL: &str = "https://api.openchain.xyz/signature-database/v1/lookup"; /// The standard request timeout for API requests const REQ_TIMEOUT: Duration = Duration::from_secs(15); @@ -22,7 +22,7 @@ const REQ_TIMEOUT: Duration = Duration::from_secs(15); /// How many request can time out before we decide this is a spurious connection const MAX_TIMEDOUT_REQ: usize = 4usize; -/// A client that can request API data from `https://sig.eth.samczsun.com/api` +/// A client that can request API data from `https://api.openchain.xyz` #[derive(Debug, Clone)] pub struct SignEthClient { inner: reqwest::Client, @@ -104,7 +104,7 @@ impl SignEthClient { } if is_connectivity_err(err) { - warn!("spurious network detected for sig.eth.samczsun.com"); + warn!("spurious network detected for api.openchain.xyz"); let previous = self.timedout_requests.fetch_add(1, Ordering::SeqCst); if previous >= self.max_timedout_requests { self.set_spurious(); @@ -129,7 +129,7 @@ impl SignEthClient { Ok(()) } - /// Decodes the given function or event selector using sig.eth.samczsun.com + /// Decodes the given function or event selector using api.openchain.xyz pub async fn decode_selector( &self, selector: &str, @@ -146,8 +146,8 @@ impl SignEthClient { #[derive(Deserialize)] struct ApiResult { - event: HashMap>, - function: HashMap>, + event: HashMap>>, + function: HashMap>>, } #[derive(Deserialize)] @@ -156,11 +156,13 @@ impl SignEthClient { result: ApiResult, } - // using samczsun signature database over 4byte + // using openchain signature database over 4byte // see https://github.com/foundry-rs/foundry/issues/1672 let url = match selector_type { - SelectorType::Function => format!("{SELECTOR_DATABASE_URL}?function={selector}"), - SelectorType::Event => format!("{SELECTOR_DATABASE_URL}?event={selector}"), + SelectorType::Function => { + format!("{SELECTOR_DATABASE_URL}?function={selector}&filter=true") + } + SelectorType::Event => format!("{SELECTOR_DATABASE_URL}?event={selector}&filter=true"), }; let res = self.get_text(&url).await?; @@ -180,9 +182,17 @@ impl SignEthClient { SelectorType::Event => api_response.result.event, }; + // If the search returns null, we should default to using the selector + let default_decoded = vec![Decoded { + name: selector.to_string(), + filtered: false, + }]; + Ok(decoded .get(selector) .ok_or(eyre::eyre!("No signature found"))? + .as_ref() + .unwrap_or(&default_decoded) .iter() .filter(|d| !d.filtered) .map(|d| d.name.clone()) @@ -191,7 +201,7 @@ impl SignEthClient { .cloned()) } - /// Fetches a function signature given the selector using sig.eth.samczsun.com + /// Fetches a function signature given the selector using api.openchain.xyz pub async fn decode_function_selector(&self, selector: &str) -> eyre::Result> { let prefixed_selector = format!("0x{}", selector.strip_prefix("0x").unwrap_or(selector)); if prefixed_selector.len() != 10 { @@ -212,7 +222,7 @@ pub enum SelectorType { Function, Event, } -/// Fetches a function signature given the selector using sig.eth.samczsun.com +/// Fetches a function signature given the selector using api.openchain.xyz pub async fn decode_function_selector(selector: &str) -> eyre::Result> { { let cache = CACHE.read().await;