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

feat: add support for multiple verifiers #119

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion config.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ private_key = "1"

[starknetid_contracts]
naming_contract = "0xXXXXXXXXXXXX"
verifier_contract = "0xXXXXXXXXXXXX"
verifier_contracts = [ "0xXXXXXXXXXXXX" ]
identity_contract = "0xXXXXXXXXXXXX"

[quests]
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub_struct!(Clone, Deserialize; Variables {

pub_struct!(Clone, Deserialize; StarknetIdContracts {
naming_contract: FieldElement,
verifier_contract: FieldElement,
verifier_contracts: Vec<FieldElement>,
identity_contract: FieldElement,
});

Expand Down
64 changes: 38 additions & 26 deletions src/endpoints/quests/starknetid/verify_socials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Th0rgal marked this conversation as resolved.
Show resolved Hide resolved
Err("You have not verified your Twitter account".to_string())
} else {
Err("You have not verified your Discord account".to_string())
Expand Down