Skip to content

Commit 853208b

Browse files
Filip-Lfilip-neti
andauthored
[FIL-394 ]Verify if the client had allocations (#243)
* Verify if the client had allocations --------- Co-authored-by: Filip Lelek <[email protected]>
1 parent 0eda5a6 commit 853208b

File tree

7 files changed

+79
-2
lines changed

7 files changed

+79
-2
lines changed

fplus-lib/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn default_env_vars() -> &'static HashMap<&'static str, &'static str> {
3333
m.insert("GITCOIN_MINIMUM_SCORE", "30");
3434
m.insert("KYC_URL", "https://kyc.allocator.tech");
3535
m.insert("RPC_URL", "https://mainnet.optimism.io");
36-
m.insert("DMOB_API_URL", "https://api.datacapstats.io/public/api");
36+
m.insert("DMOB_API_URL", "https://api.datacapstats.io");
3737
m.insert("DMOB_API_KEY", "5c993a17-7b18-4ead-a8a8-89dad981d87e");
3838
m.insert("DAYS_TO_NEXT_AUTOALLOCATION", "14");
3939
m.insert(

fplus-lib/src/core/mod.rs

+28
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use reqwest::Response;
1515
use serde::{Deserialize, Serialize};
1616
use serde_json::from_str;
1717

18+
use crate::external_services::dmob::get_client_allocation;
1819
use crate::{
1920
base64,
2021
config::get_env_var_or_default,
@@ -752,6 +753,33 @@ impl LDNApplication {
752753
}
753754
}
754755
}
756+
757+
match get_client_allocation(&application_id).await {
758+
Ok(response) => {
759+
if response.count.is_some() {
760+
log::info!("Allocation found for client {}", application_id);
761+
Self::issue_pathway_mismatch_comment(
762+
issue_number,
763+
info.owner,
764+
info.repo,
765+
None,
766+
)
767+
.await?;
768+
769+
return Err(LDNError::New(
770+
"Pathway mismatch: Client has already allocation".to_string(),
771+
));
772+
} else {
773+
log::info!("Client allocation not found");
774+
}
775+
}
776+
Err(e) => {
777+
return Err(LDNError::New(format!(
778+
"Getting client allocation failed /// {}",
779+
e
780+
)));
781+
}
782+
}
755783
}
756784

757785
let file_content = match serde_json::to_string_pretty(&application_file) {

fplus-lib/src/external_services/blockchain.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ impl BlockchainData {
4242

4343
BlockchainData {
4444
client,
45-
base_url: get_env_var_or_default("DMOB_API_URL"),
45+
base_url: format!(
46+
"{}{}",
47+
get_env_var_or_default("DMOB_API_URL"),
48+
"/public/api"
49+
),
4650
}
4751
}
4852

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::config::get_env_var_or_default;
2+
use crate::models::dmob::VerifiedClientResponse;
3+
4+
pub async fn get_client_allocation(
5+
address: &str,
6+
) -> Result<VerifiedClientResponse, reqwest::Error> {
7+
let api_url = get_env_var_or_default("DMOB_API_URL");
8+
let url = format!("{}/api/getVerifiedClients?filter={}", api_url, address);
9+
10+
let client = reqwest::Client::new();
11+
12+
let response = client
13+
.get(&url)
14+
.send()
15+
.await?
16+
.json::<VerifiedClientResponse>()
17+
.await?;
18+
Ok(response)
19+
}
+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod blockchain;
2+
pub mod dmob;
23
pub mod filecoin;
34
pub mod github;

fplus-lib/src/models/dmob.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use serde::{Deserialize, Serialize};
2+
use serde_json::Value;
3+
4+
#[derive(Serialize, Deserialize, Debug)]
5+
pub struct VerifiedClientResponse {
6+
#[serde(deserialize_with = "number_to_string")]
7+
pub count: Option<String>,
8+
}
9+
10+
fn number_to_string<'de, D>(de: D) -> Result<Option<String>, D::Error>
11+
where
12+
D: serde::Deserializer<'de>,
13+
{
14+
let helper: Value = Deserialize::deserialize(de)?;
15+
16+
match helper {
17+
Value::Number(n) => Ok(n
18+
.as_u64()
19+
.filter(|&number| number != 0)
20+
.map(|_| n.to_string())),
21+
Value::String(s) => Ok(Some(s)),
22+
_ => Ok(None),
23+
}
24+
}

fplus-lib/src/models/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
pub mod dmob;
12
pub mod filecoin;

0 commit comments

Comments
 (0)