Skip to content

Commit 6104eb0

Browse files
authored
Merge pull request #3377 from G8XSU/hex-impls
Implement to_lower_hex() Display/Debug for PaymentId & OfferId
2 parents 66e4458 + 2e11841 commit 6104eb0

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,14 @@ use alloc::collections::{btree_map, BTreeMap};
107107
use crate::io;
108108
use crate::prelude::*;
109109
use core::{cmp, mem};
110+
use core::borrow::Borrow;
110111
use core::cell::RefCell;
111112
use crate::io::Read;
112113
use crate::sync::{Arc, Mutex, RwLock, RwLockReadGuard, FairRwLock, LockTestExt, LockHeldState};
113114
use core::sync::atomic::{AtomicUsize, AtomicBool, Ordering};
114115
use core::time::Duration;
115116
use core::ops::Deref;
116-
117+
use bitcoin::hex::impl_fmt_traits;
117118
// Re-export this for use in the public API.
118119
pub use crate::ln::outbound_payment::{Bolt12PaymentError, PaymentSendFailure, ProbeSendFailure, Retry, RetryableSendFailure, RecipientOnionFields};
119120
use crate::ln::script::ShutdownScript;
@@ -468,7 +469,7 @@ impl Verification for PaymentHash {
468469
/// a payment and ensure idempotency in LDK.
469470
///
470471
/// This is not exported to bindings users as we just use [u8; 32] directly
471-
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
472+
#[derive(Hash, Copy, Clone, PartialEq, Eq)]
472473
pub struct PaymentId(pub [u8; Self::LENGTH]);
473474

474475
impl PaymentId {
@@ -528,6 +529,18 @@ impl PaymentId {
528529
}
529530
}
530531

532+
impl Borrow<[u8]> for PaymentId {
533+
fn borrow(&self) -> &[u8] {
534+
&self.0[..]
535+
}
536+
}
537+
538+
impl_fmt_traits! {
539+
impl fmt_traits for PaymentId {
540+
const LENGTH: usize = 32;
541+
}
542+
}
543+
531544
impl Writeable for PaymentId {
532545
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
533546
self.0.write(w)
@@ -541,12 +554,6 @@ impl Readable for PaymentId {
541554
}
542555
}
543556

544-
impl core::fmt::Display for PaymentId {
545-
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
546-
crate::util::logger::DebugBytes(&self.0).fmt(f)
547-
}
548-
}
549-
550557
/// An identifier used to uniquely identify an intercepted HTLC to LDK.
551558
///
552559
/// This is not exported to bindings users as we just use [u8; 32] directly

lightning/src/offers/offer.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
//! [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
7878
//! [`ChannelManager::create_offer_builder`]: crate::ln::channelmanager::ChannelManager::create_offer_builder
7979
80+
use core::borrow::Borrow;
8081
use bitcoin::constants::ChainHash;
8182
use bitcoin::network::Network;
8283
use bitcoin::secp256k1::{Keypair, PublicKey, Secp256k1, self};
@@ -111,12 +112,13 @@ use crate::prelude::*;
111112

112113
#[cfg(feature = "std")]
113114
use std::time::SystemTime;
115+
use bitcoin::hex::impl_fmt_traits;
114116

115117
pub(super) const IV_BYTES_WITH_METADATA: &[u8; IV_LEN] = b"LDK Offer ~~~~~~";
116118
pub(super) const IV_BYTES_WITHOUT_METADATA: &[u8; IV_LEN] = b"LDK Offer v2~~~~";
117119

118120
/// An identifier for an [`Offer`] built using [`DerivedMetadata`].
119-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
121+
#[derive(Clone, Copy, Eq, PartialEq)]
120122
pub struct OfferId(pub [u8; 32]);
121123

122124
impl OfferId {
@@ -134,6 +136,18 @@ impl OfferId {
134136
}
135137
}
136138

139+
impl Borrow<[u8]> for OfferId {
140+
fn borrow(&self) -> &[u8] {
141+
&self.0[..]
142+
}
143+
}
144+
145+
impl_fmt_traits! {
146+
impl fmt_traits for OfferId {
147+
const LENGTH: usize = 32;
148+
}
149+
}
150+
137151
impl Writeable for OfferId {
138152
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
139153
self.0.write(w)

0 commit comments

Comments
 (0)