Skip to content

Commit

Permalink
Merge pull request #90 from starknet-id/feat/add_braavos_quests
Browse files Browse the repository at this point in the history
fix: braavos achievement
  • Loading branch information
Th0rgal authored Oct 10, 2023
2 parents 4211e55 + ee32b90 commit 6b23faf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ async-trait = "0.1.68"
percent-encoding = "2.3.0"
chrono = "0.4.19"
lazy_static = "1.4.0"
regex = "1.10.0"
9 changes: 3 additions & 6 deletions src/common/verify_has_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub async fn execute_has_nft(
addr: FieldElement,
contract: FieldElement,
limit: u32,
is_whitelisted: fn(&Nft) -> bool,
is_whitelisted: fn(&Nft, &mut Vec<String>),
) -> Result<bool, String> {
let url = format!(
"https://api.starkscan.co/api/v0/nfts?contract_address={}&owner_address={}",
Expand All @@ -34,11 +34,8 @@ pub async fn execute_has_nft(
let nft_data = res.data;
let mut unique_nfts: Vec<String> = Vec::new();
for nft in nft_data {
if nft.name.is_some() && is_whitelisted(&nft) {
let name = nft.name.unwrap();
if !unique_nfts.contains(&name) {
unique_nfts.push(name);
}
if nft.name.is_some() {
is_whitelisted(&nft, &mut unique_nfts)
}
}
Ok(unique_nfts.len() >= limit as usize)
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/achievements/verify_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use mongodb::bson::doc;
use serde_json::json;
use starknet::core::types::FieldElement;

type NftCheck = fn(&Nft) -> bool;
type NftCheck = fn(&Nft, unique_nfts: &mut Vec<String>);

fn get_args(config: Config, achievement_id: u32) -> Result<(FieldElement, u32, NftCheck), String> {
let argent_contract = config.achievements.argent.contract;
Expand Down
42 changes: 29 additions & 13 deletions src/endpoints/achievements/verify_whitelisted.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
use crate::models::Nft;
use regex::Regex;

pub fn is_braavos_whitelisted(nft: &Nft) -> bool {
let whitelist = vec![
"Starknet Onboarding Journey NFT",
"Starknet Identity Journey",
"Starknet Exchange Journey",
"Starknet Mobile Journey",
"Starknet Journey Coin NFT",
lazy_static::lazy_static! {
static ref BRAAVOS_WHITELIST : Vec<Regex> = vec![
Regex::new(r"Starknet Onboarding Journey( NFT)?").unwrap(),
Regex::new(r"Starknet Identity Journey").unwrap(),
Regex::new(r"Starknet Exchange Journey").unwrap(),
Regex::new(r"Starknet Mobile Journey").unwrap(),
Regex::new(r"(Starknet Journey Coin NFT|starknet-journey-coin)").unwrap()
];
}

pub fn is_braavos_whitelisted(nft: &Nft, unique_nfts: &mut Vec<String>) {
if let Some(name) = nft.name.as_ref() {
return whitelist.contains(&name.as_str());
for pattern in &*BRAAVOS_WHITELIST {
if pattern.is_match(name) && !unique_nfts.contains(name) {
unique_nfts.push(name.clone());
return;
}
}
}
false
}

pub fn is_argent_whitelisted(_nft: &Nft) -> bool {
true
pub fn is_argent_whitelisted(nft: &Nft, unique_nfts: &mut Vec<String>) {
if let Some(name) = nft.name.as_ref() {
if !unique_nfts.contains(name) {
unique_nfts.push(name.to_string());
}
}
}

pub fn is_carbonable_whitelisted(_nft: &Nft) -> bool {
true
pub fn is_carbonable_whitelisted(nft: &Nft, unique_nfts: &mut Vec<String>) {
if let Some(name) = nft.name.as_ref() {
if !unique_nfts.contains(name) {
unique_nfts.push(name.to_string());
}
}
}

0 comments on commit 6b23faf

Please sign in to comment.