Skip to content

Commit

Permalink
Merge pull request #163 from ZhongFuze/graphql/domain-search
Browse files Browse the repository at this point in the history
[!] Fix `domain_search` available list must be returned in specified order
  • Loading branch information
nykma authored Aug 15, 2024
2 parents ac2a2a9 + 93bbb22 commit f1a84b8
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 68 deletions.
133 changes: 76 additions & 57 deletions src/tigergraph/vertex/domain_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,74 +222,96 @@ impl DomainCollection {
let result = r.results.and_then(|vec_res| vec_res.first().cloned());
match result {
None => return Ok(None),
Some(mut result) => {
Some(result) => {
if result.collection.is_empty() {
return Ok(None);
}
// Fill the domain available name list
// list must be returned in the specified order
let mut available_domains: Vec<AvailableDomain> = Vec::new();

for (domain_platform, exts) in EXTENSION.iter() {
let existing_tlds: Vec<String> = result
.domains
.iter()
.filter(|domain| domain.platform == *domain_platform)
.map(|domain| domain.tld.clone())
.collect();
let mut exist_tld_map: HashMap<(Platform, String), AvailableDomain> =
HashMap::new();
for exist in result.domains.iter() {
exist_tld_map.insert(
(exist.platform.clone(), exist.tld.clone()),
exist.to_owned(),
);
}

if existing_tlds.is_empty() {
// If the domain_platform does not exist, add all tlds as available
if *domain_platform == Platform::Clusters {
let cluster_parent = format!("{}", name);
let cluster_child = format!("{}/{}", name, EXT::ClustersMain);
available_domains.push(AvailableDomain {
platform: domain_platform.clone(),
name: cluster_parent,
tld: EXT::ClustersRoot.to_string(),
availability: true,
status: DomainStatus::Available,
expired_at: None,
});
available_domains.push(AvailableDomain {
platform: domain_platform.clone(),
name: cluster_child,
tld: EXT::ClustersMain.to_string(),
availability: true,
status: DomainStatus::Available,
expired_at: None,
});
} else if *domain_platform == Platform::Farcaster {
available_domains.push(AvailableDomain {
platform: domain_platform.clone(),
name: name.to_string(),
tld: "".to_string(),
availability: true,
status: DomainStatus::Available,
expired_at: None,
});
} else {
for ext in exts {
let domain_name = format!("{}.{}", name, ext);
// specified order
let return_order = vec![
Platform::ENS,
Platform::Farcaster,
Platform::Lens,
Platform::SNS,
Platform::Dotbit,
Platform::Crossbell,
Platform::Clusters,
Platform::UnstoppableDomains,
Platform::SpaceId,
Platform::Zeta,
Platform::Mode,
Platform::Arbitrum,
Platform::Taiko,
Platform::Mint,
Platform::Zkfair,
Platform::Manta,
Platform::Lightlink,
Platform::Genome,
Platform::Merlin,
Platform::AlienX,
Platform::Tomo,
Platform::Ailayer,
];

for domain_order in return_order.iter() {
if let Some(required_exts) = EXTENSION.get(domain_order) {
if *domain_order == Platform::Clusters {
if let Some(exist_domain) = exist_tld_map
.get(&(Platform::Clusters, EXT::ClustersRoot.to_string()))
{
available_domains.push(exist_domain.to_owned());
} else {
let cluster_parent = format!("{}", name);
available_domains.push(AvailableDomain {
platform: domain_platform.clone(),
name: domain_name,
tld: ext.to_string(),
platform: domain_order.clone(),
name: cluster_parent,
tld: EXT::ClustersRoot.to_string(),
availability: true,
status: DomainStatus::Available,
expired_at: None,
});
}
}
} else {
// If the domain_platform exists, find missing tlds
if *domain_platform != Platform::Clusters
&& *domain_platform != Platform::Unknown
{
for ext in exts {
if !existing_tlds.contains(&ext.to_string()) {
} else if *domain_order == Platform::Farcaster {
if let Some(exist_domain) = exist_tld_map
.get(&(Platform::Farcaster, EXT::Eth.to_string()))
{
available_domains.push(exist_domain.to_owned());
} else if let Some(exist_domain) =
exist_tld_map.get(&(Platform::Farcaster, "".to_string()))
{
available_domains.push(exist_domain.to_owned());
} else {
available_domains.push(AvailableDomain {
platform: domain_order.clone(),
name: name.to_string(),
tld: "".to_string(),
availability: true,
status: DomainStatus::Available,
expired_at: None,
});
}
} else {
for ext in required_exts {
if let Some(exist_domain) =
exist_tld_map.get(&(*domain_order, ext.to_string()))
{
available_domains.push(exist_domain.to_owned());
} else {
let domain_name = format!("{}.{}", name, ext);
available_domains.push(AvailableDomain {
platform: domain_platform.clone(),
platform: domain_order.clone(),
name: domain_name,
tld: ext.to_string(),
availability: true,
Expand All @@ -302,15 +324,12 @@ impl DomainCollection {
}
}

// Update the result with the newly found available domains
result.domains.extend(available_domains);

match result.collection.first().cloned() {
None => return Ok(None),
Some(c) => {
return Ok(Some(DomainAvailableSearch {
collection: c.attributes.clone(),
domains: result.domains,
domains: available_domains,
}))
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/upstream/clusters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async fn batch_fetch_by_address(target: &Target) -> Result<(TargetProcessedList,
let mut edges = EdgeList::new();
let hv = IdentitiesGraph::default();
for d in metadatas.into_iter() {
let wallet_platform: Platform = d.platform.parse()?;
let wallet_platform: Platform = d.platform.parse().unwrap_or(Platform::Unknown);
if wallet_platform == Platform::Unknown {
warn!(
?target,
Expand Down Expand Up @@ -277,7 +277,7 @@ async fn batch_fetch_by_clusters(
let hv = IdentitiesGraph::default();

for d in metadatas.into_iter() {
let wallet_platform: Platform = d.platform.parse()?;
let wallet_platform: Platform = d.platform.parse().unwrap_or(Platform::Unknown);
if wallet_platform == Platform::Unknown {
warn!(
?target,
Expand Down Expand Up @@ -614,7 +614,7 @@ impl DomainSearch for Clusters {
updated_at: naive_now(),
};
for d in metadatas.into_iter() {
let wallet_platform: Platform = d.platform.parse()?;
let wallet_platform: Platform = d.platform.parse().unwrap_or(Platform::Unknown);
if wallet_platform == Platform::Unknown {
warn!(
"Clusters domain_search(name={}) platform={} is Unknown in types",
Expand Down
8 changes: 4 additions & 4 deletions src/upstream/farcaster/warpcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub async fn batch_fetch_by_username(
}

for verification in verifications.iter() {
let protocol: Platform = verification.protocol.parse()?;
let protocol: Platform = verification.protocol.parse().unwrap_or(Platform::Unknown);
let mut address = verification.address.clone();
if protocol == Platform::Ethereum {
address = address.to_lowercase();
Expand Down Expand Up @@ -179,7 +179,7 @@ pub async fn batch_fetch_by_signer(
}

for verification in verifications.iter() {
let protocol: Platform = verification.protocol.parse()?;
let protocol: Platform = verification.protocol.parse().unwrap_or(Platform::Unknown);
let mut verification_address = verification.address.clone();
if protocol == Platform::Ethereum {
verification_address = verification_address.to_lowercase();
Expand Down Expand Up @@ -319,7 +319,7 @@ async fn save_verifications(
user: &User,
verification: &Verification,
) -> Result<Target, Error> {
let protocol: Platform = verification.protocol.parse()?;
let protocol: Platform = verification.protocol.parse().unwrap_or(Platform::Unknown);
let mut address = verification.address.clone();
if protocol == Platform::Ethereum {
address = address.to_lowercase();
Expand Down Expand Up @@ -715,7 +715,7 @@ pub async fn domain_search(name: &str) -> Result<EdgeList, Error> {
}

for verification in verifications.iter() {
let protocol: Platform = verification.protocol.parse()?;
let protocol: Platform = verification.protocol.parse().unwrap_or(Platform::Unknown);
let mut address = verification.address.clone();
if protocol == Platform::Ethereum {
address = address.to_lowercase();
Expand Down
2 changes: 1 addition & 1 deletion src/upstream/opensea/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async fn batch_fetch_connections(
let hv = IdentitiesGraph::default();

for record in records.iter() {
let sns_platform: Platform = record.sns_platform.parse()?;
let sns_platform: Platform = record.sns_platform.parse().unwrap_or(Platform::Unknown);
let sns_handle = record.sns_handle.clone();
let address = record.address.clone();
if !record.is_verified {
Expand Down
2 changes: 1 addition & 1 deletion src/upstream/space_id/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl DomainSearch for SpaceIdV3 {
};

let tld_name = item.tld.tld_name.clone();
let tld: EXT = tld_name.parse()?;
let tld: EXT = tld_name.parse().unwrap_or(EXT::Unknown);
if tld == EXT::Gno || tld == EXT::Eth {
continue; // EXT(`.eth`, `.gno`) are in special upstreams, do not repeated
}
Expand Down
10 changes: 9 additions & 1 deletion src/upstream/types/domain_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ pub enum EXT {
#[serde(rename = "tball")]
#[graphql(name = "tball")]
Tball,
#[strum(serialize = "farms")]
#[serde(rename = "farms")]
#[graphql(name = "farms")]
Farms,

// Domains (TLDs) using the SPACE ID 3.0 infrastructure
/// https://api.prd.space.id/
Expand Down Expand Up @@ -464,7 +468,9 @@ lazy_static! {
EXT::Zil,
EXT::Austin,
EXT::Raiin,
EXT::Tball]);
EXT::Tball,
EXT::Farms,
]);

extension.insert(Platform::SpaceId, vec![
EXT::Bnb,
Expand Down Expand Up @@ -517,6 +523,7 @@ impl From<EXT> for Platform {
EXT::Austin => Platform::UnstoppableDomains,
EXT::Raiin => Platform::UnstoppableDomains,
EXT::Tball => Platform::UnstoppableDomains,
EXT::Farms => Platform::UnstoppableDomains,

// SpaceID 3.0 extensions
EXT::Bnb => Platform::SpaceId,
Expand Down Expand Up @@ -567,6 +574,7 @@ impl From<EXT> for DomainNameSystem {
EXT::Austin => DomainNameSystem::UnstoppableDomains,
EXT::Raiin => DomainNameSystem::UnstoppableDomains,
EXT::Tball => DomainNameSystem::UnstoppableDomains,
EXT::Farms => DomainNameSystem::UnstoppableDomains,

// SpaceID 3.0 extensions
EXT::Bnb => DomainNameSystem::SpaceId,
Expand Down
2 changes: 1 addition & 1 deletion src/upstream/unstoppable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ impl DomainSearch for UnstoppableDomains {
for r in result.iter() {
let ud_name = r.domain.name.clone();
let tld_name = r.domain.extension.clone();
let tld: EXT = tld_name.parse()?;
let tld: EXT = tld_name.parse().unwrap_or(EXT::Unknown);
if tld == EXT::Unknown {
continue;
}
Expand Down

0 comments on commit f1a84b8

Please sign in to comment.