From: G8XSU <3442979+G8XSU@users.noreply.github.com> Date: Mon, 21 Oct 2024 22:36:11 +0000 (-0700) Subject: Implement to_lower_hex() Display/Debug for OfferId. X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=2e118415e0a12a68abbae0deeae8aae591a7786b;p=rust-lightning Implement to_lower_hex() Display/Debug for OfferId. --- diff --git a/lightning/src/offers/offer.rs b/lightning/src/offers/offer.rs index 6580430fb..0880e369e 100644 --- a/lightning/src/offers/offer.rs +++ b/lightning/src/offers/offer.rs @@ -77,6 +77,7 @@ //! [`ChannelManager`]: crate::ln::channelmanager::ChannelManager //! [`ChannelManager::create_offer_builder`]: crate::ln::channelmanager::ChannelManager::create_offer_builder +use core::borrow::Borrow; use bitcoin::constants::ChainHash; use bitcoin::network::Network; use bitcoin::secp256k1::{Keypair, PublicKey, Secp256k1, self}; @@ -111,12 +112,13 @@ use crate::prelude::*; #[cfg(feature = "std")] use std::time::SystemTime; +use bitcoin::hex::impl_fmt_traits; pub(super) const IV_BYTES_WITH_METADATA: &[u8; IV_LEN] = b"LDK Offer ~~~~~~"; pub(super) const IV_BYTES_WITHOUT_METADATA: &[u8; IV_LEN] = b"LDK Offer v2~~~~"; /// An identifier for an [`Offer`] built using [`DerivedMetadata`]. -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Eq, PartialEq)] pub struct OfferId(pub [u8; 32]); impl OfferId { @@ -134,6 +136,18 @@ impl OfferId { } } +impl Borrow<[u8]> for OfferId { + fn borrow(&self) -> &[u8] { + &self.0[..] + } +} + +impl_fmt_traits! { + impl fmt_traits for OfferId { + const LENGTH: usize = 32; + } +} + impl Writeable for OfferId { fn write(&self, w: &mut W) -> Result<(), io::Error> { self.0.write(w)