Skip to content

Commit

Permalink
fix: social networks not showing on ENS page (#88)
Browse files Browse the repository at this point in the history
* fix: add multiple verifier contracts for evm recors verifiers

* fix: get social id from multicall results

* fix: update config template file
  • Loading branch information
irisdv authored May 22, 2024
1 parent 39dfe16 commit 963137a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
6 changes: 3 additions & 3 deletions config.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ arbitrum = 2147525809
[evm_records_verifiers]

[evm_records_verifiers."com.discord"]
verifier_contract = "0x0182EcE8173C216A395f4828e1523541b7e3600bf190CB252E1a1A0cE219d184"
verifier_contracts = ["0x0182EcE8173C216A395f4828e1523541b7e3600bf190CB252E1a1A0cE219d184"]
field = "discord"
handler = "GetDiscordName"

[evm_records_verifiers."com.github"]
verifier_contract = "0x0182EcE8173C216A395f4828e1523541b7e3600bf190CB252E1a1A0cE219d184"
verifier_contracts = ["0x0182EcE8173C216A395f4828e1523541b7e3600bf190CB252E1a1A0cE219d184"]
field = "github"
handler = "GetGithubName"

[evm_records_verifiers."com.twitter"]
verifier_contract = "0x0182EcE8173C216A395f4828e1523541b7e3600bf190CB252E1a1A0cE219d184"
verifier_contracts = ["0x0182EcE8173C216A395f4828e1523541b7e3600bf190CB252E1a1A0cE219d184"]
field = "twitter"
handler = "GetTwitterName"
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub_struct!(Clone, Debug, Deserialize; Evm {
pub struct OffchainResolvers(HashMap<String, OffchainResolver>);

pub_struct!(Clone, Debug, Deserialize; EvmRecordVerifier {
verifier_contract: FieldElement,
verifier_contracts: Vec<FieldElement>,
field: String,
handler: HandlerType,
});
Expand Down
48 changes: 35 additions & 13 deletions src/endpoints/crosschain/ethereum/text_records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,43 +125,65 @@ pub async fn get_verifier_data(
id: FieldElement,
record_config: &EvmRecordVerifier,
) -> Option<String> {
let mut calls: Vec<FieldElement> = vec![FieldElement::from(record_config.verifier_contracts.len())];
for verifier in &record_config.verifier_contracts {
calls.push(config.contracts.starknetid);
calls.push(selector!("get_verifier_data"));
calls.push(FieldElement::from_dec_str("4").unwrap());
calls.push(id);
calls.push(cairo_short_string_to_felt(&record_config.field).unwrap());
calls.push(*verifier);
calls.push(FieldElement::ZERO)
}

let call_result = provider
.call(
FunctionCall {
contract_address: config.contracts.starknetid,
entry_point_selector: selector!("get_verifier_data"),
calldata: vec![
id,
cairo_short_string_to_felt(&record_config.field).unwrap(),
record_config.verifier_contract,
FieldElement::ZERO,
],
contract_address: config.contracts.argent_multicall,
entry_point_selector: selector!("aggregate"),
calldata: calls,
},
BlockId::Tag(BlockTag::Latest),
)
.await;

match call_result {
Ok(result) => {
if result[0] == FieldElement::ZERO {
let social_id = find_social_id(&result);
if social_id == FieldElement::ZERO {
return None;
}

match record_config.execute_handler(config, result[0]).await {
match record_config.execute_handler(config, social_id).await {
Ok(name) => Some(name),
Err(e) => {
println!("Error while executing handler: {:?}", e);
None
}
}

}
Err(e) => {
println!("Error while fetchingverifier data: {:?}", e);
Err(err) => {
println!("Error while fetching balances: {:?}", err);
None
}
}
}

fn find_social_id(result: &[FieldElement]) -> FieldElement {
// Remove the first element
let skipped_result = &result[2..];

// Iterate over chunks of 2 elements
for chunk in skipped_result.chunks(2) {
if let [_, second] = chunk {
if *second != FieldElement::ZERO {
return *second;
}
}
}
FieldElement::ZERO
}

pub async fn get_unbounded_user_data(
config: &Config,
provider: &JsonRpcClient<HttpTransport>,
Expand Down

0 comments on commit 963137a

Please sign in to comment.