diff --git a/src/ffi/types.rs b/src/ffi/types.rs index f39f3bca7..06dce4948 100644 --- a/src/ffi/types.rs +++ b/src/ffi/types.rs @@ -382,7 +382,8 @@ impl std::fmt::Display for Offer { /// This struct can also be used for LN-Address recipients. /// /// [Homograph Attacks]: https://en.wikipedia.org/wiki/IDN_homograph_attack -#[derive(uniffi::Object)] +#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, uniffi::Object)] +#[uniffi::export(Debug, Display, Eq)] pub struct HumanReadableName { pub(crate) inner: LdkHumanReadableName, } @@ -439,6 +440,12 @@ impl AsRef for HumanReadableName { } } +impl std::fmt::Display for HumanReadableName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.inner) + } +} + /// A `Refund` is a request to send an [`Bolt12Invoice`] without a preceding [`Offer`]. /// /// Typically, after an invoice is paid, the recipient may publish a refund allowing the sender to @@ -1987,4 +1994,21 @@ mod tests { assert_eq!(ldk_invoice.signable_hash().to_vec(), wrapped_invoice.signable_hash()); } + + #[test] + fn test_hrn_traits() { + let encoded = "alice@lightning.space"; + let hrn1 = HumanReadableName::from_encoded(encoded).unwrap(); + let hrn2 = HumanReadableName::from_encoded(encoded).unwrap(); + + assert_eq!(hrn1.to_string(), "â‚¿alice@lightning.space"); + + assert_eq!(hrn1, hrn2); + + let debug_output = format!("{:?}", hrn1); + assert!(debug_output.contains("HumanReadableName")); + + let hrn3 = hrn1; + assert_eq!(hrn1, hrn3); + } }