Skip to content

Commit 6941b0a

Browse files
authored
Merge pull request #4174 from andrei-21/feature/clean-predicates
Use char-based predicates in DNS resolver
2 parents be24841 + 32a33ac commit 6941b0a

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

lightning/src/onion_message/dns_resolution.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ pub struct HumanReadableName {
211211
impl HumanReadableName {
212212
/// Constructs a new [`HumanReadableName`] from the `user` and `domain` parts. See the
213213
/// struct-level documentation for more on the requirements on each.
214-
pub fn new(user: &str, domain: &str) -> Result<HumanReadableName, ()> {
214+
pub fn new(user: &str, domain: &str) -> Result<Self, ()> {
215215
// First normalize domain and remove the optional trailing `.`
216-
let domain = domain.strip_suffix(".").unwrap_or(domain);
216+
let domain = domain.strip_suffix('.').unwrap_or(domain);
217217
if user.len() + domain.len() + REQUIRED_EXTRA_LEN > 255 {
218218
return Err(());
219219
}
@@ -233,24 +233,17 @@ impl HumanReadableName {
233233
let mut contents = [0; 255 - REQUIRED_EXTRA_LEN];
234234
contents[..user.len()].copy_from_slice(user.as_bytes());
235235
contents[user.len()..user.len() + domain.len()].copy_from_slice(domain.as_bytes());
236-
Ok(HumanReadableName {
237-
contents,
238-
user_len: user.len() as u8,
239-
domain_len: domain.len() as u8,
240-
})
236+
Ok(Self { contents, user_len: user.len() as u8, domain_len: domain.len() as u8 })
241237
}
242238

243239
/// Constructs a new [`HumanReadableName`] from the standard encoding - `user`@`domain`.
244240
///
245241
/// If `user` includes the standard BIP 353 ₿ prefix it is automatically removed as required by
246242
/// BIP 353.
247-
pub fn from_encoded(encoded: &str) -> Result<HumanReadableName, ()> {
248-
if let Some((user, domain)) = encoded.strip_prefix('₿').unwrap_or(encoded).split_once("@")
249-
{
250-
Self::new(user, domain)
251-
} else {
252-
Err(())
253-
}
243+
pub fn from_encoded(encoded: &str) -> Result<Self, ()> {
244+
let encoded = encoded.strip_prefix('₿').unwrap_or(encoded);
245+
let (user, domain) = encoded.split_once('@').ok_or(())?;
246+
Self::new(user, domain)
254247
}
255248

256249
/// Gets the `user` part of this Human Readable Name
@@ -438,9 +431,9 @@ impl OMNameResolver {
438431
&self, msg: DNSSECProof, context: DNSResolverContext,
439432
) -> Option<(Vec<(HumanReadableName, PaymentId)>, Offer)> {
440433
let (completed_requests, uri) = self.handle_dnssec_proof_for_uri(msg, context)?;
441-
if let Some((_onchain, params)) = uri.split_once("?") {
442-
for param in params.split("&") {
443-
let (k, v) = if let Some(split) = param.split_once("=") {
434+
if let Some((_onchain, params)) = uri.split_once('?') {
435+
for param in params.split('&') {
436+
let (k, v) = if let Some(split) = param.split_once('=') {
444437
split
445438
} else {
446439
continue;

0 commit comments

Comments
 (0)