Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: braavos achievement #90

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
}