Skip to content

Commit

Permalink
[FIL-394 ]Verify if the client had allocations (#243)
Browse files Browse the repository at this point in the history
* Verify if the client had allocations
---------

Co-authored-by: Filip Lelek <[email protected]>
  • Loading branch information
Filip-L and filip-neti authored Nov 7, 2024
1 parent 0eda5a6 commit 853208b
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fplus-lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
28 changes: 28 additions & 0 deletions fplus-lib/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion fplus-lib/src/external_services/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
}
}

Expand Down
19 changes: 19 additions & 0 deletions fplus-lib/src/external_services/dmob.rs
Original file line number Diff line number Diff line change
@@ -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<VerifiedClientResponse, reqwest::Error> {
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::<VerifiedClientResponse>()
.await?;
Ok(response)
}
1 change: 1 addition & 0 deletions fplus-lib/src/external_services/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod blockchain;
pub mod dmob;
pub mod filecoin;
pub mod github;
24 changes: 24 additions & 0 deletions fplus-lib/src/models/dmob.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
}

fn number_to_string<'de, D>(de: D) -> Result<Option<String>, 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),
}
}
1 change: 1 addition & 0 deletions fplus-lib/src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod dmob;
pub mod filecoin;

0 comments on commit 853208b

Please sign in to comment.