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(bens): Added TLD-based fallback for name search in networks #1175

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c661327
updated function with serch by picking 5 names+tld
Ilyak777 Jan 6, 2025
f38fd92
deleted unnecessary empty lines
Ilyak777 Jan 6, 2025
a113537
Merge branch 'main' into feat/bens/add-tld-for-name-in-network-search
Ilyak777 Jan 6, 2025
e4376da
fixed spelling problems
Ilyak777 Jan 6, 2025
67cf6d7
Merge branch 'feat/bens/add-tld-for-name-in-network-search' of github…
Ilyak777 Jan 6, 2025
a2b3fed
used fmt to solve spelling issues
Ilyak777 Jan 6, 2025
99b159b
updated core function
Ilyak777 Jan 16, 2025
213c5ff
fixed spellings with rust rules
Ilyak777 Jan 16, 2025
4a7da33
updated code with clippy suggestions
Ilyak777 Jan 16, 2025
9e2e224
added first test cases for tld function
Ilyak777 Jan 16, 2025
34a79d7
added printsLn to capture moment where app crashes
Ilyak777 Jan 22, 2025
5e0e2ad
added new func to extract the exact domain
Ilyak777 Jan 23, 2025
46d13c1
updated after fmt command
Ilyak777 Jan 23, 2025
a9d0009
updated mock data
Ilyak777 Jan 23, 2025
3f746a5
added map_err and fixed with fmt
Ilyak777 Jan 23, 2025
5d5755b
removed Rabbit suggestion with mapping error
Ilyak777 Jan 23, 2025
57c745d
deleted all pintLn from protocoler and domain
Ilyak777 Jan 23, 2025
6c41165
returned variables to readme
Ilyak777 Jan 23, 2025
5b461ba
Merge branch 'main' into feat/bens/add-tld-for-name-in-network-search
Ilyak777 Jan 23, 2025
9bfeb5d
Update blockscout-ens/bens-logic/src/protocols/protocoler.rs
Ilyak777 Jan 24, 2025
506c310
updated due to comments in review
Ilyak777 Jan 27, 2025
64213c9
pulled main into this branch
Ilyak777 Jan 27, 2025
062a4ec
added abcnews with another domain to seed file and added prints
Ilyak777 Feb 5, 2025
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
50 changes: 47 additions & 3 deletions blockscout-ens/bens-logic/src/protocols/protocoler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub enum AddressResolveTechnique {
ReverseRegistry,
AllDomains,
}
const MAX_NAMES_LIMIT: usize = 5;

impl Tld {
pub fn new(tld: &str) -> Tld {
Expand Down Expand Up @@ -203,15 +204,58 @@ impl Protocoler {
network_id: i64,
maybe_filter: Option<NonEmpty<String>>,
) -> Result<Vec<DomainNameOnProtocol>, ProtocolError> {
let tld = Tld::from_domain_name(name)
.ok_or_else(|| ProtocolError::InvalidName(name.to_string()))?;
let tlds = self
.networks
.get(&network_id)
.ok_or_else(|| ProtocolError::NetworkNotFound(network_id))?
.use_protocols
.iter()
.filter_map(|protocol_name| {
self.protocols
.get(protocol_name)
.map(|protocol| protocol.info.tld_list.iter().cloned())
})
.flatten()
.collect::<Vec<Tld>>();

if name.contains('.') {
return self.find_names_with_tld(name, network_id, maybe_filter);
}

let mut all_names_with_protocols = Vec::new();
for tld in tlds {
if all_names_with_protocols.len() >= MAX_NAMES_LIMIT {
break;
}
let name_with_tld = format!("{}.{}", name, tld.0);
if let Ok(mut names) = self.find_names_with_tld(&name_with_tld, network_id, maybe_filter.clone()) {
all_names_with_protocols.append(&mut names);
}
}

if all_names_with_protocols.is_empty() {
return Err(ProtocolError::InvalidName(name.to_string()));
}

Ok(all_names_with_protocols.into_iter().take(MAX_NAMES_LIMIT).collect())
}

fn find_names_with_tld(
&self,
name_with_tld: &str,
network_id: i64,
maybe_filter: Option<NonEmpty<String>>,
) -> Result<Vec<DomainNameOnProtocol>, ProtocolError> {
let tld = Tld::from_domain_name(name_with_tld)
.ok_or_else(|| ProtocolError::InvalidName(name_with_tld.to_string()))?;
let protocols = self.protocols_of_network_for_tld(network_id, tld, maybe_filter)?;
let names_with_protocols = protocols
.into_iter()
.filter_map(|p| DomainNameOnProtocol::new(name, p).ok())
.filter_map(|p| DomainNameOnProtocol::new(name_with_tld, p).ok())
.collect();
Ok(names_with_protocols)
}


pub fn main_name_in_network(
&self,
Expand Down