From f18d54929359e459320d7f241b41b34ae01a1a37 Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Thu, 18 Jan 2024 17:56:04 +0000 Subject: [PATCH] refactor: use #route macro to clean main.rs --- Cargo.toml | 2 + .../batched/verify_tvl_batched.rs | 6 + .../achievements/claim/quests_achievement.rs | 53 +- src/endpoints/achievements/fetch.rs | 6 + src/endpoints/achievements/fetch_buildings.rs | 6 + .../achievements/verify_achieved_quests.rs | 6 + src/endpoints/achievements/verify_avnu.rs | 6 + src/endpoints/achievements/verify_briq.rs | 10 +- src/endpoints/achievements/verify_default.rs | 6 + .../achievements/verify_has_domain.rs | 21 +- src/endpoints/achievements/verify_quests.rs | 6 + .../achievements/verify_seniority.rs | 6 + src/endpoints/achievements/verify_tvl.rs | 6 + src/endpoints/get_boosted_quests.rs | 12 +- src/endpoints/get_completed_quests.rs | 2 + src/endpoints/get_deployed_time.rs | 2 + src/endpoints/get_quest.rs | 2 + src/endpoints/get_quest_category.rs | 2 + src/endpoints/get_quest_participants.rs | 6 + src/endpoints/get_quests.rs | 2 + src/endpoints/get_quiz.rs | 2 + src/endpoints/get_tasks.rs | 2 + src/endpoints/get_trending_quests.rs | 2 + src/endpoints/has_completed_quest.rs | 2 + src/endpoints/leaderboard/get_ranking.rs | 6 + src/endpoints/leaderboard/get_static_info.rs | 18 +- src/endpoints/quest_boost/get_boost.rs | 2 + src/endpoints/quest_boost/get_boosts.rs | 2 + src/endpoints/quest_boost/get_claim_params.rs | 22 +- .../quest_boost/get_completed_boosts.rs | 6 + .../quest_boost/get_pending_claims.rs | 6 + src/endpoints/quest_boost/get_quests.rs | 2 + src/endpoints/quests/avnu/claimable.rs | 12 +- .../quests/avnu/discord_fw_callback.rs | 6 + src/endpoints/quests/avnu/verify_swap.rs | 6 + .../quests/braavos/avnu/claimable.rs | 12 +- .../quests/braavos/avnu/verify_has_domain.rs | 6 + .../quests/braavos/avnu/verify_swap.rs | 6 + .../braavos/avnu/verify_twitter_fw_avnu.rs | 6 + .../braavos/avnu/verify_twitter_fw_braavos.rs | 6 + .../quests/braavos/avnu/verify_twitter_rt.rs | 6 + .../quests/braavos/myswap/claimable.rs | 12 +- .../braavos/myswap/verify_added_liquidity.rs | 6 + .../braavos/myswap/verify_has_domain.rs | 6 + .../myswap/verify_twitter_fw_braavos.rs | 6 + .../myswap/verify_twitter_fw_myswap.rs | 6 + .../quests/braavos/pyramid/claimable.rs | 10 +- .../braavos/pyramid/verify_buy_or_list.rs | 28 +- .../braavos/pyramid/verify_has_domain.rs | 6 + .../pyramid/verify_twitter_fw_braavos.rs | 6 + .../pyramid/verify_twitter_fw_pyramid.rs | 6 + .../braavos/pyramid/verify_twitter_rt.rs | 6 + .../quests/braavos/starknetid/claimable.rs | 12 +- .../braavos/starknetid/verify_has_domain.rs | 6 + .../braavos/starknetid/verify_has_mission.rs | 6 + .../starknetid/verify_twitter_fw_braavos.rs | 6 + .../starknetid/verify_twitter_fw_sid.rs | 6 + .../starknetid/verify_twitter_fw_sq.rs | 6 + .../quests/braavos/wallet/claimable.rs | 12 +- .../braavos/wallet/verify_has_domain.rs | 6 + .../wallet/verify_twitter_fw_braavos.rs | 6 + .../braavos/wallet/verify_twitter_rt.rs | 6 + .../quests/braavos/zklend/claimable.rs | 10 +- .../braavos/zklend/verify_added_liquidity.rs | 6 + .../braavos/zklend/verify_has_domain.rs | 6 + .../zklend/verify_twitter_fw_braavos.rs | 6 + .../zklend/verify_twitter_fw_zklend.rs | 6 + .../braavos/zklend/verify_twitter_rt.rs | 6 + src/endpoints/quests/carmine/claimable.rs | 12 +- src/endpoints/quests/contract_uri.rs | 2 + src/endpoints/quests/ekubo/claimable.rs | 12 +- .../quests/ekubo/discord_fw_callback.rs | 6 + .../quests/ekubo/verify_added_liquidity.rs | 6 + src/endpoints/quests/ekubo/verify_quiz.rs | 6 + .../quests/element/briq/claimable.rs | 12 +- .../quests/element/briq/verify_own_briq.rs | 8 +- .../quests/element/briq/verify_twitter_fw.rs | 6 + .../quests/element/element/claimable.rs | 12 +- .../element/element/verify_is_eligible.rs | 6 + .../element/element/verify_twitter_fw.rs | 6 + .../quests/element/layerswap/claimable.rs | 12 +- .../element/layerswap/verify_has_bridged.rs | 6 + .../element/layerswap/verify_twitter_fw.rs | 6 + .../element/layerswap/verify_twitter_rt.rs | 6 + .../quests/element/starknetid/claimable.rs | 12 +- .../starknetid/verify_has_root_domain.rs | 6 + .../engagement/discord_fw_callback.rs | 6 + .../focustree/engagement/verify_twitter_rt.rs | 6 + .../focustree/introduction/claimable.rs | 12 +- .../introduction/verify_twitter_fw.rs | 6 + .../introduction/verify_twitter_rt.rs | 6 + src/endpoints/quests/jediswap/claimable.rs | 12 +- .../quests/jediswap/verify_added_liquidity.rs | 6 + .../quests/jediswap/verify_twitter_fw.rs | 6 + .../quests/jediswap/verify_twitter_rt.rs | 6 + src/endpoints/quests/morphine/claimable.rs | 12 +- .../quests/morphine/verify_added_liquidity.rs | 6 + src/endpoints/quests/myswap/claimable.rs | 12 +- .../quests/myswap/discord_fw_callback.rs | 6 + .../quests/myswap/verify_added_liquidity.rs | 6 + src/endpoints/quests/nostra/claimable.rs | 6 + .../quests/nostra/discord_fw_callback.rs | 6 + .../quests/nostra/verify_added_liquidity.rs | 6 + src/endpoints/quests/orbiter/claimable.rs | 12 +- .../quests/orbiter/verify_has_bridged.rs | 6 + .../quests/orbiter/verify_has_root_domain.rs | 6 + .../quests/orbiter/verify_twitter_fw.rs | 6 + .../quests/orbiter/verify_twitter_fw_sq.rs | 6 + .../quests/orbiter/verify_twitter_rt.rs | 6 + src/endpoints/quests/rango/check_trade.rs | 14 +- src/endpoints/quests/rango/claimable.rs | 6 + .../quests/rango/discord_fw_callback.rs | 6 + .../quests/rango/verify_twitter_fw.rs | 6 + src/endpoints/quests/rhino/check_bridge.rs | 6 + src/endpoints/quests/rhino/claimable.rs | 6 + .../quests/rhino/verify_twitter_fw.rs | 6 + .../quests/rhino/verify_twitter_rw.rs | 6 + src/endpoints/quests/sithswap/claimable.rs | 12 +- .../quests/sithswap/verify_added_liquidity.rs | 6 + .../quests/sithswap/verify_twitter_fw.rs | 6 + .../quests/starknet/aa_mastery/claimable.rs | 12 +- .../quests/starknet/gigabrain/claimable.rs | 12 +- src/endpoints/quests/starknetid/claimable.rs | 12 +- .../quests/starknetid/verify_has_domain.rs | 6 + .../starknetid/verify_has_root_domain.rs | 6 + .../quests/starknetid/verify_socials.rs | 27 +- .../quests/starknetid/verify_twitter_fw.rs | 6 + src/endpoints/quests/tribe/claimable.rs | 7 + .../quests/tribe/verify_has_domain.rs | 6 + .../quests/tribe/verify_has_root_domain.rs | 6 + .../quests/tribe/verify_three_years_expiry.rs | 6 + src/endpoints/quests/uri.rs | 2 + src/endpoints/quests/verify_quiz.rs | 2 + src/endpoints/quests/zklend/claimable.rs | 12 +- src/endpoints/quests/zklend/verify_borrow.rs | 6 + .../quests/zklend/verify_twitter_fw.rs | 6 + src/main.rs | 549 +----------------- src/utils.rs | 34 +- 138 files changed, 957 insertions(+), 666 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 52433c75..7e8a9833 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "c974e5cb42e8d8344cee910b76005ec46b4dd3ed" } starknet-id = { git = "https://github.com/starknet-id/starknet-id.rs.git", rev = "2b30c2453b96789a628c86d2edebb1023fa2e77d" } +axum_auto_routes = { git = "https://github.com/Th0rgal/axum_auto_routes.git", rev = "f9e1d2083e887cd264642359c4aa851938da6f09" } axum = "0.6.17" toml = "0.5.10" serde = { version = "1.0.152", features = ["derive"] } @@ -23,3 +24,4 @@ percent-encoding = "2.3.1" chrono = "0.4.19" lazy_static = "1.4.0" regex = "1.10.0" +ctor = "0.2.6" diff --git a/src/endpoints/achievements/batched/verify_tvl_batched.rs b/src/endpoints/achievements/batched/verify_tvl_batched.rs index c02e0494..eff70ac5 100644 --- a/src/endpoints/achievements/batched/verify_tvl_batched.rs +++ b/src/endpoints/achievements/batched/verify_tvl_batched.rs @@ -11,9 +11,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/achievements/batched/verify_tvl_batched", + crate::endpoints::achievements::batched::verify_tvl_batched +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/achievements/claim/quests_achievement.rs b/src/endpoints/achievements/claim/quests_achievement.rs index 657b9ab8..ebb0ec65 100644 --- a/src/endpoints/achievements/claim/quests_achievement.rs +++ b/src/endpoints/achievements/claim/quests_achievement.rs @@ -1,8 +1,9 @@ use std::sync::Arc; +use crate::utils::{to_hex, AchievementsTrait}; use crate::{ models::{AppState, VerifyAchievementQuery}, - utils::{get_error}, + utils::get_error, }; use axum::{ extract::{Query, State}, @@ -10,11 +11,11 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::TryStreamExt; use mongodb::bson::{doc, Document}; use serde_json::json; use starknet::core::types::FieldElement; -use crate::utils::{AchievementsTrait, to_hex}; fn get_number_of_quests(id: u32) -> u32 { return match id { 23 => 1, @@ -26,6 +27,11 @@ fn get_number_of_quests(id: u32) -> u32 { }; } +#[route( + get, + "/achievements/claim/quest_achievement", + crate::endpoints::achievements::claim::quests_achievement +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -89,29 +95,29 @@ pub async fn handler( } }, doc! { - "$group": doc! { - "_id": null, - "count": doc! { - "$sum": 1 + "$group": doc! { + "_id": null, + "count": doc! { + "$sum": 1 + } } - } - }, + }, doc! { - "$addFields": doc! { - "result": doc! { - "$cond": doc! { - "if": doc! { - "$gte": [ - "$count", - quests_threshold - ] - }, - "then": true, - "else": false + "$addFields": doc! { + "result": doc! { + "$cond": doc! { + "if": doc! { + "$gte": [ + "$count", + quests_threshold + ] + }, + "then": true, + "else": false + } } } - } - }, + }, ]; let tasks_collection = state.db.collection::("completed_tasks"); @@ -125,7 +131,10 @@ pub async fn handler( return get_error("User hasn't completed required number of quests".into()); } let addr_hex = to_hex(addr); - match state.upsert_claimed_achievement(addr_hex, achievement_id).await { + match state + .upsert_claimed_achievement(addr_hex, achievement_id) + .await + { Ok(_) => (StatusCode::OK, Json(json!({"res": true}))).into_response(), Err(e) => get_error(format!("{}", e)), } diff --git a/src/endpoints/achievements/fetch.rs b/src/endpoints/achievements/fetch.rs index b7a97b28..48afba5c 100644 --- a/src/endpoints/achievements/fetch.rs +++ b/src/endpoints/achievements/fetch.rs @@ -10,10 +10,16 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::stream::StreamExt; use mongodb::bson::{doc, from_document}; use starknet::core::types::FieldElement; +#[route( + get, + "/achievements/fetch", + crate::endpoints::achievements::fetch +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/achievements/fetch_buildings.rs b/src/endpoints/achievements/fetch_buildings.rs index 7c509161..5e4ed8e1 100644 --- a/src/endpoints/achievements/fetch_buildings.rs +++ b/src/endpoints/achievements/fetch_buildings.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::stream::StreamExt; use mongodb::bson::{doc, from_document}; +#[route( + get, + "/achievements/fetch_buildings", + crate::endpoints::achievements::fetch_buildings +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/achievements/verify_achieved_quests.rs b/src/endpoints/achievements/verify_achieved_quests.rs index 5a5d6851..56746770 100644 --- a/src/endpoints/achievements/verify_achieved_quests.rs +++ b/src/endpoints/achievements/verify_achieved_quests.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/achievements/verify_achieved_quests", + crate::endpoints::achievements::verify_achieved_quests +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/achievements/verify_avnu.rs b/src/endpoints/achievements/verify_avnu.rs index 345dc55e..789fb2f0 100644 --- a/src/endpoints/achievements/verify_avnu.rs +++ b/src/endpoints/achievements/verify_avnu.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/achievements/verify_avnu", + crate::endpoints::achievements::verify_avnu +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/achievements/verify_briq.rs b/src/endpoints/achievements/verify_briq.rs index 7cbbe57a..06a30f49 100644 --- a/src/endpoints/achievements/verify_briq.rs +++ b/src/endpoints/achievements/verify_briq.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use crate::utils::fetch_json_from_url; use crate::{ models::{AchievedDocument, AppState, VerifyAchievementQuery}, utils::{get_error, to_hex, AchievementsTrait}, @@ -10,11 +11,16 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use mongodb::bson::doc; use serde_json::json; use starknet::core::types::FieldElement; -use crate::utils::fetch_json_from_url; +#[route( + get, + "/achievements/verify_briq", + crate::endpoints::achievements::verify_briq +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -47,7 +53,7 @@ pub async fn handler( Ok(response) => { if let Some(sets) = response.get("sets") { match sets { - serde_json::Value::Array(sets_array ) => { + serde_json::Value::Array(sets_array) => { for set in sets_array.iter() { if let serde_json::Value::String(set_str) = set { let url = format!( diff --git a/src/endpoints/achievements/verify_default.rs b/src/endpoints/achievements/verify_default.rs index 3dcfe3e2..eff39efc 100644 --- a/src/endpoints/achievements/verify_default.rs +++ b/src/endpoints/achievements/verify_default.rs @@ -15,6 +15,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use mongodb::bson::doc; use serde_json::json; use starknet::core::types::FieldElement; @@ -41,6 +42,11 @@ fn get_args(config: Config, achievement_id: u32) -> Result<(FieldElement, u32, N } } +#[route( + get, + "/achievements/verify_default", + crate::endpoints::achievements::verify_default +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/achievements/verify_has_domain.rs b/src/endpoints/achievements/verify_has_domain.rs index f7e3cccf..3afc6928 100644 --- a/src/endpoints/achievements/verify_has_domain.rs +++ b/src/endpoints/achievements/verify_has_domain.rs @@ -8,6 +8,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::{ core::types::{BlockId, BlockTag, FieldElement, FunctionCall}, @@ -19,6 +20,11 @@ use std::{ time::{SystemTime, UNIX_EPOCH}, }; +#[route( + get, + "/achievements/verify_has_domain", + crate::endpoints::achievements::verify_has_domain +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -51,16 +57,17 @@ pub async fn handler( FunctionCall { contract_address: state.conf.starknetid_contracts.naming_contract, entry_point_selector: selector!("domain_to_expiry"), - calldata: vec![ FieldElement::ONE, result[1] ], + calldata: vec![FieldElement::ONE, result[1]], }, BlockId::Tag(BlockTag::Latest), ) - .await else { - return get_error("error querying expiry".to_string()) - }; - let Ok(expiry) : Result = expiry_result[0].try_into() else { - return get_error("error reading expiry".to_string()) - }; + .await + else { + return get_error("error querying expiry".to_string()); + }; + let Ok(expiry): Result = expiry_result[0].try_into() else { + return get_error("error reading expiry".to_string()); + }; let now = match SystemTime::now().duration_since(UNIX_EPOCH) { Ok(n) => n.as_secs(), Err(_) => return get_error("system time before UNIX EPOCH".to_string()), diff --git a/src/endpoints/achievements/verify_quests.rs b/src/endpoints/achievements/verify_quests.rs index 81ec90f1..248f1d48 100644 --- a/src/endpoints/achievements/verify_quests.rs +++ b/src/endpoints/achievements/verify_quests.rs @@ -11,6 +11,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::TryStreamExt; use mongodb::bson::{doc, Document}; use serde_json::json; @@ -27,6 +28,11 @@ fn get_number_of_quests(id: u32) -> u32 { }; } +#[route( + get, + "/achievements/verify_quests", + crate::endpoints::achievements::verify_quests +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/achievements/verify_seniority.rs b/src/endpoints/achievements/verify_seniority.rs index 89194275..caf0565a 100644 --- a/src/endpoints/achievements/verify_seniority.rs +++ b/src/endpoints/achievements/verify_seniority.rs @@ -11,10 +11,16 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use chrono::{NaiveDateTime, Utc}; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/achievements/verify_seniority", + crate::endpoints::achievements::verify_seniority +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/achievements/verify_tvl.rs b/src/endpoints/achievements/verify_tvl.rs index 6183579b..cdd47ed4 100644 --- a/src/endpoints/achievements/verify_tvl.rs +++ b/src/endpoints/achievements/verify_tvl.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/achievements/verify_tvl", + crate::endpoints::achievements::verify_tvl +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/get_boosted_quests.rs b/src/endpoints/get_boosted_quests.rs index 5f181089..6f64458a 100644 --- a/src/endpoints/get_boosted_quests.rs +++ b/src/endpoints/get_boosted_quests.rs @@ -1,18 +1,14 @@ use crate::{models::AppState, utils::get_error}; -use axum::{ - extract::{State}, - response::IntoResponse, - Json, -}; +use axum::{extract::State, response::IntoResponse, Json}; +use axum_auto_routes::route; use futures::TryStreamExt; use mongodb::bson::{doc, Document}; use reqwest::StatusCode; use std::sync::Arc; -pub async fn handler( - State(state): State>, -) -> impl IntoResponse { +#[route(get, "/get_boosted_quests", crate::endpoints::get_boosted_quests)] +pub async fn handler(State(state): State>) -> impl IntoResponse { let pipeline = vec![ doc! { "$unwind": doc! { diff --git a/src/endpoints/get_completed_quests.rs b/src/endpoints/get_completed_quests.rs index 28214e53..94482817 100644 --- a/src/endpoints/get_completed_quests.rs +++ b/src/endpoints/get_completed_quests.rs @@ -5,6 +5,7 @@ use axum::{ Json, }; +use axum_auto_routes::route; use futures::TryStreamExt; use mongodb::bson::{doc, Document}; use reqwest::StatusCode; @@ -18,6 +19,7 @@ pub struct GetCompletedQuestsQuery { addr: FieldElement, } +#[route(get, "/get_completed_quests", crate::endpoints::get_completed_quests)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/get_deployed_time.rs b/src/endpoints/get_deployed_time.rs index 7dd9624b..3f7f007f 100644 --- a/src/endpoints/get_deployed_time.rs +++ b/src/endpoints/get_deployed_time.rs @@ -8,6 +8,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde::{Deserialize, Serialize}; use serde_json::json; use starknet::core::types::FieldElement; @@ -18,6 +19,7 @@ pub struct GetDeployedTimeQuery { addr: FieldElement, } +#[route(get, "/get_deployed_time", crate::endpoints::get_deployed_time)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/get_quest.rs b/src/endpoints/get_quest.rs index 57b3c0d0..a3ab39e4 100644 --- a/src/endpoints/get_quest.rs +++ b/src/endpoints/get_quest.rs @@ -7,6 +7,7 @@ use axum::{ http::StatusCode, response::{IntoResponse, Json}, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use mongodb::bson::from_document; @@ -18,6 +19,7 @@ pub struct GetQuestsQuery { id: u32, } +#[route(get, "/get_quest", crate::endpoints::get_quest)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/get_quest_category.rs b/src/endpoints/get_quest_category.rs index c140a85a..eb9730f4 100644 --- a/src/endpoints/get_quest_category.rs +++ b/src/endpoints/get_quest_category.rs @@ -7,6 +7,7 @@ use axum::{ http::StatusCode, response::{IntoResponse, Json}, }; +use axum_auto_routes::route; use mongodb::bson::doc; use serde::Deserialize; use std::sync::Arc; @@ -16,6 +17,7 @@ pub struct GetQuestsQuery { name: String, } +#[route(get, "/get_quest_category", crate::endpoints::get_quest_category)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/get_quest_participants.rs b/src/endpoints/get_quest_participants.rs index a0bb5d90..a54ae7e1 100644 --- a/src/endpoints/get_quest_participants.rs +++ b/src/endpoints/get_quest_participants.rs @@ -5,6 +5,7 @@ use axum::{ Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::{doc, Document}; use reqwest::StatusCode; @@ -17,6 +18,11 @@ pub struct GetQuestParticipantsQuery { quest_id: u32, } +#[route( + get, + "/get_quest_participants", + crate::endpoints::get_quest_participants +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/get_quests.rs b/src/endpoints/get_quests.rs index 914812fc..e629b027 100644 --- a/src/endpoints/get_quests.rs +++ b/src/endpoints/get_quests.rs @@ -7,6 +7,7 @@ use axum::{ http::StatusCode, response::{IntoResponse, Json}, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use mongodb::bson::from_document; @@ -20,6 +21,7 @@ pub struct NFTItem { level: u32, } +#[route(get, "/get_quests", crate::endpoints::get_quests)] pub async fn handler(State(state): State>) -> impl IntoResponse { let pipeline = vec![ doc! { diff --git a/src/endpoints/get_quiz.rs b/src/endpoints/get_quiz.rs index 5212bd90..93ba7f44 100644 --- a/src/endpoints/get_quiz.rs +++ b/src/endpoints/get_quiz.rs @@ -4,6 +4,7 @@ use axum::{ http::StatusCode, response::{IntoResponse, Json}, }; +use axum_auto_routes::route; use mongodb::bson::doc; use serde::{Deserialize, Serialize}; use starknet::core::types::FieldElement; @@ -33,6 +34,7 @@ pub struct QuizResponse { questions: Vec, } +#[route(get, "/get_quiz", crate::endpoints::get_quiz)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/get_tasks.rs b/src/endpoints/get_tasks.rs index 47808949..75db0fa7 100644 --- a/src/endpoints/get_tasks.rs +++ b/src/endpoints/get_tasks.rs @@ -4,6 +4,7 @@ use axum::{ http::StatusCode, response::{IntoResponse, Json}, }; +use axum_auto_routes::route; use futures::stream::StreamExt; use mongodb::bson::{doc, from_document, Document}; use serde::{Deserialize, Serialize}; @@ -31,6 +32,7 @@ pub struct GetTasksQuery { addr: FieldElement, } +#[route(get, "/get_tasks", crate::endpoints::get_tasks)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/get_trending_quests.rs b/src/endpoints/get_trending_quests.rs index 6c4b600b..b7f5e855 100644 --- a/src/endpoints/get_trending_quests.rs +++ b/src/endpoints/get_trending_quests.rs @@ -7,6 +7,7 @@ use axum::{ http::StatusCode, response::{IntoResponse, Json}, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use mongodb::bson::from_document; @@ -19,6 +20,7 @@ pub struct NFTItem { level: u32, } +#[route(get, "/get_trending_quests", crate::endpoints::get_trending_quests)] pub async fn handler(State(state): State>) -> impl IntoResponse { let pipeline = vec![ doc! { diff --git a/src/endpoints/has_completed_quest.rs b/src/endpoints/has_completed_quest.rs index 2c06113d..98c70a60 100644 --- a/src/endpoints/has_completed_quest.rs +++ b/src/endpoints/has_completed_quest.rs @@ -5,6 +5,7 @@ use axum::{ Json, }; +use axum_auto_routes::route; use futures::TryStreamExt; use mongodb::bson::{doc, Document}; use reqwest::StatusCode; @@ -18,6 +19,7 @@ pub struct HasCompletedQuestsQuery { quest_id: u32, } +#[route(get, "/has_completed_quest", crate::endpoints::has_completed_quest)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/leaderboard/get_ranking.rs b/src/endpoints/leaderboard/get_ranking.rs index 55b618b4..f4af5bf8 100644 --- a/src/endpoints/leaderboard/get_ranking.rs +++ b/src/endpoints/leaderboard/get_ranking.rs @@ -38,6 +38,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use crate::utils::get_timestamp_from_days; use axum::http::{header, Response}; @@ -234,6 +235,11 @@ pub struct GetCompletedQuestsQuery { duration: String, } +#[route( + get, + "/leaderboard/get_ranking", + crate::endpoints::leaderboard::get_ranking +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/leaderboard/get_static_info.rs b/src/endpoints/leaderboard/get_static_info.rs index 6e6e8d51..dbaaf49a 100644 --- a/src/endpoints/leaderboard/get_static_info.rs +++ b/src/endpoints/leaderboard/get_static_info.rs @@ -12,6 +12,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use crate::utils::get_timestamp_from_days; use axum::http::header; @@ -33,6 +34,11 @@ pub struct GetLeaderboardInfoQuery { duration: String, } +#[route( + get, + "/leaderboard/get_static_info", + crate::endpoints::leaderboard::get_static_info +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -42,15 +48,9 @@ pub async fn handler( // check value of duration and set time_gap accordingly using match and respective timestamp let time_gap = match query.duration.as_str() { - "week" => { - get_timestamp_from_days(7) - } - "month" => { - get_timestamp_from_days(30) - } - "all" => { - 0 - } + "week" => get_timestamp_from_days(7), + "month" => get_timestamp_from_days(30), + "all" => 0, _ => { return get_error("Invalid duration".to_string()); } diff --git a/src/endpoints/quest_boost/get_boost.rs b/src/endpoints/quest_boost/get_boost.rs index 04039622..b6aa29c4 100644 --- a/src/endpoints/quest_boost/get_boost.rs +++ b/src/endpoints/quest_boost/get_boost.rs @@ -7,6 +7,7 @@ use axum::{ http::StatusCode, response::{IntoResponse, Json}, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -17,6 +18,7 @@ pub struct GetQuestsQuery { id: u32, } +#[route(get, "/boost/get_boost", crate::endpoints::quest_boost::get_boost)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quest_boost/get_boosts.rs b/src/endpoints/quest_boost/get_boosts.rs index d6d0db25..074a9ea1 100644 --- a/src/endpoints/quest_boost/get_boosts.rs +++ b/src/endpoints/quest_boost/get_boosts.rs @@ -5,10 +5,12 @@ use axum::{ http::StatusCode, response::{IntoResponse, Json}, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use std::sync::Arc; +#[route(get, "/boost/get_boosts", crate::endpoints::quest_boost::get_boosts)] pub async fn handler(State(state): State>) -> impl IntoResponse { let collection = state.db.collection::("boosts"); let mut boosts = match collection.find(doc! {"hidden":false}, None).await { diff --git a/src/endpoints/quest_boost/get_claim_params.rs b/src/endpoints/quest_boost/get_claim_params.rs index f90885d0..c1ae6f90 100644 --- a/src/endpoints/quest_boost/get_claim_params.rs +++ b/src/endpoints/quest_boost/get_claim_params.rs @@ -4,16 +4,17 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use std::str::FromStr; -use mongodb::bson::{Bson, doc, Document}; +use crate::utils::to_hex; +use mongodb::bson::{doc, Bson, Document}; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; use serde_json::json; use starknet::core::crypto::ecdsa_sign; use starknet::core::{crypto::pedersen_hash, types::FieldElement}; use std::sync::Arc; -use crate::utils::to_hex; #[derive(Debug, Serialize, Deserialize)] pub struct GetClaimBoostQuery { @@ -21,6 +22,11 @@ pub struct GetClaimBoostQuery { addr: FieldElement, } +#[route( + get, + "/boost/get_claim_params", + crate::endpoints::quest_boost::get_claim_params +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -28,7 +34,10 @@ pub async fn handler( let address = to_hex(query.addr); let boost_id = query.boost_id; let collection = state.db.collection::("boosts"); - let res = collection.find_one(doc! {"id":boost_id}, None).await.unwrap(); + let res = collection + .find_one(doc! {"id":boost_id}, None) + .await + .unwrap(); // if no boost found with the requested id if res.is_none() { @@ -45,7 +54,10 @@ pub async fn handler( // if the user is not in the winner list if !winner_list.contains(&bson_value) { - return get_error(format!("User {} is not in the winner list", address.clone())); + return get_error(format!( + "User {} is not in the winner list", + address.clone() + )); } let hashed = pedersen_hash( @@ -70,4 +82,4 @@ pub async fn handler( .into_response(), Err(e) => get_error(format!("Error while generating signature: {}", e)), } -} \ No newline at end of file +} diff --git a/src/endpoints/quest_boost/get_completed_boosts.rs b/src/endpoints/quest_boost/get_completed_boosts.rs index 47021b4b..2ef579ef 100644 --- a/src/endpoints/quest_boost/get_completed_boosts.rs +++ b/src/endpoints/quest_boost/get_completed_boosts.rs @@ -5,6 +5,7 @@ use axum::{ Json, }; +use axum_auto_routes::route; use futures::TryStreamExt; use mongodb::bson::{doc, Document}; use reqwest::StatusCode; @@ -18,6 +19,11 @@ pub struct GetCompletedQuestsQuery { addr: FieldElement, } +#[route( + get, + "/boost/get_completed_boosts", + crate::endpoints::quest_boost::get_completed_boosts +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quest_boost/get_pending_claims.rs b/src/endpoints/quest_boost/get_pending_claims.rs index bdb32629..28d49143 100644 --- a/src/endpoints/quest_boost/get_pending_claims.rs +++ b/src/endpoints/quest_boost/get_pending_claims.rs @@ -8,6 +8,7 @@ use axum::{ http::StatusCode, response::{IntoResponse, Json}, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -19,6 +20,11 @@ pub struct GetQuestsQuery { addr: FieldElement, } +#[route( + get, + "/boost/get_pending_claims", + crate::endpoints::quest_boost::get_pending_claims +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quest_boost/get_quests.rs b/src/endpoints/quest_boost/get_quests.rs index e46afc51..782bf3ce 100644 --- a/src/endpoints/quest_boost/get_quests.rs +++ b/src/endpoints/quest_boost/get_quests.rs @@ -6,6 +6,7 @@ use axum::{ http::StatusCode, response::{IntoResponse, Json}, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use mongodb::bson::from_document; @@ -17,6 +18,7 @@ pub struct GetQuestForBoostQuery { boost_id: u32, } +#[route(get, "/boost/get_quests", crate::endpoints::quest_boost::get_quests)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/avnu/claimable.rs b/src/endpoints/quests/avnu/claimable.rs index 8cfba227..7f79dd18 100644 --- a/src/endpoints/quests/avnu/claimable.rs +++ b/src/endpoints/quests/avnu/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/avnu/claimable", + crate::endpoints::quests::avnu::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/avnu/discord_fw_callback.rs b/src/endpoints/quests/avnu/discord_fw_callback.rs index 19288a11..c0ae5712 100644 --- a/src/endpoints/quests/avnu/discord_fw_callback.rs +++ b/src/endpoints/quests/avnu/discord_fw_callback.rs @@ -9,6 +9,7 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use mongodb::bson::doc; use reqwest::header::AUTHORIZATION; use serde::Deserialize; @@ -27,6 +28,11 @@ pub struct Guild { name: String, } +#[route( + get, + "/quests/avnu/discord_fw_callback", + crate::endpoints::quests::avnu::discord_fw_callback +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/avnu/verify_swap.rs b/src/endpoints/quests/avnu/verify_swap.rs index c1540a98..ce50ca20 100644 --- a/src/endpoints/quests/avnu/verify_swap.rs +++ b/src/endpoints/quests/avnu/verify_swap.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/avnu/verify_swap", + crate::endpoints::quests::avnu::verify_swap +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/avnu/claimable.rs b/src/endpoints/quests/braavos/avnu/claimable.rs index 8c1d7a0f..39dd65da 100644 --- a/src/endpoints/quests/braavos/avnu/claimable.rs +++ b/src/endpoints/quests/braavos/avnu/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/braavos/avnu/claimable", + crate::endpoints::quests::braavos::avnu::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/braavos/avnu/verify_has_domain.rs b/src/endpoints/quests/braavos/avnu/verify_has_domain.rs index 0d65ce44..4e69684c 100644 --- a/src/endpoints/quests/braavos/avnu/verify_has_domain.rs +++ b/src/endpoints/quests/braavos/avnu/verify_has_domain.rs @@ -6,8 +6,14 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use std::sync::Arc; +#[route( + get, + "/quests/braavos/avnu/verify_has_domain", + crate::endpoints::quests::braavos::avnu::verify_has_domain +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/avnu/verify_swap.rs b/src/endpoints/quests/braavos/avnu/verify_swap.rs index 9c794163..c90bfe37 100644 --- a/src/endpoints/quests/braavos/avnu/verify_swap.rs +++ b/src/endpoints/quests/braavos/avnu/verify_swap.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/avnu/verify_swap", + crate::endpoints::quests::braavos::avnu::verify_swap +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/avnu/verify_twitter_fw_avnu.rs b/src/endpoints/quests/braavos/avnu/verify_twitter_fw_avnu.rs index 9f1db308..5b944743 100644 --- a/src/endpoints/quests/braavos/avnu/verify_twitter_fw_avnu.rs +++ b/src/endpoints/quests/braavos/avnu/verify_twitter_fw_avnu.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/avnu/verify_twitter_fw_avnu", + crate::endpoints::quests::braavos::avnu::verify_twitter_fw_avnu +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/avnu/verify_twitter_fw_braavos.rs b/src/endpoints/quests/braavos/avnu/verify_twitter_fw_braavos.rs index c954043a..7ee374fe 100644 --- a/src/endpoints/quests/braavos/avnu/verify_twitter_fw_braavos.rs +++ b/src/endpoints/quests/braavos/avnu/verify_twitter_fw_braavos.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/avnu/verify_twitter_fw_braavos", + crate::endpoints::quests::braavos::avnu::verify_twitter_fw_braavos +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/avnu/verify_twitter_rt.rs b/src/endpoints/quests/braavos/avnu/verify_twitter_rt.rs index 69310c7d..7e7f8e9f 100644 --- a/src/endpoints/quests/braavos/avnu/verify_twitter_rt.rs +++ b/src/endpoints/quests/braavos/avnu/verify_twitter_rt.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/avnu/verify_twitter_rt", + crate::endpoints::quests::braavos::avnu::verify_twitter_rt +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/myswap/claimable.rs b/src/endpoints/quests/braavos/myswap/claimable.rs index 3770a02b..4d76673c 100644 --- a/src/endpoints/quests/braavos/myswap/claimable.rs +++ b/src/endpoints/quests/braavos/myswap/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/braavos/myswap/claimable", + crate::endpoints::quests::braavos::myswap::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/braavos/myswap/verify_added_liquidity.rs b/src/endpoints/quests/braavos/myswap/verify_added_liquidity.rs index 79e0ddfd..98b79282 100644 --- a/src/endpoints/quests/braavos/myswap/verify_added_liquidity.rs +++ b/src/endpoints/quests/braavos/myswap/verify_added_liquidity.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::{ core::types::{BlockId, BlockTag, FieldElement, FunctionCall}, @@ -17,6 +18,11 @@ use starknet::{ providers::Provider, }; +#[route( + get, + "/quests/braavos/myswap/verify_added_liquidity", + crate::endpoints::quests::braavos::myswap::verify_added_liquidity +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/myswap/verify_has_domain.rs b/src/endpoints/quests/braavos/myswap/verify_has_domain.rs index dd41cd7f..378b1e74 100644 --- a/src/endpoints/quests/braavos/myswap/verify_has_domain.rs +++ b/src/endpoints/quests/braavos/myswap/verify_has_domain.rs @@ -6,8 +6,14 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use std::sync::Arc; +#[route( + get, + "/quests/braavos/myswap/verify_has_domain", + crate::endpoints::quests::braavos::myswap::verify_has_domain +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/myswap/verify_twitter_fw_braavos.rs b/src/endpoints/quests/braavos/myswap/verify_twitter_fw_braavos.rs index 4b755b84..83f3a740 100644 --- a/src/endpoints/quests/braavos/myswap/verify_twitter_fw_braavos.rs +++ b/src/endpoints/quests/braavos/myswap/verify_twitter_fw_braavos.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/myswap/verify_twitter_fw_braavos", + crate::endpoints::quests::braavos::myswap::verify_twitter_fw_braavos +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/myswap/verify_twitter_fw_myswap.rs b/src/endpoints/quests/braavos/myswap/verify_twitter_fw_myswap.rs index 7533357c..4d273433 100644 --- a/src/endpoints/quests/braavos/myswap/verify_twitter_fw_myswap.rs +++ b/src/endpoints/quests/braavos/myswap/verify_twitter_fw_myswap.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/myswap/verify_twitter_fw_myswap", + crate::endpoints::quests::braavos::myswap::verify_twitter_fw_myswap +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/pyramid/claimable.rs b/src/endpoints/quests/braavos/pyramid/claimable.rs index 02642fd1..7e590125 100644 --- a/src/endpoints/quests/braavos/pyramid/claimable.rs +++ b/src/endpoints/quests/braavos/pyramid/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/braavos/pyramid/claimable", + crate::endpoints::quests::braavos::pyramid::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,7 +85,9 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); }; diff --git a/src/endpoints/quests/braavos/pyramid/verify_buy_or_list.rs b/src/endpoints/quests/braavos/pyramid/verify_buy_or_list.rs index b67734e5..fdd05a40 100644 --- a/src/endpoints/quests/braavos/pyramid/verify_buy_or_list.rs +++ b/src/endpoints/quests/braavos/pyramid/verify_buy_or_list.rs @@ -1,19 +1,22 @@ use std::sync::Arc; -use crate::{ - models::{AppState}, - utils::{get_error}, -}; +use crate::models::VerifyQuery; +use crate::utils::{fetch_json_from_url, to_hex, CompletedTasksTrait}; +use crate::{models::AppState, utils::get_error}; use axum::{ extract::{Query, State}, http::StatusCode, response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; -use crate::models::{VerifyQuery}; -use crate::utils::{CompletedTasksTrait, fetch_json_from_url, to_hex}; +#[route( + get, + "/quests/braavos/pyramid/verify_buy_or_list", + crate::endpoints::quests::braavos::pyramid::verify_buy_or_list +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -22,7 +25,8 @@ pub async fn handler( // make get request to pyramid api for verification let url = format!( - "{}/{}/isEligibleForQuest", state.conf.pyramid.api_endpoint, + "{}/{}/isEligibleForQuest", + state.conf.pyramid.api_endpoint, to_hex(query.addr) ); @@ -31,12 +35,8 @@ pub async fn handler( let has_bought_or_listed_nft = response.get("result").unwrap().as_bool().unwrap(); return if has_bought_or_listed_nft { match state.upsert_completed_task(query.addr, task_id).await { - Ok(_) => { - (StatusCode::OK, Json(json!({"res": true}))).into_response() - } - Err(e) => { - get_error(format!("{}", e)) - } + Ok(_) => (StatusCode::OK, Json(json!({"res": true}))).into_response(), + Err(e) => get_error(format!("{}", e)), } } else { get_error("NFT not bought/listed".to_string()) @@ -44,4 +44,4 @@ pub async fn handler( } Err(e) => get_error(format!("{}", e)), } -} \ No newline at end of file +} diff --git a/src/endpoints/quests/braavos/pyramid/verify_has_domain.rs b/src/endpoints/quests/braavos/pyramid/verify_has_domain.rs index f09723ea..ab167faa 100644 --- a/src/endpoints/quests/braavos/pyramid/verify_has_domain.rs +++ b/src/endpoints/quests/braavos/pyramid/verify_has_domain.rs @@ -6,8 +6,14 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use std::sync::Arc; +#[route( + get, + "/quests/braavos/pyramid/verify_has_domain", + crate::endpoints::quests::braavos::pyramid::verify_has_domain +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/pyramid/verify_twitter_fw_braavos.rs b/src/endpoints/quests/braavos/pyramid/verify_twitter_fw_braavos.rs index dfe180dc..10bd7f8f 100644 --- a/src/endpoints/quests/braavos/pyramid/verify_twitter_fw_braavos.rs +++ b/src/endpoints/quests/braavos/pyramid/verify_twitter_fw_braavos.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/pyramid/verify_twitter_fw_braavos", + crate::endpoints::quests::braavos::pyramid::verify_twitter_fw_braavos +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/pyramid/verify_twitter_fw_pyramid.rs b/src/endpoints/quests/braavos/pyramid/verify_twitter_fw_pyramid.rs index c3fccbd3..514e8ab9 100644 --- a/src/endpoints/quests/braavos/pyramid/verify_twitter_fw_pyramid.rs +++ b/src/endpoints/quests/braavos/pyramid/verify_twitter_fw_pyramid.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/pyramid/verify_twitter_fw_pyramid", + crate::endpoints::quests::braavos::pyramid::verify_twitter_fw_pyramid +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/pyramid/verify_twitter_rt.rs b/src/endpoints/quests/braavos/pyramid/verify_twitter_rt.rs index 6cb212e8..781be8ad 100644 --- a/src/endpoints/quests/braavos/pyramid/verify_twitter_rt.rs +++ b/src/endpoints/quests/braavos/pyramid/verify_twitter_rt.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/pyramid/verify_twitter_rt", + crate::endpoints::quests::braavos::pyramid::verify_twitter_rt +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/starknetid/claimable.rs b/src/endpoints/quests/braavos/starknetid/claimable.rs index 589ff6cc..d8d0b28f 100644 --- a/src/endpoints/quests/braavos/starknetid/claimable.rs +++ b/src/endpoints/quests/braavos/starknetid/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/braavos/starknetid/claimable", + crate::endpoints::quests::braavos::starknetid::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/braavos/starknetid/verify_has_domain.rs b/src/endpoints/quests/braavos/starknetid/verify_has_domain.rs index a1862950..c0e51dda 100644 --- a/src/endpoints/quests/braavos/starknetid/verify_has_domain.rs +++ b/src/endpoints/quests/braavos/starknetid/verify_has_domain.rs @@ -6,8 +6,14 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use std::sync::Arc; +#[route( + get, + "/quests/braavos/starknetid/verify_has_domain", + crate::endpoints::quests::braavos::starknetid::verify_has_domain +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/starknetid/verify_has_mission.rs b/src/endpoints/quests/braavos/starknetid/verify_has_mission.rs index 65742e90..a82efa09 100644 --- a/src/endpoints/quests/braavos/starknetid/verify_has_mission.rs +++ b/src/endpoints/quests/braavos/starknetid/verify_has_mission.rs @@ -6,6 +6,7 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use reqwest::header::{self, AUTHORIZATION}; use serde::Deserialize; use starknet::core::types::FieldElement; @@ -24,6 +25,11 @@ pub struct DiscordUser { username: String, } +#[route( + get, + "/quests/braavos/starknetid/verify_has_mission", + crate::endpoints::quests::braavos::starknetid::verify_has_mission +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/starknetid/verify_twitter_fw_braavos.rs b/src/endpoints/quests/braavos/starknetid/verify_twitter_fw_braavos.rs index c1139a3f..58e99fb8 100644 --- a/src/endpoints/quests/braavos/starknetid/verify_twitter_fw_braavos.rs +++ b/src/endpoints/quests/braavos/starknetid/verify_twitter_fw_braavos.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/starknetid/verify_twitter_fw_braavos", + crate::endpoints::quests::braavos::starknetid::verify_twitter_fw_braavos +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/starknetid/verify_twitter_fw_sid.rs b/src/endpoints/quests/braavos/starknetid/verify_twitter_fw_sid.rs index 4a03e3d8..75ea9e81 100644 --- a/src/endpoints/quests/braavos/starknetid/verify_twitter_fw_sid.rs +++ b/src/endpoints/quests/braavos/starknetid/verify_twitter_fw_sid.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/starknetid/verify_twitter_fw_sid", + crate::endpoints::quests::braavos::starknetid::verify_twitter_fw_sid +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/starknetid/verify_twitter_fw_sq.rs b/src/endpoints/quests/braavos/starknetid/verify_twitter_fw_sq.rs index 37f5074f..daecbe87 100644 --- a/src/endpoints/quests/braavos/starknetid/verify_twitter_fw_sq.rs +++ b/src/endpoints/quests/braavos/starknetid/verify_twitter_fw_sq.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/starknetid/verify_twitter_fw_sq", + crate::endpoints::quests::braavos::starknetid::verify_twitter_fw_sq +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/wallet/claimable.rs b/src/endpoints/quests/braavos/wallet/claimable.rs index 1f6882d8..6bec7b80 100644 --- a/src/endpoints/quests/braavos/wallet/claimable.rs +++ b/src/endpoints/quests/braavos/wallet/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/braavos/wallet/claimable", + crate::endpoints::quests::braavos::wallet::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/braavos/wallet/verify_has_domain.rs b/src/endpoints/quests/braavos/wallet/verify_has_domain.rs index 8d68efff..ba2ea2d1 100644 --- a/src/endpoints/quests/braavos/wallet/verify_has_domain.rs +++ b/src/endpoints/quests/braavos/wallet/verify_has_domain.rs @@ -6,8 +6,14 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use std::sync::Arc; +#[route( + get, + "/quests/braavos/wallet/verify_has_domain", + crate::endpoints::quests::braavos::wallet::verify_has_domain +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/wallet/verify_twitter_fw_braavos.rs b/src/endpoints/quests/braavos/wallet/verify_twitter_fw_braavos.rs index e5e9d578..b33eee83 100644 --- a/src/endpoints/quests/braavos/wallet/verify_twitter_fw_braavos.rs +++ b/src/endpoints/quests/braavos/wallet/verify_twitter_fw_braavos.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/wallet/verify_twitter_fw_braavos", + crate::endpoints::quests::braavos::wallet::verify_twitter_fw_braavos +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/wallet/verify_twitter_rt.rs b/src/endpoints/quests/braavos/wallet/verify_twitter_rt.rs index 3ccf2ddc..cc918f02 100644 --- a/src/endpoints/quests/braavos/wallet/verify_twitter_rt.rs +++ b/src/endpoints/quests/braavos/wallet/verify_twitter_rt.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/wallet/verify_twitter_rt", + crate::endpoints::quests::braavos::wallet::verify_twitter_rt +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/zklend/claimable.rs b/src/endpoints/quests/braavos/zklend/claimable.rs index ca894a27..3dc6de8a 100644 --- a/src/endpoints/quests/braavos/zklend/claimable.rs +++ b/src/endpoints/quests/braavos/zklend/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/braavos/zklend/claimable", + crate::endpoints::quests::braavos::zklend::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,7 +85,9 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); }; diff --git a/src/endpoints/quests/braavos/zklend/verify_added_liquidity.rs b/src/endpoints/quests/braavos/zklend/verify_added_liquidity.rs index 95dca1d9..21bc3eba 100644 --- a/src/endpoints/quests/braavos/zklend/verify_added_liquidity.rs +++ b/src/endpoints/quests/braavos/zklend/verify_added_liquidity.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::{ core::types::{BlockId, BlockTag, FieldElement, FunctionCall}, @@ -17,6 +18,11 @@ use starknet::{ providers::Provider, }; +#[route( + get, + "/quests/braavos/zklend/verify_added_liquidity", + crate::endpoints::quests::braavos::zklend::verify_added_liquidity +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/zklend/verify_has_domain.rs b/src/endpoints/quests/braavos/zklend/verify_has_domain.rs index d85f93da..f504d1b2 100644 --- a/src/endpoints/quests/braavos/zklend/verify_has_domain.rs +++ b/src/endpoints/quests/braavos/zklend/verify_has_domain.rs @@ -6,8 +6,14 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use std::sync::Arc; +#[route( + get, + "/quests/braavos/zklend/verify_has_domain", + crate::endpoints::quests::braavos::zklend::verify_has_domain +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/zklend/verify_twitter_fw_braavos.rs b/src/endpoints/quests/braavos/zklend/verify_twitter_fw_braavos.rs index fe81725c..a6e27f93 100644 --- a/src/endpoints/quests/braavos/zklend/verify_twitter_fw_braavos.rs +++ b/src/endpoints/quests/braavos/zklend/verify_twitter_fw_braavos.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/zklend/verify_twitter_fw_braavos", + crate::endpoints::quests::braavos::zklend::verify_twitter_fw_braavos +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/zklend/verify_twitter_fw_zklend.rs b/src/endpoints/quests/braavos/zklend/verify_twitter_fw_zklend.rs index 907b2533..c782d357 100644 --- a/src/endpoints/quests/braavos/zklend/verify_twitter_fw_zklend.rs +++ b/src/endpoints/quests/braavos/zklend/verify_twitter_fw_zklend.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/zklend/verify_twitter_fw_zklend", + crate::endpoints::quests::braavos::zklend::verify_twitter_fw_zklend +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/braavos/zklend/verify_twitter_rt.rs b/src/endpoints/quests/braavos/zklend/verify_twitter_rt.rs index 864cc86c..499ceb50 100644 --- a/src/endpoints/quests/braavos/zklend/verify_twitter_rt.rs +++ b/src/endpoints/quests/braavos/zklend/verify_twitter_rt.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/braavos/zklend/verify_twitter_rt", + crate::endpoints::quests::braavos::zklend::verify_twitter_rt +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/carmine/claimable.rs b/src/endpoints/quests/carmine/claimable.rs index 4b673c12..9ddc4d9e 100644 --- a/src/endpoints/quests/carmine/claimable.rs +++ b/src/endpoints/quests/carmine/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/carmine/claimable", + crate::endpoints::quests::carmine::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/contract_uri.rs b/src/endpoints/quests/contract_uri.rs index 2cceae59..af09ebd5 100644 --- a/src/endpoints/quests/contract_uri.rs +++ b/src/endpoints/quests/contract_uri.rs @@ -5,6 +5,7 @@ use axum::{ response::{IntoResponse, Response}, Json, }; +use axum_auto_routes::route; use serde::Serialize; use std::sync::Arc; @@ -17,6 +18,7 @@ pub struct TokenURI { external_link: String, } +#[route(get, "/quests/contract_uri", crate::endpoints::quests::contract_uri)] pub async fn handler(State(state): State>) -> Response { let response = TokenURI { name: "Starknet Quest".into(), diff --git a/src/endpoints/quests/ekubo/claimable.rs b/src/endpoints/quests/ekubo/claimable.rs index 307b3b56..df168f9d 100644 --- a/src/endpoints/quests/ekubo/claimable.rs +++ b/src/endpoints/quests/ekubo/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/ekubo/claimable", + crate::endpoints::quests::ekubo::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/ekubo/discord_fw_callback.rs b/src/endpoints/quests/ekubo/discord_fw_callback.rs index eacaf606..82a784a4 100644 --- a/src/endpoints/quests/ekubo/discord_fw_callback.rs +++ b/src/endpoints/quests/ekubo/discord_fw_callback.rs @@ -9,6 +9,7 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use mongodb::bson::doc; use reqwest::header::AUTHORIZATION; use serde::Deserialize; @@ -27,6 +28,11 @@ pub struct Guild { name: String, } +#[route( + get, + "/quests/ekubo/discord_fw_callback", + crate::endpoints::quests::ekubo::discord_fw_callback +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/ekubo/verify_added_liquidity.rs b/src/endpoints/quests/ekubo/verify_added_liquidity.rs index 8d7c658c..1a798715 100644 --- a/src/endpoints/quests/ekubo/verify_added_liquidity.rs +++ b/src/endpoints/quests/ekubo/verify_added_liquidity.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::{ core::types::{BlockId, BlockTag, FieldElement, FunctionCall}, @@ -17,6 +18,11 @@ use starknet::{ providers::Provider, }; +#[route( + get, + "/quests/ekubo/verify_added_liquidity", + crate::endpoints::quests::ekubo::verify_added_liquidity +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/ekubo/verify_quiz.rs b/src/endpoints/quests/ekubo/verify_quiz.rs index a648d804..9cf7fb47 100644 --- a/src/endpoints/quests/ekubo/verify_quiz.rs +++ b/src/endpoints/quests/ekubo/verify_quiz.rs @@ -6,9 +6,15 @@ use crate::{ utils::{get_error, CompletedTasksTrait}, }; use axum::{extract::State, http::StatusCode, response::IntoResponse, Json}; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + post, + "/quests/ekubo/verify_quiz", + crate::endpoints::quests::ekubo::verify_quiz +)] pub async fn handler( State(state): State>, body: Json, diff --git a/src/endpoints/quests/element/briq/claimable.rs b/src/endpoints/quests/element/briq/claimable.rs index 4d61e897..d198ab07 100644 --- a/src/endpoints/quests/element/briq/claimable.rs +++ b/src/endpoints/quests/element/briq/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/element/briq/claimable", + crate::endpoints::quests::element::briq::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/element/briq/verify_own_briq.rs b/src/endpoints/quests/element/briq/verify_own_briq.rs index 72df4be8..bdde2e5e 100644 --- a/src/endpoints/quests/element/briq/verify_own_briq.rs +++ b/src/endpoints/quests/element/briq/verify_own_briq.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use crate::utils::fetch_json_from_url; use crate::{ models::{AppState, VerifyQuery}, utils::{get_error, to_hex, CompletedTasksTrait}, @@ -10,10 +11,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; -use crate::utils::fetch_json_from_url; +#[route( + get, + "/quests/element/briq/verify_own_briq", + crate::endpoints::quests::element::briq::verify_own_briq +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/element/briq/verify_twitter_fw.rs b/src/endpoints/quests/element/briq/verify_twitter_fw.rs index 01c1b670..6e10acd0 100644 --- a/src/endpoints/quests/element/briq/verify_twitter_fw.rs +++ b/src/endpoints/quests/element/briq/verify_twitter_fw.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/quests/element/briq/verify_twitter_fw", + crate::endpoints::quests::element::briq::verify_twitter_fw +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/element/element/claimable.rs b/src/endpoints/quests/element/element/claimable.rs index 6b3b6c9d..590a8828 100644 --- a/src/endpoints/quests/element/element/claimable.rs +++ b/src/endpoints/quests/element/element/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/element/element/claimable", + crate::endpoints::quests::element::element::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/element/element/verify_is_eligible.rs b/src/endpoints/quests/element/element/verify_is_eligible.rs index 08954458..23fb09c6 100644 --- a/src/endpoints/quests/element/element/verify_is_eligible.rs +++ b/src/endpoints/quests/element/element/verify_is_eligible.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde::Deserialize; use serde_json::json; use starknet::core::types::FieldElement; @@ -21,6 +22,11 @@ pub struct ElementResponse { data: bool, } +#[route( + get, + "/quests/element/element/verify_is_eligible", + crate::endpoints::quests::element::element::verify_is_eligible +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/element/element/verify_twitter_fw.rs b/src/endpoints/quests/element/element/verify_twitter_fw.rs index e1d40ce9..0ff98ce5 100644 --- a/src/endpoints/quests/element/element/verify_twitter_fw.rs +++ b/src/endpoints/quests/element/element/verify_twitter_fw.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/quests/element/element/verify_twitter_fw", + crate::endpoints::quests::element::element::verify_twitter_fw +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/element/layerswap/claimable.rs b/src/endpoints/quests/element/layerswap/claimable.rs index 19c78ce2..38c22e77 100644 --- a/src/endpoints/quests/element/layerswap/claimable.rs +++ b/src/endpoints/quests/element/layerswap/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/element/layerswap/claimable", + crate::endpoints::quests::element::layerswap::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/element/layerswap/verify_has_bridged.rs b/src/endpoints/quests/element/layerswap/verify_has_bridged.rs index afff3a6e..f31eb2c5 100644 --- a/src/endpoints/quests/element/layerswap/verify_has_bridged.rs +++ b/src/endpoints/quests/element/layerswap/verify_has_bridged.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde::Deserialize; use serde_json::json; @@ -29,6 +30,11 @@ struct LayerswapError { message: String, } +#[route( + get, + "/quests/element/layerswap/verify_has_bridged", + crate::endpoints::quests::element::layerswap::verify_has_bridged +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/element/layerswap/verify_twitter_fw.rs b/src/endpoints/quests/element/layerswap/verify_twitter_fw.rs index e2aadc9c..68c1cc1f 100644 --- a/src/endpoints/quests/element/layerswap/verify_twitter_fw.rs +++ b/src/endpoints/quests/element/layerswap/verify_twitter_fw.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/quests/element/layerswap/verify_twitter_fw", + crate::endpoints::quests::element::layerswap::verify_twitter_fw +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/element/layerswap/verify_twitter_rt.rs b/src/endpoints/quests/element/layerswap/verify_twitter_rt.rs index bd0fac98..43e7de21 100644 --- a/src/endpoints/quests/element/layerswap/verify_twitter_rt.rs +++ b/src/endpoints/quests/element/layerswap/verify_twitter_rt.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/quests/element/layerswap/verify_twitter_rt", + crate::endpoints::quests::element::layerswap::verify_twitter_rt +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/element/starknetid/claimable.rs b/src/endpoints/quests/element/starknetid/claimable.rs index 8e8f36fd..22de2f23 100644 --- a/src/endpoints/quests/element/starknetid/claimable.rs +++ b/src/endpoints/quests/element/starknetid/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/element/starknetid/claimable", + crate::endpoints::quests::element::starknetid::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/element/starknetid/verify_has_root_domain.rs b/src/endpoints/quests/element/starknetid/verify_has_root_domain.rs index 06a90998..81eb4bab 100644 --- a/src/endpoints/quests/element/starknetid/verify_has_root_domain.rs +++ b/src/endpoints/quests/element/starknetid/verify_has_root_domain.rs @@ -6,8 +6,14 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use std::sync::Arc; +#[route( + get, + "/quests/element/starknetid/verify_has_root_domain", + crate::endpoints::quests::element::starknetid::verify_has_root_domain +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/focustree/engagement/discord_fw_callback.rs b/src/endpoints/quests/focustree/engagement/discord_fw_callback.rs index 99ce58bf..857a8257 100644 --- a/src/endpoints/quests/focustree/engagement/discord_fw_callback.rs +++ b/src/endpoints/quests/focustree/engagement/discord_fw_callback.rs @@ -9,6 +9,7 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use mongodb::bson::doc; use reqwest::header::AUTHORIZATION; use serde::Deserialize; @@ -27,6 +28,11 @@ pub struct Guild { name: String, } +#[route( + get, + "/quests/focustree/discord_fw_callback", + crate::endpoints::quests::focustree::engagement::discord_fw_callback +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/focustree/engagement/verify_twitter_rt.rs b/src/endpoints/quests/focustree/engagement/verify_twitter_rt.rs index b478eb77..49ca8383 100644 --- a/src/endpoints/quests/focustree/engagement/verify_twitter_rt.rs +++ b/src/endpoints/quests/focustree/engagement/verify_twitter_rt.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/focustree/verify_twitter_rw_user", + crate::endpoints::quests::focustree::engagement::verify_twitter_rt +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/focustree/introduction/claimable.rs b/src/endpoints/quests/focustree/introduction/claimable.rs index 4ab53fcc..550568f0 100644 --- a/src/endpoints/quests/focustree/introduction/claimable.rs +++ b/src/endpoints/quests/focustree/introduction/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/focustree/claimable", + crate::endpoints::quests::focustree::introduction::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/focustree/introduction/verify_twitter_fw.rs b/src/endpoints/quests/focustree/introduction/verify_twitter_fw.rs index 941c7b1a..e4d866d5 100644 --- a/src/endpoints/quests/focustree/introduction/verify_twitter_fw.rs +++ b/src/endpoints/quests/focustree/introduction/verify_twitter_fw.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/focustree/verify_twitter_fw", + crate::endpoints::quests::focustree::introduction::verify_twitter_fw +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/focustree/introduction/verify_twitter_rt.rs b/src/endpoints/quests/focustree/introduction/verify_twitter_rt.rs index 332cb6ad..a2d6de6b 100644 --- a/src/endpoints/quests/focustree/introduction/verify_twitter_rt.rs +++ b/src/endpoints/quests/focustree/introduction/verify_twitter_rt.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/focustree/verify_twitter_rt", + crate::endpoints::quests::focustree::introduction::verify_twitter_rt +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/jediswap/claimable.rs b/src/endpoints/quests/jediswap/claimable.rs index 076acb93..0b82b5ae 100644 --- a/src/endpoints/quests/jediswap/claimable.rs +++ b/src/endpoints/quests/jediswap/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/jediswap/claimable", + crate::endpoints::quests::jediswap::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/jediswap/verify_added_liquidity.rs b/src/endpoints/quests/jediswap/verify_added_liquidity.rs index e68d7030..101c2609 100644 --- a/src/endpoints/quests/jediswap/verify_added_liquidity.rs +++ b/src/endpoints/quests/jediswap/verify_added_liquidity.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::{ core::types::{BlockId, BlockTag, FieldElement, FunctionCall}, @@ -17,6 +18,11 @@ use starknet::{ providers::Provider, }; +#[route( + get, + "/quests/jediswap/verify_added_liquidity", + crate::endpoints::quests::jediswap::verify_added_liquidity +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/jediswap/verify_twitter_fw.rs b/src/endpoints/quests/jediswap/verify_twitter_fw.rs index e1979680..09a01933 100644 --- a/src/endpoints/quests/jediswap/verify_twitter_fw.rs +++ b/src/endpoints/quests/jediswap/verify_twitter_fw.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/jediswap/verify_twitter_fw", + crate::endpoints::quests::jediswap::verify_twitter_fw +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/jediswap/verify_twitter_rt.rs b/src/endpoints/quests/jediswap/verify_twitter_rt.rs index 92e3ded6..5f9ea58a 100644 --- a/src/endpoints/quests/jediswap/verify_twitter_rt.rs +++ b/src/endpoints/quests/jediswap/verify_twitter_rt.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/jediswap/verify_twitter_rt", + crate::endpoints::quests::jediswap::verify_twitter_rt +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/morphine/claimable.rs b/src/endpoints/quests/morphine/claimable.rs index 5b818a4c..1644751d 100644 --- a/src/endpoints/quests/morphine/claimable.rs +++ b/src/endpoints/quests/morphine/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/morphine/claimable", + crate::endpoints::quests::morphine::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/morphine/verify_added_liquidity.rs b/src/endpoints/quests/morphine/verify_added_liquidity.rs index efffd431..37cfcea3 100644 --- a/src/endpoints/quests/morphine/verify_added_liquidity.rs +++ b/src/endpoints/quests/morphine/verify_added_liquidity.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::{ core::types::{BlockId, BlockTag, FieldElement, FunctionCall}, @@ -34,6 +35,11 @@ lazy_static::lazy_static! { ]; } +#[route( + get, + "/quests/morphine/verify_added_liquidity", + crate::endpoints::quests::morphine::verify_added_liquidity +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/myswap/claimable.rs b/src/endpoints/quests/myswap/claimable.rs index b4485238..e6d56294 100644 --- a/src/endpoints/quests/myswap/claimable.rs +++ b/src/endpoints/quests/myswap/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/myswap/claimable", + crate::endpoints::quests::myswap::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/myswap/discord_fw_callback.rs b/src/endpoints/quests/myswap/discord_fw_callback.rs index 7e51c332..88346a75 100644 --- a/src/endpoints/quests/myswap/discord_fw_callback.rs +++ b/src/endpoints/quests/myswap/discord_fw_callback.rs @@ -9,6 +9,7 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use mongodb::bson::doc; use reqwest::header::AUTHORIZATION; use serde::Deserialize; @@ -27,6 +28,11 @@ pub struct Guild { name: String, } +#[route( + get, + "/quests/myswap/discord_fw_callback", + crate::endpoints::quests::myswap::discord_fw_callback +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/myswap/verify_added_liquidity.rs b/src/endpoints/quests/myswap/verify_added_liquidity.rs index cadad015..d8a00924 100644 --- a/src/endpoints/quests/myswap/verify_added_liquidity.rs +++ b/src/endpoints/quests/myswap/verify_added_liquidity.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::{ core::types::{BlockId, BlockTag, FieldElement, FunctionCall}, @@ -17,6 +18,11 @@ use starknet::{ providers::Provider, }; +#[route( + get, + "/quests/myswap/verify_added_liquidity", + crate::endpoints::quests::myswap::verify_added_liquidity +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/nostra/claimable.rs b/src/endpoints/quests/nostra/claimable.rs index f1ea8d89..3e9c16de 100644 --- a/src/endpoints/quests/nostra/claimable.rs +++ b/src/endpoints/quests/nostra/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/nostra/claimable", + crate::endpoints::quests::nostra::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/nostra/discord_fw_callback.rs b/src/endpoints/quests/nostra/discord_fw_callback.rs index c5576ec3..b1c46b2a 100644 --- a/src/endpoints/quests/nostra/discord_fw_callback.rs +++ b/src/endpoints/quests/nostra/discord_fw_callback.rs @@ -9,6 +9,7 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use mongodb::bson::doc; use reqwest::header::AUTHORIZATION; use serde::Deserialize; @@ -27,6 +28,11 @@ pub struct Guild { name: String, } +#[route( + get, + "/quests/nostra/discord_fw_callback", + crate::endpoints::quests::nostra::discord_fw_callback +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/nostra/verify_added_liquidity.rs b/src/endpoints/quests/nostra/verify_added_liquidity.rs index b1611449..9208fb21 100644 --- a/src/endpoints/quests/nostra/verify_added_liquidity.rs +++ b/src/endpoints/quests/nostra/verify_added_liquidity.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::{ core::types::{BlockId, BlockTag, FieldElement, FunctionCall}, @@ -17,6 +18,11 @@ use starknet::{ providers::Provider, }; +#[route( + get, + "/quests/nostra/verify_added_liquidity", + crate::endpoints::quests::nostra::verify_added_liquidity +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/orbiter/claimable.rs b/src/endpoints/quests/orbiter/claimable.rs index de752229..ba1ee945 100644 --- a/src/endpoints/quests/orbiter/claimable.rs +++ b/src/endpoints/quests/orbiter/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/orbiter/claimable", + crate::endpoints::quests::orbiter::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/orbiter/verify_has_bridged.rs b/src/endpoints/quests/orbiter/verify_has_bridged.rs index 5833ee06..5acf212b 100644 --- a/src/endpoints/quests/orbiter/verify_has_bridged.rs +++ b/src/endpoints/quests/orbiter/verify_has_bridged.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; #[derive(Debug, serde::Deserialize)] @@ -28,6 +29,11 @@ struct Response { data: Data, } +#[route( + get, + "/quests/orbiter/verify_has_bridged", + crate::endpoints::quests::orbiter::verify_has_bridged +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/orbiter/verify_has_root_domain.rs b/src/endpoints/quests/orbiter/verify_has_root_domain.rs index 1f9c3883..e1250063 100644 --- a/src/endpoints/quests/orbiter/verify_has_root_domain.rs +++ b/src/endpoints/quests/orbiter/verify_has_root_domain.rs @@ -6,8 +6,14 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use std::sync::Arc; +#[route( + get, + "/quests/orbiter/verify_has_root_domain", + crate::endpoints::quests::orbiter::verify_has_root_domain +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/orbiter/verify_twitter_fw.rs b/src/endpoints/quests/orbiter/verify_twitter_fw.rs index 48083e59..6fa56416 100644 --- a/src/endpoints/quests/orbiter/verify_twitter_fw.rs +++ b/src/endpoints/quests/orbiter/verify_twitter_fw.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/quests/orbiter/verify_twitter_fw", + crate::endpoints::quests::orbiter::verify_twitter_fw +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/orbiter/verify_twitter_fw_sq.rs b/src/endpoints/quests/orbiter/verify_twitter_fw_sq.rs index 18e92f08..b6711ee9 100644 --- a/src/endpoints/quests/orbiter/verify_twitter_fw_sq.rs +++ b/src/endpoints/quests/orbiter/verify_twitter_fw_sq.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/quests/orbiter/verify_twitter_fw_sq", + crate::endpoints::quests::orbiter::verify_twitter_fw_sq +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/orbiter/verify_twitter_rt.rs b/src/endpoints/quests/orbiter/verify_twitter_rt.rs index f577f0c2..ac0cc2f3 100644 --- a/src/endpoints/quests/orbiter/verify_twitter_rt.rs +++ b/src/endpoints/quests/orbiter/verify_twitter_rt.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/quests/orbiter/verify_twitter_rt", + crate::endpoints::quests::orbiter::verify_twitter_rt +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/rango/check_trade.rs b/src/endpoints/quests/rango/check_trade.rs index ad5533e6..2de0144d 100644 --- a/src/endpoints/quests/rango/check_trade.rs +++ b/src/endpoints/quests/rango/check_trade.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use crate::models::VerifyQuery; -use crate::utils::{CompletedTasksTrait, to_hex}; +use crate::utils::{to_hex, CompletedTasksTrait}; use crate::{models::AppState, utils::get_error}; use axum::{ extract::{Query, State}, @@ -9,7 +9,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; + +#[route( + get, + "/quests/rango/check_trade", + crate::endpoints::quests::rango::check_trade +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -35,7 +42,7 @@ pub async fn handler( &state.conf.rango.api_key, &address_hex, ) - .await; + .await; let response = match res { Ok(response) => response, Err(_) => return get_error(format!("Try again later")), @@ -67,7 +74,8 @@ async fn make_rango_request( })) .header("apiKey", api_key) .send() - .await { + .await + { Ok(response) => match response.json::().await { Ok(json) => Ok(json), Err(_) => Err(format!("Funds not bridged")), diff --git a/src/endpoints/quests/rango/claimable.rs b/src/endpoints/quests/rango/claimable.rs index 9913a78b..3b6d8f69 100644 --- a/src/endpoints/quests/rango/claimable.rs +++ b/src/endpoints/quests/rango/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/rango/claimable", + crate::endpoints::quests::rango::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/rango/discord_fw_callback.rs b/src/endpoints/quests/rango/discord_fw_callback.rs index 4c79fccb..87155c94 100644 --- a/src/endpoints/quests/rango/discord_fw_callback.rs +++ b/src/endpoints/quests/rango/discord_fw_callback.rs @@ -9,6 +9,7 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use mongodb::bson::doc; use reqwest::header::AUTHORIZATION; use serde::Deserialize; @@ -27,6 +28,11 @@ pub struct Guild { name: String, } +#[route( + get, + "/quests/rango/discord_fw_callback", + crate::endpoints::quests::rango::discord_fw_callback +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/rango/verify_twitter_fw.rs b/src/endpoints/quests/rango/verify_twitter_fw.rs index abeea52f..3062d1dd 100644 --- a/src/endpoints/quests/rango/verify_twitter_fw.rs +++ b/src/endpoints/quests/rango/verify_twitter_fw.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/rango/verify_twitter_fw", + crate::endpoints::quests::rango::verify_twitter_fw +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/rhino/check_bridge.rs b/src/endpoints/quests/rhino/check_bridge.rs index 8bb46829..80a2b784 100644 --- a/src/endpoints/quests/rhino/check_bridge.rs +++ b/src/endpoints/quests/rhino/check_bridge.rs @@ -11,8 +11,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/rhino/check_bridge", + crate::endpoints::quests::rhino::check_bridge +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/rhino/claimable.rs b/src/endpoints/quests/rhino/claimable.rs index 5e2433cb..ef570dac 100644 --- a/src/endpoints/quests/rhino/claimable.rs +++ b/src/endpoints/quests/rhino/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/rhino/claimable", + crate::endpoints::quests::rhino::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/rhino/verify_twitter_fw.rs b/src/endpoints/quests/rhino/verify_twitter_fw.rs index 48e0aca5..992f0a7d 100644 --- a/src/endpoints/quests/rhino/verify_twitter_fw.rs +++ b/src/endpoints/quests/rhino/verify_twitter_fw.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/rhino/verify_twitter_fw", + crate::endpoints::quests::rhino::verify_twitter_fw +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/rhino/verify_twitter_rw.rs b/src/endpoints/quests/rhino/verify_twitter_rw.rs index bb6085a3..600ba5a8 100644 --- a/src/endpoints/quests/rhino/verify_twitter_rw.rs +++ b/src/endpoints/quests/rhino/verify_twitter_rw.rs @@ -10,8 +10,14 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; +#[route( + get, + "/quests/rhino/verify_twitter_rw", + crate::endpoints::quests::rhino::verify_twitter_rw +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/sithswap/claimable.rs b/src/endpoints/quests/sithswap/claimable.rs index 48002552..a065f0e4 100644 --- a/src/endpoints/quests/sithswap/claimable.rs +++ b/src/endpoints/quests/sithswap/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/sithswap/claimable", + crate::endpoints::quests::sithswap::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/sithswap/verify_added_liquidity.rs b/src/endpoints/quests/sithswap/verify_added_liquidity.rs index 8e328382..badb412e 100644 --- a/src/endpoints/quests/sithswap/verify_added_liquidity.rs +++ b/src/endpoints/quests/sithswap/verify_added_liquidity.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::{ core::types::{BlockId, BlockTag, FieldElement, FunctionCall}, @@ -17,6 +18,11 @@ use starknet::{ providers::Provider, }; +#[route( + get, + "/quests/sithswap/verify_added_liquidity", + crate::endpoints::quests::sithswap::verify_added_liquidity +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/sithswap/verify_twitter_fw.rs b/src/endpoints/quests/sithswap/verify_twitter_fw.rs index eb0cbc0c..a37a715f 100644 --- a/src/endpoints/quests/sithswap/verify_twitter_fw.rs +++ b/src/endpoints/quests/sithswap/verify_twitter_fw.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/quests/sithswap/verify_twitter_fw", + crate::endpoints::quests::sithswap::verify_twitter_fw +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/starknet/aa_mastery/claimable.rs b/src/endpoints/quests/starknet/aa_mastery/claimable.rs index 4d6a1a38..90f35a13 100644 --- a/src/endpoints/quests/starknet/aa_mastery/claimable.rs +++ b/src/endpoints/quests/starknet/aa_mastery/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/starknet/aa_mastery/claimable", + crate::endpoints::quests::starknet::aa_mastery::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/starknet/gigabrain/claimable.rs b/src/endpoints/quests/starknet/gigabrain/claimable.rs index a172c738..9847f24b 100644 --- a/src/endpoints/quests/starknet/gigabrain/claimable.rs +++ b/src/endpoints/quests/starknet/gigabrain/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/starknet/gigabrain/claimable", + crate::endpoints::quests::starknet::gigabrain::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/starknetid/claimable.rs b/src/endpoints/quests/starknetid/claimable.rs index e690f6a5..be4b6397 100644 --- a/src/endpoints/quests/starknetid/claimable.rs +++ b/src/endpoints/quests/starknetid/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/starknetid/claimable", + crate::endpoints::quests::starknetid::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/starknetid/verify_has_domain.rs b/src/endpoints/quests/starknetid/verify_has_domain.rs index 3d24377c..52a57936 100644 --- a/src/endpoints/quests/starknetid/verify_has_domain.rs +++ b/src/endpoints/quests/starknetid/verify_has_domain.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use mongodb::bson::doc; use serde::Deserialize; use serde_json::json; @@ -24,6 +25,11 @@ pub struct StarknetIdQuery { addr: FieldElement, } +#[route( + get, + "/quests/starknetid/verify_has_domain", + crate::endpoints::quests::starknetid::verify_has_domain +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/starknetid/verify_has_root_domain.rs b/src/endpoints/quests/starknetid/verify_has_root_domain.rs index 1ea26402..f854b023 100644 --- a/src/endpoints/quests/starknetid/verify_has_root_domain.rs +++ b/src/endpoints/quests/starknetid/verify_has_root_domain.rs @@ -6,8 +6,14 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use std::sync::Arc; +#[route( + get, + "/quests/starknetid/verify_has_root_domain", + crate::endpoints::quests::starknetid::verify_has_root_domain +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/starknetid/verify_socials.rs b/src/endpoints/quests/starknetid/verify_socials.rs index be30f861..ea265cc7 100644 --- a/src/endpoints/quests/starknetid/verify_socials.rs +++ b/src/endpoints/quests/starknetid/verify_socials.rs @@ -8,6 +8,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::{ core::types::{BlockId, BlockTag, FieldElement, FunctionCall}, @@ -36,6 +37,12 @@ async fn call_contract_helper( result.map_err(|e| format!("{}", e)) } + +#[route( + get, + "/quests/starknetid/verify_socials", + crate::endpoints::quests::starknetid::verify_socials +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -66,7 +73,6 @@ pub async fn handler( let mut twitter = false; let mut discord = false; for verifier_contract in &state.conf.starknetid_contracts.verifier_contracts { - let twitter_verifier_data = call_contract_helper( &state, state.conf.starknetid_contracts.identity_contract, @@ -79,10 +85,10 @@ pub async fn handler( ], ) .await?; - if twitter_verifier_data[0] != felt!("0") { - twitter = true; - } - + if twitter_verifier_data[0] != felt!("0") { + twitter = true; + } + let discord_verifier_data = call_contract_helper( &state, state.conf.starknetid_contracts.identity_contract, @@ -95,18 +101,17 @@ pub async fn handler( ], ) .await?; - if discord_verifier_data[0] != felt!("0") { - discord = true; - } + if discord_verifier_data[0] != felt!("0") { + discord = true; + } } - - if twitter && discord{ + if twitter && discord { match state.upsert_completed_task(query.addr, task_id).await { Ok(_) => Ok((StatusCode::OK, Json(json!({"res": true})))), Err(e) => Err(e.to_string()), } - } else if !twitter{ + } else if !twitter { Err("You have not verified your Twitter account".to_string()) } else { Err("You have not verified your Discord account".to_string()) diff --git a/src/endpoints/quests/starknetid/verify_twitter_fw.rs b/src/endpoints/quests/starknetid/verify_twitter_fw.rs index debaa3e7..8a3b2b34 100644 --- a/src/endpoints/quests/starknetid/verify_twitter_fw.rs +++ b/src/endpoints/quests/starknetid/verify_twitter_fw.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/quests/starknetid/verify_twitter_follow", + crate::endpoints::quests::starknetid::verify_twitter_fw +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/tribe/claimable.rs b/src/endpoints/quests/tribe/claimable.rs index a4ef44a7..fb3d9aef 100644 --- a/src/endpoints/quests/tribe/claimable.rs +++ b/src/endpoints/quests/tribe/claimable.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::{Deserialize, Serialize}; @@ -47,6 +48,12 @@ pub struct ClaimableQuery { } const QUEST_ID: u32 = 4; + +#[route( + get, + "/quests/tribe/claimable", + crate::endpoints::quests::tribe::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/tribe/verify_has_domain.rs b/src/endpoints/quests/tribe/verify_has_domain.rs index b4f7d560..81ed5fc1 100644 --- a/src/endpoints/quests/tribe/verify_has_domain.rs +++ b/src/endpoints/quests/tribe/verify_has_domain.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use mongodb::bson::doc; use serde::Deserialize; use serde_json::json; @@ -24,6 +25,11 @@ pub struct StarknetIdQuery { addr: FieldElement, } +#[route( + get, + "/quests/tribe/verify_has_domain", + crate::endpoints::quests::tribe::verify_has_domain +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/tribe/verify_has_root_domain.rs b/src/endpoints/quests/tribe/verify_has_root_domain.rs index a9030525..3823d986 100644 --- a/src/endpoints/quests/tribe/verify_has_root_domain.rs +++ b/src/endpoints/quests/tribe/verify_has_root_domain.rs @@ -6,8 +6,14 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; +use axum_auto_routes::route; use std::sync::Arc; +#[route( + get, + "/quests/tribe/verify_has_root_domain", + crate::endpoints::quests::tribe::verify_has_root_domain +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/tribe/verify_three_years_expiry.rs b/src/endpoints/quests/tribe/verify_three_years_expiry.rs index c8b91b07..98183799 100644 --- a/src/endpoints/quests/tribe/verify_three_years_expiry.rs +++ b/src/endpoints/quests/tribe/verify_three_years_expiry.rs @@ -13,6 +13,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use mongodb::bson::doc; use serde::Deserialize; use serde_json::json; @@ -27,6 +28,11 @@ pub struct StarknetIdQuery { addr: FieldElement, } +#[route( + get, + "/quests/tribe/verify_three_years_expiry", + crate::endpoints::quests::tribe::verify_three_years_expiry +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/uri.rs b/src/endpoints/quests/uri.rs index 06a469e8..d0f398af 100644 --- a/src/endpoints/quests/uri.rs +++ b/src/endpoints/quests/uri.rs @@ -6,6 +6,7 @@ use axum::{ response::{IntoResponse, Response}, Json, }; +use axum_auto_routes::route; use serde::{Deserialize, Serialize}; use std::sync::Arc; @@ -28,6 +29,7 @@ pub struct LevelQuery { level: Option, } +#[route(get, "/quests/uri", crate::endpoints::quests::uri)] pub async fn handler( State(state): State>, Query(level_query): Query, diff --git a/src/endpoints/quests/verify_quiz.rs b/src/endpoints/quests/verify_quiz.rs index ce77e7fd..19f5d7c5 100644 --- a/src/endpoints/quests/verify_quiz.rs +++ b/src/endpoints/quests/verify_quiz.rs @@ -6,6 +6,7 @@ use crate::{ utils::{get_error, CompletedTasksTrait}, }; use axum::{extract::State, http::StatusCode, response::IntoResponse, Json}; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; @@ -35,6 +36,7 @@ fn get_task_id(quiz_name: &str) -> Option { } } +#[route(post, "/quests/verify_quiz", crate::endpoints::quests::verify_quiz)] pub async fn handler( State(state): State>, body: Json, diff --git a/src/endpoints/quests/zklend/claimable.rs b/src/endpoints/quests/zklend/claimable.rs index 004c5998..ade12f90 100644 --- a/src/endpoints/quests/zklend/claimable.rs +++ b/src/endpoints/quests/zklend/claimable.rs @@ -6,6 +6,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use futures::StreamExt; use mongodb::bson::doc; use serde::Deserialize; @@ -25,6 +26,11 @@ pub struct ClaimableQuery { addr: FieldElement, } +#[route( + get, + "/quests/zklend/claimable", + crate::endpoints::quests::zklend::claimable +)] pub async fn handler( State(state): State>, Query(query): Query, @@ -79,9 +85,11 @@ pub async fn handler( let mut rewards = vec![]; - let Ok((token_id, sig)) = get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await else { + let Ok((token_id, sig)) = + get_nft(QUEST_ID, LAST_TASK, &query.addr, NFT_LEVEL, &signer).await + else { return get_error("Signature failed".into()); - }; + }; rewards.push(Reward { task_id: LAST_TASK, diff --git a/src/endpoints/quests/zklend/verify_borrow.rs b/src/endpoints/quests/zklend/verify_borrow.rs index 33eb4b67..b9d2870d 100644 --- a/src/endpoints/quests/zklend/verify_borrow.rs +++ b/src/endpoints/quests/zklend/verify_borrow.rs @@ -10,6 +10,7 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::{ core::types::{BlockId, BlockTag, FieldElement, FunctionCall}, @@ -17,6 +18,11 @@ use starknet::{ providers::Provider, }; +#[route( + get, + "/quests/zklend/verify_borrow", + crate::endpoints::quests::zklend::verify_borrow +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/endpoints/quests/zklend/verify_twitter_fw.rs b/src/endpoints/quests/zklend/verify_twitter_fw.rs index d1e7eb99..dfd509c5 100644 --- a/src/endpoints/quests/zklend/verify_twitter_fw.rs +++ b/src/endpoints/quests/zklend/verify_twitter_fw.rs @@ -10,9 +10,15 @@ use axum::{ response::IntoResponse, Json, }; +use axum_auto_routes::route; use serde_json::json; use starknet::core::types::FieldElement; +#[route( + get, + "/quests/zklend/verify_twitter_fw", + crate::endpoints::quests::zklend::verify_twitter_fw +)] pub async fn handler( State(state): State>, Query(query): Query, diff --git a/src/main.rs b/src/main.rs index fe9b0e58..47eb03a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,20 +5,22 @@ mod config; mod endpoints; mod models; -use axum::{ - http::StatusCode, - routing::{get, post}, - Router, -}; +use axum::{http::StatusCode, Router}; +use axum_auto_routes::route; use mongodb::{bson::doc, options::ClientOptions, Client}; use reqwest::Url; use starknet::providers::{jsonrpc::HttpTransport, JsonRpcClient}; -use std::net::SocketAddr; use std::sync::Arc; +use std::{net::SocketAddr, sync::Mutex}; +use utils::WithState; use crate::utils::{add_leaderboard_table, run_boosts_raffle}; use tower_http::cors::{Any, CorsLayer}; +lazy_static::lazy_static! { + pub static ref ROUTE_REGISTRY: Mutex>> = Mutex::new(Vec::new()); +} + #[tokio::main] async fn main() { println!("quest_server: starting v{}", env!("CARGO_PKG_VERSION")); @@ -53,536 +55,10 @@ async fn main() { add_leaderboard_table(&shared_state.db).await; let cors = CorsLayer::new().allow_headers(Any).allow_origin(Any); - let app = Router::new() - .route("/", get(root)) - .route("/quests/uri", get(endpoints::quests::uri::handler)) - .route( - "/quests/contract_uri", - get(endpoints::quests::contract_uri::handler), - ) - .route("/get_quiz", get(endpoints::get_quiz::handler)) - .route("/get_quest", get(endpoints::get_quest::handler)) - .route("/get_quests", get(endpoints::get_quests::handler)) - .route( - "/get_completed_quests", - get(endpoints::get_completed_quests::handler), - ) - .route( - "/get_boosted_quests", - get(endpoints::get_boosted_quests::handler), - ) - .route( - "/has_completed_quests", - get(endpoints::has_completed_quest::handler), - ) - .route( - "/get_quest_participants", - get(endpoints::get_quest_participants::handler), - ) - .route( - "/get_trending_quests", - get(endpoints::get_trending_quests::handler), - ) - .route("/get_tasks", get(endpoints::get_tasks::handler)) - .route( - "/get_deployed_time", - get(endpoints::get_deployed_time::handler), - ) - .route( - "/get_quest_category", - get(endpoints::get_quest_category::handler), - ) - .route( - "/quests/verify_quiz", - post(endpoints::quests::verify_quiz::handler), - ) - .route( - "/quests/starknetid/verify_has_domain", - get(endpoints::quests::starknetid::verify_has_domain::handler), - ) - .route( - "/quests/starknetid/verify_twitter_follow", - get(endpoints::quests::starknetid::verify_twitter_fw::handler), - ) - .route( - "/quests/starknetid/verify_has_root_domain", - get(endpoints::quests::starknetid::verify_has_root_domain::handler), - ) - .route( - "/quests/starknetid/verify_socials", - get(endpoints::quests::starknetid::verify_socials::handler), - ) - .route( - "/quests/starknetid/claimable", - get(endpoints::quests::starknetid::claimable::handler), - ) - .route( - "/quests/jediswap/verify_added_liquidity", - get(endpoints::quests::jediswap::verify_added_liquidity::handler), - ) - .route( - "/quests/jediswap/verify_twitter_fw", - get(endpoints::quests::jediswap::verify_twitter_fw::handler), - ) - .route( - "/quests/jediswap/verify_twitter_rt", - get(endpoints::quests::jediswap::verify_twitter_rt::handler), - ) - .route( - "/quests/jediswap/claimable", - get(endpoints::quests::jediswap::claimable::handler), - ) - .route( - "/quests/zklend/verify_borrow", - get(endpoints::quests::zklend::verify_borrow::handler), - ) - .route( - "/quests/zklend/verify_twitter_fw", - get(endpoints::quests::zklend::verify_twitter_fw::handler), - ) - .route( - "/quests/zklend/claimable", - get(endpoints::quests::zklend::claimable::handler), - ) - .route( - "/quests/avnu/discord_fw_callback", - get(endpoints::quests::avnu::discord_fw_callback::handler), - ) - .route( - "/quests/avnu/verify_swap", - get(endpoints::quests::avnu::verify_swap::handler), - ) - .route( - "/quests/avnu/claimable", - get(endpoints::quests::avnu::claimable::handler), - ) - .route( - "/quests/tribe/verify_has_domain", - get(endpoints::quests::tribe::verify_has_domain::handler), - ) - .route( - "/quests/tribe/verify_has_root_domain", - get(endpoints::quests::tribe::verify_has_root_domain::handler), - ) - .route( - "/quests/tribe/verify_three_years_expiry", - get(endpoints::quests::tribe::verify_three_years_expiry::handler), - ) - .route( - "/quests/tribe/claimable", - get(endpoints::quests::tribe::claimable::handler), - ) - .route( - "/quests/sithswap/verify_added_liquidity", - get(endpoints::quests::sithswap::verify_added_liquidity::handler), - ) - .route( - "/quests/sithswap/verify_twitter_fw", - get(endpoints::quests::sithswap::verify_twitter_fw::handler), - ) - .route( - "/quests/sithswap/claimable", - get(endpoints::quests::sithswap::claimable::handler), - ) - .route( - "/quests/orbiter/verify_has_root_domain", - get(endpoints::quests::orbiter::verify_has_root_domain::handler), - ) - .route( - "/quests/orbiter/verify_twitter_fw", - get(endpoints::quests::orbiter::verify_twitter_fw::handler), - ) - .route( - "/quests/orbiter/verify_twitter_fw_sq", - get(endpoints::quests::orbiter::verify_twitter_fw_sq::handler), - ) - .route( - "/quests/orbiter/verify_twitter_rt", - get(endpoints::quests::orbiter::verify_twitter_rt::handler), - ) - .route( - "/quests/orbiter/verify_has_bridged", - get(endpoints::quests::orbiter::verify_has_bridged::handler), - ) - .route( - "/quests/orbiter/claimable", - get(endpoints::quests::orbiter::claimable::handler), - ) - .route( - "/quests/ekubo/claimable", - get(endpoints::quests::ekubo::claimable::handler), - ) - .route( - "/quests/ekubo/discord_fw_callback", - get(endpoints::quests::ekubo::discord_fw_callback::handler), - ) - .route( - "/quests/ekubo/verify_quiz", - post(endpoints::quests::ekubo::verify_quiz::handler), - ) - .route( - "/quests/ekubo/verify_added_liquidity", - get(endpoints::quests::ekubo::verify_added_liquidity::handler), - ) - .route( - "/quests/carmine/claimable", - get(endpoints::quests::carmine::claimable::handler), - ) - .route( - "/quests/morphine/verify_added_liquidity", - get(endpoints::quests::morphine::verify_added_liquidity::handler), - ) - .route( - "/quests/morphine/claimable", - get(endpoints::quests::morphine::claimable::handler), - ) - .route( - "/quests/myswap/verify_added_liquidity", - get(endpoints::quests::myswap::verify_added_liquidity::handler), - ) - .route( - "/quests/myswap/discord_fw_callback", - get(endpoints::quests::myswap::discord_fw_callback::handler), - ) - .route( - "/quests/myswap/claimable", - get(endpoints::quests::myswap::claimable::handler), - ) - .route( - "/quests/starknet/gigabrain/claimable", - get(endpoints::quests::starknet::gigabrain::claimable::handler), - ) - .route( - "/quests/starknet/aa_mastery/claimable", - get(endpoints::quests::starknet::aa_mastery::claimable::handler), - ) - .route( - "/quests/braavos/starknetid/verify_has_domain", - get(endpoints::quests::braavos::starknetid::verify_has_domain::handler), - ) - .route( - "/quests/braavos/starknetid/verify_twitter_fw_braavos", - get(endpoints::quests::braavos::starknetid::verify_twitter_fw_braavos::handler), - ) - .route( - "/quests/braavos/starknetid/verify_twitter_fw_sid", - get(endpoints::quests::braavos::starknetid::verify_twitter_fw_sid::handler), - ) - .route( - "/quests/braavos/starknetid/verify_twitter_fw_sq", - get(endpoints::quests::braavos::starknetid::verify_twitter_fw_sq::handler), - ) - .route( - "/quests/braavos/starknetid/verify_has_mission", - get(endpoints::quests::braavos::starknetid::verify_has_mission::handler), - ) - .route( - "/quests/braavos/starknetid/claimable", - get(endpoints::quests::braavos::starknetid::claimable::handler), - ) - .route( - "/quests/braavos/myswap/claimable", - get(endpoints::quests::braavos::myswap::claimable::handler), - ) - .route( - "/quests/braavos/myswap/verify_has_domain", - get(endpoints::quests::braavos::myswap::verify_has_domain::handler), - ) - .route( - "/quests/braavos/myswap/verify_added_liquidity", - get(endpoints::quests::braavos::myswap::verify_added_liquidity::handler), - ) - .route( - "/quests/braavos/myswap/verify_twitter_fw_braavos", - get(endpoints::quests::braavos::myswap::verify_twitter_fw_braavos::handler), - ) - .route( - "/quests/braavos/myswap/verify_twitter_fw_myswap", - get(endpoints::quests::braavos::myswap::verify_twitter_fw_myswap::handler), - ) - .route( - "/quests/braavos/avnu/claimable", - get(endpoints::quests::braavos::avnu::claimable::handler), - ) - .route( - "/quests/braavos/avnu/verify_has_domain", - get(endpoints::quests::braavos::avnu::verify_has_domain::handler), - ) - .route( - "/quests/braavos/avnu/verify_swap", - get(endpoints::quests::braavos::avnu::verify_swap::handler), - ) - .route( - "/quests/braavos/avnu/verify_twitter_fw_avnu", - get(endpoints::quests::braavos::avnu::verify_twitter_fw_avnu::handler), - ) - .route( - "/quests/braavos/avnu/verify_twitter_fw_braavos", - get(endpoints::quests::braavos::avnu::verify_twitter_fw_braavos::handler), - ) - .route( - "/quests/braavos/avnu/verify_twitter_rt", - get(endpoints::quests::braavos::avnu::verify_twitter_rt::handler), - ) - .route( - "/quests/braavos/wallet/claimable", - get(endpoints::quests::braavos::wallet::claimable::handler), - ) - .route( - "/quests/braavos/wallet/verify_has_domain", - get(endpoints::quests::braavos::wallet::verify_has_domain::handler), - ) - .route( - "/quests/braavos/wallet/verify_twitter_fw_braavos", - get(endpoints::quests::braavos::wallet::verify_twitter_fw_braavos::handler), - ) - .route( - "/quests/braavos/wallet/verify_twitter_rt", - get(endpoints::quests::braavos::wallet::verify_twitter_rt::handler), - ) - .route( - "/quests/braavos/pyramid/verify_has_domain", - get(endpoints::quests::braavos::pyramid::verify_has_domain::handler), - ) - .route( - "/quests/braavos/pyramid/verify_twitter_fw_pyramid", - get(endpoints::quests::braavos::pyramid::verify_twitter_fw_pyramid::handler), - ) - .route( - "/quests/braavos/pyramid/verify_twitter_fw_braavos", - get(endpoints::quests::braavos::pyramid::verify_twitter_fw_braavos::handler), - ) - .route( - "/quests/braavos/pyramid/verify_buy_or_list", - get(endpoints::quests::braavos::pyramid::verify_buy_or_list::handler), - ) - .route( - "/quests/braavos/pyramid/verify_twitter_rt", - get(endpoints::quests::braavos::pyramid::verify_twitter_rt::handler), - ) - .route( - "/quests/braavos/pyramid/claimable", - get(endpoints::quests::braavos::pyramid::claimable::handler), - ) - .route( - "/quests/braavos/zklend/verify_has_domain", - get(endpoints::quests::braavos::zklend::verify_has_domain::handler), - ) - .route( - "/quests/braavos/zklend/verify_twitter_fw_zklend", - get(endpoints::quests::braavos::zklend::verify_twitter_fw_zklend::handler), - ) - .route( - "/quests/braavos/zklend/verify_twitter_fw_braavos", - get(endpoints::quests::braavos::zklend::verify_twitter_fw_braavos::handler), - ) - .route( - "/quests/braavos/zklend/verify_added_liquidity", - get(endpoints::quests::braavos::zklend::verify_added_liquidity::handler), - ) - .route( - "/quests/braavos/zklend/verify_twitter_rt", - get(endpoints::quests::braavos::zklend::verify_twitter_rt::handler), - ) - .route( - "/quests/braavos/zklend/claimable", - get(endpoints::quests::braavos::zklend::claimable::handler), - ) - .route( - "/quests/focustree/verify_twitter_fw", - get(endpoints::quests::focustree::introduction::verify_twitter_fw::handler), - ) - .route( - "/quests/focustree/verify_twitter_rt", - get(endpoints::quests::focustree::introduction::verify_twitter_rt::handler), - ) - .route( - "/quests/focustree/claimable", - get(endpoints::quests::focustree::introduction::claimable::handler), - ) - .route( - "/quests/focustree/discord_fw_callback", - get(endpoints::quests::focustree::engagement::discord_fw_callback::handler), - ) - .route( - "/quests/focustree/verify_twitter_rw_user", - get(endpoints::quests::focustree::engagement::verify_twitter_rt::handler), - ) - .route( - "/quests/element/element/verify_is_eligible", - get(endpoints::quests::element::element::verify_is_eligible::handler), - ) - .route( - "/quests/element/element/verify_twitter_fw", - get(endpoints::quests::element::element::verify_twitter_fw::handler), - ) - .route( - "/quests/element/element/claimable", - get(endpoints::quests::element::element::claimable::handler), - ) - .route( - "/quests/element/briq/verify_own_briq", - get(endpoints::quests::element::briq::verify_own_briq::handler), - ) - .route( - "/quests/element/briq/verify_twitter_fw", - get(endpoints::quests::element::briq::verify_twitter_fw::handler), - ) - .route( - "/quests/element/briq/claimable", - get(endpoints::quests::element::briq::claimable::handler), - ) - .route( - "/quests/element/layerswap/verify_has_bridged", - get(endpoints::quests::element::layerswap::verify_has_bridged::handler), - ) - .route( - "/quests/element/layerswap/verify_twitter_fw", - get(endpoints::quests::element::layerswap::verify_twitter_fw::handler), - ) - .route( - "/quests/element/layerswap/verify_twitter_rt", - get(endpoints::quests::element::layerswap::verify_twitter_rt::handler), - ) - .route( - "/quests/element/layerswap/claimable", - get(endpoints::quests::element::layerswap::claimable::handler), - ) - .route( - "/quests/element/starknetid/verify_has_root_domain", - get(endpoints::quests::element::starknetid::verify_has_root_domain::handler), - ) - .route( - "/quests/element/starknetid/claimable", - get(endpoints::quests::element::starknetid::claimable::handler), - ) - .route( - "/quests/nostra/claimable", - get(endpoints::quests::nostra::claimable::handler), - ) - .route( - "/quests/nostra/discord_fw_callback", - get(endpoints::quests::nostra::discord_fw_callback::handler), - ) - .route( - "/quests/nostra/verify_added_liquidity", - get(endpoints::quests::nostra::verify_added_liquidity::handler), - ) - .route( - "/quests/rhino/check_bridge", - get(endpoints::quests::rhino::check_bridge::handler), - ) - .route( - "/quests/rhino/verify_twitter_fw", - get(endpoints::quests::rhino::verify_twitter_fw::handler), - ) - .route( - "/quests/rhino/verify_twitter_rw", - get(endpoints::quests::rhino::verify_twitter_rw::handler), - ) - .route( - "/quests/rhino/claimable", - get(endpoints::quests::rhino::claimable::handler), - ) - .route( - "/quests/rango/verify_twitter_fw", - get(endpoints::quests::rango::verify_twitter_fw::handler), - ) - .route( - "/quests/rango/discord_fw_callback", - get(endpoints::quests::rango::discord_fw_callback::handler), - ) - .route( - "/quests/rango/check_trade", - get(endpoints::quests::rango::check_trade::handler), - ) - .route( - "/quests/rango/claimable", - get(endpoints::quests::rango::claimable::handler), - ) - .route( - "/achievements/verify_default", - get(endpoints::achievements::verify_default::handler), - ) - .route( - "/achievements/verify_briq", - get(endpoints::achievements::verify_briq::handler), - ) - .route( - "/achievements/verify_tvl", - get(endpoints::achievements::verify_tvl::handler), - ) - .route( - "/achievements/batched/verify_tvl_batched", - get(endpoints::achievements::batched::verify_tvl_batched::handler), - ) - .route( - "/achievements/verify_seniority", - get(endpoints::achievements::verify_seniority::handler), - ) - .route( - "/achievements/verify_avnu", - get(endpoints::achievements::verify_avnu::handler), - ) - .route( - "/achievements/verify_has_domain", - get(endpoints::achievements::verify_has_domain::handler), - ) - .route( - "/achievements/verify_achieved_quests", - get(endpoints::achievements::verify_achieved_quests::handler), - ) - .route( - "/achievements/fetch", - get(endpoints::achievements::fetch::handler), - ) - .route( - "/achievements/fetch_buildings", - get(endpoints::achievements::fetch_buildings::handler), - ) - .route( - "/achievements/verify_quests", - get(endpoints::achievements::verify_quests::handler), - ) - .route( - "/achievements/claim/quest_achievement", - get(endpoints::achievements::claim::quests_achievement::handler), - ) - .route( - "/leaderboard/get_static_info", - get(endpoints::leaderboard::get_static_info::handler), - ) - .route( - "/leaderboard/get_ranking", - get(endpoints::leaderboard::get_ranking::handler), - ) - .route( - "/boost/get_claim_params", - get(endpoints::quest_boost::get_claim_params::handler), - ) - .route( - "/boost/get_boosts", - get(endpoints::quest_boost::get_boosts::handler), - ) - .route( - "/boost/get_completed_boosts", - get(endpoints::quest_boost::get_completed_boosts::handler), - ) - .route( - "/boost/get_quests", - get(endpoints::quest_boost::get_quests::handler), - ) - .route( - "/boost/get_boost", - get(endpoints::quest_boost::get_boost::handler), - ) - .route( - "/boost/get_pending_claims", - get(endpoints::quest_boost::get_pending_claims::handler), - ) - .with_state(shared_state) - .layer(cors); - + let app = ROUTE_REGISTRY.lock().unwrap().clone().into_iter().fold( + Router::new().with_state(shared_state.clone()).layer(cors), + |acc, r| acc.merge(r.to_router(shared_state.clone())), + ); let addr = SocketAddr::from(([0, 0, 0, 0], conf.server.port)); println!("server: listening on http://0.0.0.0:{}", conf.server.port); axum::Server::bind(&addr) @@ -591,6 +67,7 @@ async fn main() { .unwrap(); } +#[route(get, "/")] async fn root() -> (StatusCode, String) { ( StatusCode::ACCEPTED, diff --git a/src/utils.rs b/src/utils.rs index 8a4e4cf2..059cea95 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -6,6 +6,7 @@ use axum::{ body::Body, http::{Response as HttpResponse, StatusCode, Uri}, response::{IntoResponse, Response}, + Router, }; use chrono::{Duration as dur, Utc}; use futures::TryStreamExt; @@ -22,9 +23,9 @@ use starknet::{ }, signers::LocalWallet, }; -use std::fmt::Write; use std::result::Result; use std::str::FromStr; +use std::{fmt::Write, sync::Arc}; use tokio::time::{sleep, Duration}; #[macro_export] @@ -239,7 +240,7 @@ impl CompletedTasksTrait for AppState { experience.into(), timestamp, ) - .await; + .await; } Err(_e) => { get_error("Error querying quests".to_string()); @@ -328,7 +329,7 @@ impl AchievementsTrait for AppState { experience.into(), timestamp, ) - .await; + .await; } None => {} } @@ -653,7 +654,9 @@ pub async fn fetch_and_update_boosts_winner( current_winner_index += 1; } iter_index += 1; - if current_winner_index == (num_of_winners) as usize || iter_index == address_list.len() { + if current_winner_index == (num_of_winners) as usize + || iter_index == address_list.len() + { break; } } @@ -689,3 +692,26 @@ pub fn run_boosts_raffle(db: &Database, interval: u64) { interval, )); } + +// required for axum_auto_routes +pub trait WithState: Send { + fn to_router(self: Box, shared_state: Arc) -> Router; + + fn box_clone(&self) -> Box; +} + +impl WithState for Router, Body> { + fn to_router(self: Box, shared_state: Arc) -> Router { + self.with_state(shared_state) + } + + fn box_clone(&self) -> Box { + Box::new((*self).clone()) + } +} + +impl Clone for Box { + fn clone(&self) -> Box { + self.box_clone() + } +}