-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from starknet-id/feat/carmine-price-protect-task
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod verify_price_protect; |
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,52 @@ | ||
use std::sync::Arc; | ||
|
||
use crate::{ | ||
models::{AppState, VerifyQuery}, | ||
utils::{get_error, CompletedTasksTrait}, | ||
}; | ||
use axum::{ | ||
extract::{Query, State}, | ||
http::StatusCode, | ||
response::IntoResponse, | ||
Json, | ||
}; | ||
use axum_auto_routes::route; | ||
use serde_json::json; | ||
use starknet::core::types::FieldElement; | ||
|
||
#[route(get, "/quests/carmine/verify_price_protect")] | ||
pub async fn handler( | ||
State(state): State<Arc<AppState>>, | ||
Query(query): Query<VerifyQuery>, | ||
) -> impl IntoResponse { | ||
let task_id = query.task_id.unwrap(); | ||
let addr = query.addr; | ||
|
||
let api_url = "https://api.carmine.finance/api/v1/mainnet/price-protect-users"; | ||
|
||
// Check if the addr is in the "data" field of the API response | ||
let response = reqwest::get(api_url) | ||
.await | ||
.unwrap() | ||
.json::<serde_json::Value>() | ||
.await | ||
.unwrap(); | ||
let data = response["data"].as_array().unwrap(); | ||
let mut found = false; | ||
for address in data { | ||
if FieldElement::from_hex_be(address.as_str().unwrap()).expect("Failed to parse address") | ||
== addr | ||
{ | ||
found = true; | ||
break; | ||
} | ||
} | ||
if found { | ||
match state.upsert_completed_task(addr, task_id).await { | ||
Ok(_) => (StatusCode::OK, Json(json!({"res": true}))).into_response(), | ||
Err(e) => get_error(format!("{}", e)), | ||
} | ||
} else { | ||
get_error("You didn't open price protect for at least 10$ on Carmine.".to_string()) | ||
} | ||
} |
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 carmine; | ||
pub mod claimable; | ||
pub mod contract_uri; | ||
pub mod discord_fw_callback; | ||
|
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