diff --git a/Cargo.lock b/Cargo.lock index 8adecb3..33a6264 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1130,6 +1130,17 @@ dependencies = [ "thiserror", ] +[[package]] +name = "future" +version = "0.1.0" +source = "git+https://github.com/WalletConnect/utils-rs.git?tag=v0.7.1#95b9936f0266b0f4fda40bfcce1b0b603e4dd520" +dependencies = [ + "pin-project", + "thiserror", + "tokio", + "tokio-util", +] + [[package]] name = "futures" version = "0.3.30" @@ -3183,6 +3194,7 @@ version = "0.1.0" source = "git+https://github.com/WalletConnect/utils-rs.git?tag=v0.7.1#95b9936f0266b0f4fda40bfcce1b0b603e4dd520" dependencies = [ "analytics", + "future", "geoip", ] diff --git a/Cargo.toml b/Cargo.toml index 56fa73f..70c3406 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ authors = [ build = "build.rs" [dependencies] -wc = { git = "https://github.com/WalletConnect/utils-rs.git", tag = "v0.7.1", features = ["geoip", "geoblock", "analytics"] } +wc = { git = "https://github.com/WalletConnect/utils-rs.git", tag = "v0.7.1", features = ["geoip", "geoblock", "analytics", "future"] } tokio = { version = "1", features = ["full"] } diff --git a/src/lib.rs b/src/lib.rs index c9623f7..10a7115 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,13 @@ +use { + anyhow::Context as _, + arrayvec::ArrayString, + derive_more::{AsRef, From}, + serde::{Deserialize, Serialize}, + std::time::Duration, + tap::{Tap, TapFallible, TapOptional}, + tracing::{error, instrument, warn}, + wc::future::FutureExt as _, +}; pub use { anyhow::Error, async_trait::async_trait, @@ -6,13 +16,6 @@ pub use { project_registry::ProjectRegistry, scam_guard::ScamGuard, }; -use { - arrayvec::ArrayString, - derive_more::{AsRef, From}, - serde::{Deserialize, Serialize}, - tap::{Tap, TapFallible, TapOptional}, - tracing::{error, instrument, warn}, -}; pub mod attestation_store; pub mod cache; @@ -100,7 +103,9 @@ impl<'a, I: Infra> Handle> for Service { let project_data = self .project_registry() .project_data(cmd.project_id) + .with_timeout(Duration::from_secs(10)) .await + .context("ProjectRegistry::project_data timed out")? .tap_err(|e| error!("ProjectRegistry::project_data: {e:?}"))? .ok_or(GetVerifyStatusError::UnknownProject) .tap_err(|_| warn!("Unknown project id"))?; @@ -179,8 +184,11 @@ impl<'a, I: Infra> Handle> for Service { let is_scam = self .scam_guard() .is_scam(&origin) + .with_timeout(Duration::from_secs(10)) .await - .map_err(|e| error!("ScamGuard::is_scam: {e:?}")) + .map_err(|_| error!("ScamGuard::is_scam timed out")) + .ok() + .and_then(|res| res.map_err(|e| error!("ScamGuard::is_scam: {e:?}")).ok()) .unwrap_or(IsScam::Unknown); Ok(Some(Attestation { origin, is_scam }))