Skip to content

Commit 35748f6

Browse files
authored
Merge pull request #3829 from chuksys/implement-display-for-hrn
Implement core::fmt::Display for HumanReadableName
2 parents 97f0e4b + 81b201a commit 35748f6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lightning/src/onion_message/dns_resolution.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ use dnssec_prover::rr::Name;
3636

3737
use lightning_types::features::NodeFeatures;
3838

39+
use core::fmt;
40+
3941
use crate::blinded_path::message::DNSResolverContext;
4042
use crate::io;
4143
#[cfg(feature = "dnssec")]
@@ -287,6 +289,12 @@ impl Readable for HumanReadableName {
287289
}
288290
}
289291

292+
impl fmt::Display for HumanReadableName {
293+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
294+
write!(f, "₿{}@{}", self.user(), self.domain())
295+
}
296+
}
297+
290298
#[cfg(feature = "dnssec")]
291299
struct PendingResolution {
292300
start_height: u32,
@@ -473,3 +481,24 @@ impl OMNameResolver {
473481
None
474482
}
475483
}
484+
485+
#[cfg(test)]
486+
mod tests {
487+
use super::HumanReadableName;
488+
489+
#[test]
490+
fn test_hrn_display_format() {
491+
let user = "user";
492+
let domain = "example.com";
493+
let hrn = HumanReadableName::new(user, domain)
494+
.expect("Failed to create HumanReadableName for user");
495+
496+
// Assert that the formatted string matches the expected output
497+
let expected_display = format!("₿{}@{}", user, domain);
498+
assert_eq!(
499+
format!("{}", hrn),
500+
expected_display,
501+
"HumanReadableName display format mismatch"
502+
);
503+
}
504+
}

0 commit comments

Comments
 (0)