diff --git a/fplus-lib/src/config.rs b/fplus-lib/src/config.rs index 2498ccac..b190cef3 100644 --- a/fplus-lib/src/config.rs +++ b/fplus-lib/src/config.rs @@ -33,7 +33,7 @@ pub fn default_env_vars() -> &'static HashMap<&'static str, &'static str> { m.insert("GITCOIN_MINIMUM_SCORE", "30"); m.insert("KYC_URL", "https://kyc.allocator.tech"); m.insert("RPC_URL", "https://mainnet.optimism.io"); - m.insert("DMOB_API_URL", "https://api.datacapstats.io/public/api"); + m.insert("DMOB_API_URL", "https://api.datacapstats.io"); m.insert("DMOB_API_KEY", "5c993a17-7b18-4ead-a8a8-89dad981d87e"); m.insert("DAYS_TO_NEXT_AUTOALLOCATION", "14"); m.insert( diff --git a/fplus-lib/src/core/mod.rs b/fplus-lib/src/core/mod.rs index a8c6b2f6..a228cbbb 100644 --- a/fplus-lib/src/core/mod.rs +++ b/fplus-lib/src/core/mod.rs @@ -15,6 +15,7 @@ use reqwest::Response; use serde::{Deserialize, Serialize}; use serde_json::from_str; +use crate::external_services::dmob::get_client_allocation; use crate::{ base64, config::get_env_var_or_default, @@ -752,6 +753,33 @@ impl LDNApplication { } } } + + match get_client_allocation(&application_id).await { + Ok(response) => { + if response.count.is_some() { + log::info!("Allocation found for client {}", application_id); + Self::issue_pathway_mismatch_comment( + issue_number, + info.owner, + info.repo, + None, + ) + .await?; + + return Err(LDNError::New( + "Pathway mismatch: Client has already allocation".to_string(), + )); + } else { + log::info!("Client allocation not found"); + } + } + Err(e) => { + return Err(LDNError::New(format!( + "Getting client allocation failed /// {}", + e + ))); + } + } } let file_content = match serde_json::to_string_pretty(&application_file) { diff --git a/fplus-lib/src/external_services/blockchain.rs b/fplus-lib/src/external_services/blockchain.rs index 6ca421ef..3e69c66a 100644 --- a/fplus-lib/src/external_services/blockchain.rs +++ b/fplus-lib/src/external_services/blockchain.rs @@ -42,7 +42,11 @@ impl BlockchainData { BlockchainData { client, - base_url: get_env_var_or_default("DMOB_API_URL"), + base_url: format!( + "{}{}", + get_env_var_or_default("DMOB_API_URL"), + "/public/api" + ), } } diff --git a/fplus-lib/src/external_services/dmob.rs b/fplus-lib/src/external_services/dmob.rs new file mode 100644 index 00000000..883f8e07 --- /dev/null +++ b/fplus-lib/src/external_services/dmob.rs @@ -0,0 +1,19 @@ +use crate::config::get_env_var_or_default; +use crate::models::dmob::VerifiedClientResponse; + +pub async fn get_client_allocation( + address: &str, +) -> Result { + let api_url = get_env_var_or_default("DMOB_API_URL"); + let url = format!("{}/api/getVerifiedClients?filter={}", api_url, address); + + let client = reqwest::Client::new(); + + let response = client + .get(&url) + .send() + .await? + .json::() + .await?; + Ok(response) +} diff --git a/fplus-lib/src/external_services/mod.rs b/fplus-lib/src/external_services/mod.rs index 81c6ad3f..2749809a 100644 --- a/fplus-lib/src/external_services/mod.rs +++ b/fplus-lib/src/external_services/mod.rs @@ -1,3 +1,4 @@ pub mod blockchain; +pub mod dmob; pub mod filecoin; pub mod github; diff --git a/fplus-lib/src/models/dmob.rs b/fplus-lib/src/models/dmob.rs new file mode 100644 index 00000000..03c5b52a --- /dev/null +++ b/fplus-lib/src/models/dmob.rs @@ -0,0 +1,24 @@ +use serde::{Deserialize, Serialize}; +use serde_json::Value; + +#[derive(Serialize, Deserialize, Debug)] +pub struct VerifiedClientResponse { + #[serde(deserialize_with = "number_to_string")] + pub count: Option, +} + +fn number_to_string<'de, D>(de: D) -> Result, D::Error> +where + D: serde::Deserializer<'de>, +{ + let helper: Value = Deserialize::deserialize(de)?; + + match helper { + Value::Number(n) => Ok(n + .as_u64() + .filter(|&number| number != 0) + .map(|_| n.to_string())), + Value::String(s) => Ok(Some(s)), + _ => Ok(None), + } +} diff --git a/fplus-lib/src/models/mod.rs b/fplus-lib/src/models/mod.rs index b7821eb5..f3e065eb 100644 --- a/fplus-lib/src/models/mod.rs +++ b/fplus-lib/src/models/mod.rs @@ -1 +1,2 @@ +pub mod dmob; pub mod filecoin;