From ceca3fda9c04b0f538d4011f0b02e53a7797d9e3 Mon Sep 17 00:00:00 2001 From: ayushtom Date: Mon, 4 Dec 2023 04:16:46 +0530 Subject: [PATCH 01/10] feat: add rango quest --- src/endpoints/quests/mod.rs | 1 + src/endpoints/quests/rango/mod.rs | 1 + .../quests/rango/verify_twitter_fw.rs | 24 +++++++++++++++++++ src/endpoints/quests/verify_quiz.rs | 1 + src/main.rs | 4 ++++ 5 files changed, 31 insertions(+) create mode 100644 src/endpoints/quests/rango/mod.rs create mode 100644 src/endpoints/quests/rango/verify_twitter_fw.rs diff --git a/src/endpoints/quests/mod.rs b/src/endpoints/quests/mod.rs index 658df1f7..a967ebbd 100644 --- a/src/endpoints/quests/mod.rs +++ b/src/endpoints/quests/mod.rs @@ -17,3 +17,4 @@ pub mod tribe; pub mod uri; pub mod verify_quiz; pub mod zklend; +pub mod rango; \ No newline at end of file diff --git a/src/endpoints/quests/rango/mod.rs b/src/endpoints/quests/rango/mod.rs new file mode 100644 index 00000000..9b36ce87 --- /dev/null +++ b/src/endpoints/quests/rango/mod.rs @@ -0,0 +1 @@ +pub mod verify_twitter_fw; \ No newline at end of file diff --git a/src/endpoints/quests/rango/verify_twitter_fw.rs b/src/endpoints/quests/rango/verify_twitter_fw.rs new file mode 100644 index 00000000..abeea52f --- /dev/null +++ b/src/endpoints/quests/rango/verify_twitter_fw.rs @@ -0,0 +1,24 @@ +use std::sync::Arc; + +use crate::{ + models::{AppState, VerifyQuery}, + utils::{get_error, CompletedTasksTrait}, +}; +use axum::{ + extract::{Query, State}, + http::StatusCode, + response::IntoResponse, + Json, +}; +use serde_json::json; + +pub async fn handler( + State(state): State>, + Query(query): Query, +) -> impl IntoResponse { + let task_id = 93; + 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)), + } +} diff --git a/src/endpoints/quests/verify_quiz.rs b/src/endpoints/quests/verify_quiz.rs index 59ccfbe4..484f1b73 100644 --- a/src/endpoints/quests/verify_quiz.rs +++ b/src/endpoints/quests/verify_quiz.rs @@ -28,6 +28,7 @@ fn get_task_id(quiz_name: &str) -> Option { "briq" => Some(67), "element_starknetid" => Some(73), "nostra" => Some(79), + "rango" => Some(23), _ => None, } } diff --git a/src/main.rs b/src/main.rs index a4ae6e2f..54c54b3b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -400,6 +400,10 @@ async fn main() { "/quests/nostra/verify_added_liquidity", get(endpoints::quests::nostra::verify_added_liquidity::handler), ) + .route( + "/quests/rango/verify_twitter_fw", + get(endpoints::quests::rango::verify_twitter_fw::handler), + ) .route( "/achievements/verify_default", get(endpoints::achievements::verify_default::handler), From cea0b47aa25ebc0e9d2dca773e509d5aafb8927f Mon Sep 17 00:00:00 2001 From: ayushtom Date: Mon, 4 Dec 2023 04:23:32 +0530 Subject: [PATCH 02/10] feat: add discord task --- .../quests/rango/discord_fw_callback.rs | 145 ++++++++++++++++++ src/endpoints/quests/rango/mod.rs | 3 +- src/main.rs | 4 + 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 src/endpoints/quests/rango/discord_fw_callback.rs diff --git a/src/endpoints/quests/rango/discord_fw_callback.rs b/src/endpoints/quests/rango/discord_fw_callback.rs new file mode 100644 index 00000000..4c79fccb --- /dev/null +++ b/src/endpoints/quests/rango/discord_fw_callback.rs @@ -0,0 +1,145 @@ +use std::sync::Arc; + +use crate::utils::CompletedTasksTrait; +use crate::{ + models::AppState, + utils::{get_error_redirect, success_redirect}, +}; +use axum::{ + extract::{Query, State}, + response::IntoResponse, +}; +use mongodb::bson::doc; +use reqwest::header::AUTHORIZATION; +use serde::Deserialize; +use starknet::core::types::FieldElement; + +#[derive(Deserialize)] +pub struct TwitterOAuthCallbackQuery { + code: String, + state: FieldElement, +} + +#[derive(Deserialize)] +pub struct Guild { + id: String, + #[allow(dead_code)] + name: String, +} + +pub async fn handler( + State(state): State>, + Query(query): Query, +) -> impl IntoResponse { + let quest_id = 23; + let task_id = 94; + let guild_id = "1079299393712300112"; + let authorization_code = &query.code; + let error_redirect_uri = format!( + "{}/quest/{}?task_id={}&res=false", + state.conf.variables.app_link, quest_id, task_id + ); + + // Exchange the authorization code for an access token + let params = [ + ("client_id", &state.conf.discord.oauth2_clientid), + ("client_secret", &state.conf.discord.oauth2_secret), + ("code", &authorization_code.to_string()), + ( + "redirect_uri", + &format!( + "{}/quests/rango/discord_fw_callback", + state.conf.variables.api_link + ), + ), + ("grant_type", &"authorization_code".to_string()), + ]; + let access_token = match exchange_authorization_code(params).await { + Ok(token) => token, + Err(e) => { + return get_error_redirect( + error_redirect_uri, + format!("Failed to exchange authorization code: {}", e), + ); + } + }; + + // Get user guild information + let client = reqwest::Client::new(); + let response_result = client + .get("https://discord.com/api/users/@me/guilds") + .header(AUTHORIZATION, format!("Bearer {}", access_token)) + .send() + .await; + let response: Vec = match response_result { + Ok(response) => { + let json_result = response.json().await; + match json_result { + Ok(json) => json, + Err(e) => { + return get_error_redirect( + error_redirect_uri, + format!( + "Failed to get JSON response while fetching user info: {}", + e + ), + ); + } + } + } + Err(e) => { + return get_error_redirect( + error_redirect_uri, + format!("Failed to send request to get user info: {}", e), + ); + } + }; + + for guild in response { + if guild.id == guild_id { + match state.upsert_completed_task(query.state, task_id).await { + Ok(_) => { + let redirect_uri = format!( + "{}/quest/{}?task_id={}&res=true", + state.conf.variables.app_link, quest_id, task_id + ); + return success_redirect(redirect_uri); + } + Err(e) => return get_error_redirect(error_redirect_uri, format!("{}", e)), + } + } + } + + get_error_redirect( + error_redirect_uri, + "You're not part of Rango's Discord server".to_string(), + ) +} + +async fn exchange_authorization_code( + params: [(&str, &String); 5], +) -> Result> { + let client = reqwest::Client::new(); + let res = client + .post("https://discord.com/api/oauth2/token") + .form(¶ms) + .send() + .await?; + let json: serde_json::Value = res.json().await?; + match json["access_token"].as_str() { + Some(s) => Ok(s.to_string()), + None => { + println!( + "Failed to get 'access_token' from JSON response : {:?}", + json + ); + Err(Box::new(std::io::Error::new( + std::io::ErrorKind::Other, + format!( + "Failed to get 'access_token' from JSON response : {:?}", + json + ), + ))) + } + } +} diff --git a/src/endpoints/quests/rango/mod.rs b/src/endpoints/quests/rango/mod.rs index 9b36ce87..29acb643 100644 --- a/src/endpoints/quests/rango/mod.rs +++ b/src/endpoints/quests/rango/mod.rs @@ -1 +1,2 @@ -pub mod verify_twitter_fw; \ No newline at end of file +pub mod verify_twitter_fw; +pub mod discord_fw_callback; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 54c54b3b..2ab1719d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -404,6 +404,10 @@ async fn main() { "/quests/rango/verify_twitter_fw", get(endpoints::quests::rango::verify_twitter_fw::handler), ) + .route( + "/quests/rango/discord_fw_callback", + get(endpoints::quests::rango::verify_twitter_fw::handler), + ) .route( "/achievements/verify_default", get(endpoints::achievements::verify_default::handler), From e96016ba381a83e7e44eeb6af342114c879a0f9a Mon Sep 17 00:00:00 2001 From: ayushtom Date: Tue, 5 Dec 2023 00:10:24 +0530 Subject: [PATCH 03/10] feat: add rango --- src/config.rs | 6 ++ src/endpoints/quest_boost/get_claim_params.rs | 8 ++- src/endpoints/quests/rango/check_trade.rs | 60 +++++++++++++++++++ src/endpoints/quests/rango/mod.rs | 3 +- src/main.rs | 6 +- 5 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 src/endpoints/quests/rango/check_trade.rs diff --git a/src/config.rs b/src/config.rs index 953fb3ee..5bfc9e73 100644 --- a/src/config.rs +++ b/src/config.rs @@ -122,6 +122,11 @@ pub_struct!(Clone, Deserialize; Starkscan { api_key: String, }); +pub_struct!(Clone, Deserialize; Api { + api_endpoint: String, + api_key: String, +}); + pub_struct!(Clone, Deserialize; Achievement { contract: FieldElement, }); @@ -145,6 +150,7 @@ pub_struct!(Clone, Deserialize; Config { starkscan: Starkscan, achievements: Achievements, quest_boost: QuestBoost, + rango: Api, }); pub fn load() -> Config { diff --git a/src/endpoints/quest_boost/get_claim_params.rs b/src/endpoints/quest_boost/get_claim_params.rs index 8803439c..10173d57 100644 --- a/src/endpoints/quest_boost/get_claim_params.rs +++ b/src/endpoints/quest_boost/get_claim_params.rs @@ -17,6 +17,7 @@ use std::sync::Arc; #[derive(Debug, Serialize, Deserialize)] pub struct GetClaimBoostQuery { boost_id: u32, + addr: FieldElement, } pub async fn handler( @@ -24,6 +25,7 @@ pub async fn handler( Query(query): Query, ) -> impl IntoResponse { let boost_id = query.boost_id; + let addr=query.addr; let collection = state.db.collection::("boosts"); let res=collection.find_one(doc! {"id":boost_id},None).await.unwrap(); @@ -35,7 +37,7 @@ pub async fn handler( let boost: Document = res.unwrap(); let amount = boost.get("amount").unwrap().as_i32().unwrap() as u32; let token = boost.get("token").unwrap().as_str().unwrap(); - let address = boost.get("winner").unwrap().as_str().unwrap(); + // let address = boost.get("winner").unwrap().as_str().unwrap(); let hashed = pedersen_hash( &FieldElement::from(boost_id), @@ -45,7 +47,7 @@ pub async fn handler( &FieldElement::from(0 as u32), &pedersen_hash( &FieldElement::from_str(token).unwrap(), - &FieldElement::from_str(address).unwrap(), + &addr, ), ), ), @@ -54,7 +56,7 @@ pub async fn handler( match ecdsa_sign(&state.conf.quest_boost.private_key, &hashed) { Ok(signature) => ( StatusCode::OK, - Json(json!({"address": address, "r": signature.r, "s": signature.s})), + Json(json!({"address": addr, "r": signature.r, "s": signature.s})), ) .into_response(), Err(e) => get_error(format!("Error while generating signature: {}", e)), diff --git a/src/endpoints/quests/rango/check_trade.rs b/src/endpoints/quests/rango/check_trade.rs new file mode 100644 index 00000000..50e6b07e --- /dev/null +++ b/src/endpoints/quests/rango/check_trade.rs @@ -0,0 +1,60 @@ +use std::sync::Arc; + +use crate::models::EmailQuery; +use crate::utils::{CompletedTasksTrait}; +use crate::{models::AppState, utils::get_error}; +use axum::{ + extract::{Query, State}, + http::StatusCode, + response::IntoResponse, + Json, +}; +use serde_json::json; + +pub async fn handler( + State(state): State>, + Query(query): Query, +) -> impl IntoResponse { + let task_id = 92; + + let res = make_rango_request(&state.conf.rango.api_endpoint, &state.conf.rango.api_key).await; + let response = match res { + Ok(response) => response, + Err(e) => return get_error(format!("{}", e)), + }; + + if let Some(data_response) = response.get("data") { + if let Some(result) = response.get("result") { + if result.as_bool().unwrap() { + return 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)), + }; + } else { + get_error("User has not completed the task".to_string()) + } + } else { + get_error("User has not completed the task".to_string()) + } + } else { + get_error("User has not completed the task".to_string()) + } +} + +async fn make_rango_request(endpoint: &str, apiKey: &str) -> Result { + let client = reqwest::Client::new(); + match client.get(endpoint).header("apiKey", apiKey).send().await { + Ok(response) => match response.json::().await { + Ok(json) => { + if let Some(res) = json.get("res") { + if res.as_bool().unwrap() { + return Ok(json!({"res": true})); + } + } + Err(format!("Failed to get JSON response: {}", json)) + } + Err(e) => Err(format!("Failed to get JSON response: {}", e)), + }, + Err(e) => Err(format!("Failed to send request: {}", e)), + } +} diff --git a/src/endpoints/quests/rango/mod.rs b/src/endpoints/quests/rango/mod.rs index 29acb643..cf747de5 100644 --- a/src/endpoints/quests/rango/mod.rs +++ b/src/endpoints/quests/rango/mod.rs @@ -1,2 +1,3 @@ pub mod verify_twitter_fw; -pub mod discord_fw_callback; \ No newline at end of file +pub mod discord_fw_callback; +pub mod check_trade; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 2ab1719d..c5c19832 100644 --- a/src/main.rs +++ b/src/main.rs @@ -406,7 +406,11 @@ async fn main() { ) .route( "/quests/rango/discord_fw_callback", - get(endpoints::quests::rango::verify_twitter_fw::handler), + get(endpoints::quests::rango::discord_fw_callback::handler), + ) + .route( + "/quests/rango/check_trade", + get(endpoints::quests::rango::check_trade::handler), ) .route( "/achievements/verify_default", From 083508ec08aaf7e39cfa1db0e295d356a38eca56 Mon Sep 17 00:00:00 2001 From: ayushtom Date: Tue, 5 Dec 2023 09:57:26 +0530 Subject: [PATCH 04/10] feat: add rango exchange nft --- src/endpoints/quests/rango/claimable.rs | 101 ++++++++++++++++++++++++ src/endpoints/quests/rango/mod.rs | 3 +- src/endpoints/quests/uri.rs | 10 +++ src/main.rs | 4 + 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 src/endpoints/quests/rango/claimable.rs diff --git a/src/endpoints/quests/rango/claimable.rs b/src/endpoints/quests/rango/claimable.rs new file mode 100644 index 00000000..9913a78b --- /dev/null +++ b/src/endpoints/quests/rango/claimable.rs @@ -0,0 +1,101 @@ +use crate::models::{AppState, CompletedTaskDocument, Reward, RewardResponse}; +use crate::utils::{get_error, get_nft}; +use axum::{ + extract::{Query, State}, + http::StatusCode, + response::IntoResponse, + Json, +}; +use futures::StreamExt; +use mongodb::bson::doc; +use serde::Deserialize; +use starknet::{ + core::types::FieldElement, + signers::{LocalWallet, SigningKey}, +}; +use std::sync::Arc; + +const QUEST_ID: u32 = 23; +const TASK_IDS: &[u32] = &[92, 93, 94, 95]; +const LAST_TASK: u32 = TASK_IDS[3]; +const NFT_LEVEL: u32 = 30; + +#[derive(Deserialize)] +pub struct ClaimableQuery { + addr: FieldElement, +} + +pub async fn handler( + State(state): State>, + Query(query): Query, +) -> impl IntoResponse { + let collection = state + .db + .collection::("completed_tasks"); + + let pipeline = vec![ + doc! { + "$match": { + "address": &query.addr.to_string(), + "task_id": { "$in": TASK_IDS }, + }, + }, + doc! { + "$lookup": { + "from": "tasks", + "localField": "task_id", + "foreignField": "id", + "as": "task", + }, + }, + doc! { + "$match": { + "task.quest_id": QUEST_ID, + }, + }, + doc! { + "$group": { + "_id": "$address", + "completed_tasks": { "$push": "$task_id" }, + }, + }, + doc! { + "$match": { + "completed_tasks": { "$all": TASK_IDS }, + }, + }, + ]; + + let completed_tasks = collection.aggregate(pipeline, None).await; + match completed_tasks { + Ok(mut tasks_cursor) => { + if tasks_cursor.next().await.is_none() { + return get_error("User hasn't completed all tasks".into()); + } + + let signer = LocalWallet::from(SigningKey::from_secret_scalar( + state.conf.nft_contract.private_key, + )); + + let mut rewards = vec![]; + + 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, + nft_contract: state.conf.nft_contract.address.clone(), + token_id: token_id.to_string(), + sig: (sig.r, sig.s), + }); + + if rewards.is_empty() { + get_error("No rewards found for this user".into()) + } else { + (StatusCode::OK, Json(RewardResponse { rewards })).into_response() + } + } + Err(_) => get_error("Error querying rewards".into()), + } +} \ No newline at end of file diff --git a/src/endpoints/quests/rango/mod.rs b/src/endpoints/quests/rango/mod.rs index cf747de5..7f8deb1d 100644 --- a/src/endpoints/quests/rango/mod.rs +++ b/src/endpoints/quests/rango/mod.rs @@ -1,3 +1,4 @@ pub mod verify_twitter_fw; pub mod discord_fw_callback; -pub mod check_trade; \ No newline at end of file +pub mod check_trade; +pub mod claimable; \ No newline at end of file diff --git a/src/endpoints/quests/uri.rs b/src/endpoints/quests/uri.rs index 0a8df258..8145a763 100644 --- a/src/endpoints/quests/uri.rs +++ b/src/endpoints/quests/uri.rs @@ -329,6 +329,16 @@ pub async fn handler( }), ) .into_response(), + + Some(30) => ( + StatusCode::OK, + Json(TokenURI { + name: "Rango Exchange Quest NFT".into(), + description: "A Rango Exchange Quest NFT won for successfully finishing the Quest".into(), + image: format!("{}/rango/bridge.webp", state.conf.variables.app_link), + attributes: None, + }), + ).into_response(), _ => get_error("Error, this level is not correct".into()), } diff --git a/src/main.rs b/src/main.rs index c5c19832..3f1edc5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -412,6 +412,10 @@ async fn main() { "/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), From 8d857a9a72be1a0686fb6038f5b27e77b3d6e690 Mon Sep 17 00:00:00 2001 From: ayushtom Date: Tue, 5 Dec 2023 10:31:27 +0530 Subject: [PATCH 05/10] feat: add quiz template --- config.template.toml | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/config.template.toml b/config.template.toml index 230b8dc1..99229ea5 100644 --- a/config.template.toml +++ b/config.template.toml @@ -845,6 +845,7 @@ options = [ ] correct_answers = [*] +<<<<<<< Updated upstream [quizzes.braavos] name = "Starknet Pro Score Quiz" desc = "Challenge your knowledge about your Starknet Pro Score with this quiz for and learn how to reach 100%!" @@ -895,5 +896,47 @@ options = [ "Reading online forums about cryptocurrency.", "Following Starknet on social media.", "Attending a cryptocurrency seminar." +======= + + +[quizzes.rango] +name = "Rango Quiz" +desc = "Take part in our Quiz to test your knowledge about Rango, and you'll have a chance to win an exclusive Rango Castle Bridge NFT as your reward." +intro = "Starknet Quest Quiz Rounds, a quiz series designed to make Starknet ecosystem knowledge accessible and enjoyable for all. Test your understanding of the workings of Rango, enjoy the experience, and earn an exclusive NFT reward by testing your knowledge about Starknet Ecosystem projects!" + +[[quizzes.rango.questions]] +kind = "text_choice" +layout = "default" +question = "What does Rango specialize in?" +options = [ + "Decentralized applications ", + "Cross-chain swaps and aggregating bridges and DEXs", + "58  blockchains", + "Only the Lightning network " +] +correct_answers = [*] + +[[quizzes.rango.questions]] +kind = "text_choice" +layout = "default" +question = "How many connections does Rango support in Web3?" +options = [ + "20 Cosmos Appchains and 50 CEXes", + "100 blockchains and 10 DEXes.", + "Capital inefficiency and poor price discovery in AMMs", + "Lack of social media engagement " +] +correct_answers = [*] + +[[quizzes.rango.questions]] +kind = "text_choice" +layout = "default" +question = "What makes Rango Multichain?" +options = [ + "It only supports one type of EVM blockchain.", + "Rango is a sidechain on Starknet.", + "Rango integrates multiple types of blockchains, including EVM-based, Cosmos, Solana, and many more.", + "Rango focuses exclusively on a zkEVM blockchain type" +>>>>>>> Stashed changes ] correct_answers = [*] \ No newline at end of file From 834cb689eec44ae84b81890819814bca33dc578c Mon Sep 17 00:00:00 2001 From: ayushtom Date: Tue, 5 Dec 2023 10:32:58 +0530 Subject: [PATCH 06/10] chore: remove merge brackets --- config.template.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/config.template.toml b/config.template.toml index 99229ea5..e6865915 100644 --- a/config.template.toml +++ b/config.template.toml @@ -845,7 +845,6 @@ options = [ ] correct_answers = [*] -<<<<<<< Updated upstream [quizzes.braavos] name = "Starknet Pro Score Quiz" desc = "Challenge your knowledge about your Starknet Pro Score with this quiz for and learn how to reach 100%!" @@ -896,8 +895,7 @@ options = [ "Reading online forums about cryptocurrency.", "Following Starknet on social media.", "Attending a cryptocurrency seminar." -======= - +] [quizzes.rango] name = "Rango Quiz" From 189f0a9bdd1696334ba36f1f83572e911bd76044 Mon Sep 17 00:00:00 2001 From: ayushtom Date: Tue, 5 Dec 2023 10:35:18 +0530 Subject: [PATCH 07/10] feat: change nft name --- src/endpoints/quests/uri.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/endpoints/quests/uri.rs b/src/endpoints/quests/uri.rs index ff76f23a..c62b05d5 100644 --- a/src/endpoints/quests/uri.rs +++ b/src/endpoints/quests/uri.rs @@ -345,7 +345,7 @@ pub async fn handler( Some(30) => ( StatusCode::OK, Json(TokenURI { - name: "Rango Exchange Quest NFT".into(), + name: "Rango Exchange Castle Bridge NFT".into(), description: "A Rango Exchange Quest NFT won for successfully finishing the Quest".into(), image: format!("{}/rango/bridge.webp", state.conf.variables.app_link), attributes: None, From fffaed8b79fb5b5ec9718277169c25464809a175 Mon Sep 17 00:00:00 2001 From: ayushtom Date: Wed, 6 Dec 2023 20:41:44 +0530 Subject: [PATCH 08/10] chore: rmeove unnec changes --- config.template.toml | 1 - src/endpoints/quest_boost/get_claim_params.rs | 10 ++++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/config.template.toml b/config.template.toml index e6865915..9855f098 100644 --- a/config.template.toml +++ b/config.template.toml @@ -935,6 +935,5 @@ options = [ "Rango is a sidechain on Starknet.", "Rango integrates multiple types of blockchains, including EVM-based, Cosmos, Solana, and many more.", "Rango focuses exclusively on a zkEVM blockchain type" ->>>>>>> Stashed changes ] correct_answers = [*] \ No newline at end of file diff --git a/src/endpoints/quest_boost/get_claim_params.rs b/src/endpoints/quest_boost/get_claim_params.rs index 10173d57..037d18c3 100644 --- a/src/endpoints/quest_boost/get_claim_params.rs +++ b/src/endpoints/quest_boost/get_claim_params.rs @@ -17,7 +17,6 @@ use std::sync::Arc; #[derive(Debug, Serialize, Deserialize)] pub struct GetClaimBoostQuery { boost_id: u32, - addr: FieldElement, } pub async fn handler( @@ -25,7 +24,6 @@ pub async fn handler( Query(query): Query, ) -> impl IntoResponse { let boost_id = query.boost_id; - let addr=query.addr; let collection = state.db.collection::("boosts"); let res=collection.find_one(doc! {"id":boost_id},None).await.unwrap(); @@ -37,7 +35,7 @@ pub async fn handler( let boost: Document = res.unwrap(); let amount = boost.get("amount").unwrap().as_i32().unwrap() as u32; let token = boost.get("token").unwrap().as_str().unwrap(); - // let address = boost.get("winner").unwrap().as_str().unwrap(); + let address = boost.get("winner").unwrap().as_str().unwrap(); let hashed = pedersen_hash( &FieldElement::from(boost_id), @@ -47,7 +45,7 @@ pub async fn handler( &FieldElement::from(0 as u32), &pedersen_hash( &FieldElement::from_str(token).unwrap(), - &addr, + &FieldElement::from_str(address).unwrap(), ), ), ), @@ -56,9 +54,9 @@ pub async fn handler( match ecdsa_sign(&state.conf.quest_boost.private_key, &hashed) { Ok(signature) => ( StatusCode::OK, - Json(json!({"address": addr, "r": signature.r, "s": signature.s})), + Json(json!({"address": address, "r": signature.r, "s": signature.s})), ) .into_response(), Err(e) => get_error(format!("Error while generating signature: {}", e)), } -} +} \ No newline at end of file From 6e20b6b25e11bf9a5425036afdb05a07e083b26f Mon Sep 17 00:00:00 2001 From: ayushtom Date: Mon, 11 Dec 2023 21:07:08 +0530 Subject: [PATCH 09/10] chore: resolve pr comments --- src/endpoints/quests/rango/check_trade.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/endpoints/quests/rango/check_trade.rs b/src/endpoints/quests/rango/check_trade.rs index 50e6b07e..5d1e314b 100644 --- a/src/endpoints/quests/rango/check_trade.rs +++ b/src/endpoints/quests/rango/check_trade.rs @@ -30,15 +30,10 @@ pub async fn handler( Ok(_) => (StatusCode::OK, Json(json!({"res": true}))).into_response(), Err(e) => get_error(format!("{}", e)), }; - } else { - get_error("User has not completed the task".to_string()) } - } else { - get_error("User has not completed the task".to_string()) } - } else { - get_error("User has not completed the task".to_string()) } + get_error("User has not completed the task".to_string()) } async fn make_rango_request(endpoint: &str, apiKey: &str) -> Result { From 113bcc85ad727a67e58d9e5972c2aeedc81cdeb4 Mon Sep 17 00:00:00 2001 From: ayushtom Date: Mon, 11 Dec 2023 21:15:25 +0530 Subject: [PATCH 10/10] chore: remo warnings --- src/endpoints/quests/rango/check_trade.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/endpoints/quests/rango/check_trade.rs b/src/endpoints/quests/rango/check_trade.rs index 5d1e314b..d6418380 100644 --- a/src/endpoints/quests/rango/check_trade.rs +++ b/src/endpoints/quests/rango/check_trade.rs @@ -23,7 +23,7 @@ pub async fn handler( Err(e) => return get_error(format!("{}", e)), }; - if let Some(data_response) = response.get("data") { + if let Some(_) = response.get("data") { if let Some(result) = response.get("result") { if result.as_bool().unwrap() { return match state.upsert_completed_task(query.addr, task_id).await { @@ -36,9 +36,9 @@ pub async fn handler( get_error("User has not completed the task".to_string()) } -async fn make_rango_request(endpoint: &str, apiKey: &str) -> Result { +async fn make_rango_request(endpoint: &str, api_key: &str) -> Result { let client = reqwest::Client::new(); - match client.get(endpoint).header("apiKey", apiKey).send().await { + match client.get(endpoint).header("apiKey", api_key).send().await { Ok(response) => match response.json::().await { Ok(json) => { if let Some(res) = json.get("res") {