diff --git a/src/tigergraph/vertex/domain_collection.rs b/src/tigergraph/vertex/domain_collection.rs index 52f996a..8c6dd3e 100644 --- a/src/tigergraph/vertex/domain_collection.rs +++ b/src/tigergraph/vertex/domain_collection.rs @@ -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 = Vec::new(); - for (domain_platform, exts) in EXTENSION.iter() { - let existing_tlds: Vec = 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, @@ -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, })) } } diff --git a/src/upstream/clusters/mod.rs b/src/upstream/clusters/mod.rs index 0c4581d..51d84a4 100644 --- a/src/upstream/clusters/mod.rs +++ b/src/upstream/clusters/mod.rs @@ -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, @@ -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, @@ -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", diff --git a/src/upstream/farcaster/warpcast.rs b/src/upstream/farcaster/warpcast.rs index 121f0fc..6ec59f3 100644 --- a/src/upstream/farcaster/warpcast.rs +++ b/src/upstream/farcaster/warpcast.rs @@ -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(); @@ -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(); @@ -319,7 +319,7 @@ async fn save_verifications( user: &User, verification: &Verification, ) -> Result { - 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(); @@ -715,7 +715,7 @@ pub async fn domain_search(name: &str) -> Result { } 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(); diff --git a/src/upstream/opensea/mod.rs b/src/upstream/opensea/mod.rs index 0e1ce42..936a1f1 100644 --- a/src/upstream/opensea/mod.rs +++ b/src/upstream/opensea/mod.rs @@ -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 { diff --git a/src/upstream/space_id/v3.rs b/src/upstream/space_id/v3.rs index e2079b7..cb33cff 100644 --- a/src/upstream/space_id/v3.rs +++ b/src/upstream/space_id/v3.rs @@ -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 } diff --git a/src/upstream/types/domain_name.rs b/src/upstream/types/domain_name.rs index 44c6f24..6d4da4b 100644 --- a/src/upstream/types/domain_name.rs +++ b/src/upstream/types/domain_name.rs @@ -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/ @@ -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, @@ -517,6 +523,7 @@ impl From 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, @@ -567,6 +574,7 @@ impl From 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, diff --git a/src/upstream/unstoppable/mod.rs b/src/upstream/unstoppable/mod.rs index 1231720..fed0abc 100644 --- a/src/upstream/unstoppable/mod.rs +++ b/src/upstream/unstoppable/mod.rs @@ -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; }