From 1569993d76509adfb2f33bcf2cc2d85810f0f577 Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Sat, 28 Oct 2023 16:54:49 +0700 Subject: [PATCH 1/2] feat: add support for multiple verifiers --- config.template.toml | 2 +- src/config.rs | 2 +- .../quests/starknetid/verify_socials.rs | 64 +++++++++++-------- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/config.template.toml b/config.template.toml index a88007bb..8ecb5461 100644 --- a/config.template.toml +++ b/config.template.toml @@ -11,7 +11,7 @@ private_key = "1" [starknetid_contracts] naming_contract = "0xXXXXXXXXXXXX" -verifier_contract = "0xXXXXXXXXXXXX" +verifier_contracts = [ "0xXXXXXXXXXXXX" ] identity_contract = "0xXXXXXXXXXXXX" [quests] diff --git a/src/config.rs b/src/config.rs index 7db958d6..2d07b633 100644 --- a/src/config.rs +++ b/src/config.rs @@ -26,7 +26,7 @@ pub_struct!(Clone, Deserialize; Variables { pub_struct!(Clone, Deserialize; StarknetIdContracts { naming_contract: FieldElement, - verifier_contract: FieldElement, + verifier_contracts: Vec, identity_contract: FieldElement, }); diff --git a/src/endpoints/quests/starknetid/verify_socials.rs b/src/endpoints/quests/starknetid/verify_socials.rs index 337f5220..86c3475d 100644 --- a/src/endpoints/quests/starknetid/verify_socials.rs +++ b/src/endpoints/quests/starknetid/verify_socials.rs @@ -63,38 +63,50 @@ pub async fn handler( ) .await?; - let twitter_verifier_data = call_contract_helper( - &state, - state.conf.starknetid_contracts.identity_contract, - selector!("get_verifier_data"), - vec![ - id_res[0], - short_string!("twitter"), - state.conf.starknetid_contracts.verifier_contract, - FieldElement::ZERO, - ], - ) - .await?; + let mut twitter = false; + let mut discord = false; + for verifier_contract in &state.conf.starknetid_contracts.verifier_contracts { - let discord_verifier_data = call_contract_helper( - &state, - state.conf.starknetid_contracts.identity_contract, - selector!("get_verifier_data"), - vec![ - id_res[0], - short_string!("discord"), - state.conf.starknetid_contracts.verifier_contract, - FieldElement::ZERO, - ], - ) - .await?; + let twitter_verifier_data = call_contract_helper( + &state, + state.conf.starknetid_contracts.identity_contract, + selector!("get_verifier_data"), + vec![ + id_res[0], + short_string!("twitter"), + *verifier_contract, + FieldElement::ZERO, + ], + ) + .await?; + if twitter_verifier_data[0] != felt!("0") { + twitter = true; + } + + let discord_verifier_data = call_contract_helper( + &state, + state.conf.starknetid_contracts.identity_contract, + selector!("get_verifier_data"), + vec![ + id_res[0], + short_string!("discord"), + *verifier_contract, + FieldElement::ZERO, + ], + ) + .await?; + if discord_verifier_data[0] != felt!("0") { + discord = true; + } + } + - if twitter_verifier_data[0] != felt!("0") && discord_verifier_data[0] != felt!("0") { + 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_verifier_data[0] == felt!("0") { + } else if twitter{ Err("You have not verified your Twitter account".to_string()) } else { Err("You have not verified your Discord account".to_string()) From df2ac9e762b294e54611af5870cfe42f8140c3de Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Mon, 30 Oct 2023 17:47:14 +0700 Subject: [PATCH 2/2] fix: twitter condition for error --- src/endpoints/quests/starknetid/verify_socials.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/endpoints/quests/starknetid/verify_socials.rs b/src/endpoints/quests/starknetid/verify_socials.rs index 86c3475d..be30f861 100644 --- a/src/endpoints/quests/starknetid/verify_socials.rs +++ b/src/endpoints/quests/starknetid/verify_socials.rs @@ -106,7 +106,7 @@ pub async fn handler( 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())