Skip to content

Commit 1dc0991

Browse files
committed
Verify if the client had allocations
1 parent 0eda5a6 commit 1dc0991

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

fplus-lib/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn default_env_vars() -> &'static HashMap<&'static str, &'static str> {
3434
m.insert("KYC_URL", "https://kyc.allocator.tech");
3535
m.insert("RPC_URL", "https://mainnet.optimism.io");
3636
m.insert("DMOB_API_URL", "https://api.datacapstats.io/public/api");
37+
m.insert("DATACAPSTATS_API_URL", "https://api.datacapstats.io/api");
3738
m.insert("DMOB_API_KEY", "5c993a17-7b18-4ead-a8a8-89dad981d87e");
3839
m.insert("DAYS_TO_NEXT_AUTOALLOCATION", "14");
3940
m.insert(

fplus-lib/src/core/mod.rs

Lines changed: 28 additions & 0 deletions
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::filecoin::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/filecoin.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
config::get_env_var_or_default,
55
models::filecoin::{
66
StateReadStateResponse, StateVerifiedClientStatusResponse, StateVerifierStatusResponse,
7+
VerifiedClientResponse,
78
},
89
};
910

@@ -86,3 +87,20 @@ pub async fn get_allowance_for_client(address: &str) -> Result<String, reqwest::
8687
.await?;
8788
Ok(response.result)
8889
}
90+
91+
pub async fn get_client_allocation(
92+
address: &str,
93+
) -> Result<VerifiedClientResponse, reqwest::Error> {
94+
let api_url = get_env_var_or_default("DATACAPSTATS_API_URL");
95+
let url = format!("{}/getVerifiedClients?filter={}", api_url, address);
96+
97+
let client = reqwest::Client::new();
98+
99+
let response = client
100+
.get(&url)
101+
.send()
102+
.await?
103+
.json::<VerifiedClientResponse>()
104+
.await?;
105+
Ok(response)
106+
}

fplus-lib/src/models/filecoin.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use serde::{Deserialize, Serialize};
2+
use serde_json::Value;
23

34
pub type StateReadStateResponse = JSONRPCResponse<StateReadStateResult>;
45
pub type StateVerifierStatusResponse = JSONRPCResponse<StateVerifierStatusResult>;
@@ -47,3 +48,25 @@ pub struct MultisigState {
4748
#[serde(rename = "PendingTxns")]
4849
pub pending_txns: Code,
4950
}
51+
52+
#[derive(Serialize, Deserialize, Debug)]
53+
pub struct VerifiedClientResponse {
54+
#[serde(deserialize_with = "number_to_string")]
55+
pub count: Option<String>,
56+
}
57+
58+
fn number_to_string<'de, D>(de: D) -> Result<Option<String>, D::Error>
59+
where
60+
D: serde::Deserializer<'de>,
61+
{
62+
let helper: Value = Deserialize::deserialize(de)?;
63+
64+
match helper {
65+
Value::Number(n) => Ok(n
66+
.as_u64()
67+
.filter(|&number| number != 0)
68+
.map(|_| n.to_string())),
69+
Value::String(s) => Ok(Some(s)),
70+
_ => Ok(None),
71+
}
72+
}

0 commit comments

Comments
 (0)