-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIL-394 ]Verify if the client had allocations (#243)
* Verify if the client had allocations --------- Co-authored-by: Filip Lelek <[email protected]>
- Loading branch information
1 parent
0eda5a6
commit 853208b
Showing
7 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod dmob; | ||
pub mod filecoin; |