Skip to content

Commit f740fa8

Browse files
types: remove unnecessary wrappers in non-uniffi case
This patch removes the Bolt12Invoice and StaticInvoice wrapper structs from the non-uniffi code path, using the LDK types directly instead. Problem: The non-uniffi case was wrapping LDK types in unnecessary wrapper structs. This adds boilerplate without any benefit since pure Rust users can use the LDK types directly. Solution: For non-uniffi builds, PaidBolt12Invoice now directly contains: - Arc<lightning::offers::invoice::Bolt12Invoice> - Arc<lightning::offers::static_invoice::StaticInvoice> The wrapper types are only needed for UniFFI builds where we need to expose a controlled API surface through the bindings. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3fbdb48 commit f740fa8

File tree

2 files changed

+11
-103
lines changed

2 files changed

+11
-103
lines changed

src/payment/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ pub use store::{
2424
};
2525
pub use unified::{UnifiedPayment, UnifiedPaymentResult};
2626

27-
pub use crate::types::{Bolt12Invoice, PaidBolt12Invoice, StaticInvoice};
27+
pub use crate::types::PaidBolt12Invoice;
28+
#[cfg(feature = "uniffi")]
29+
pub use crate::types::{Bolt12Invoice, StaticInvoice};

src/types.rs

Lines changed: 8 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
use std::fmt;
99
use std::future::Future;
10-
#[cfg(not(feature = "uniffi"))]
11-
use std::ops::Deref;
1210
use std::pin::Pin;
1311
use std::sync::{Arc, Mutex};
1412

@@ -629,98 +627,6 @@ pub use crate::ffi::{Bolt12Invoice, PaidBolt12Invoice, StaticInvoice};
629627
mod invoice_types {
630628
use super::*;
631629

632-
/// A wrapper around a [`lightning::offers::invoice::Bolt12Invoice`].
633-
#[derive(Debug, Clone, PartialEq, Eq)]
634-
pub struct Bolt12Invoice {
635-
pub(crate) inner: LdkBolt12Invoice,
636-
}
637-
638-
impl Bolt12Invoice {
639-
/// Returns the [`lightning_types::payment::PaymentHash`] of the invoice.
640-
pub fn payment_hash(&self) -> lightning_types::payment::PaymentHash {
641-
self.inner.payment_hash()
642-
}
643-
644-
/// Returns the amount in millisatoshis.
645-
pub fn amount_msats(&self) -> u64 {
646-
self.inner.amount_msats()
647-
}
648-
649-
/// Writes `self` out to a `Vec<u8>`.
650-
pub fn encode(&self) -> Vec<u8> {
651-
self.inner.encode()
652-
}
653-
}
654-
655-
impl Deref for Bolt12Invoice {
656-
type Target = LdkBolt12Invoice;
657-
fn deref(&self) -> &Self::Target {
658-
&self.inner
659-
}
660-
}
661-
662-
impl AsRef<LdkBolt12Invoice> for Bolt12Invoice {
663-
fn as_ref(&self) -> &LdkBolt12Invoice {
664-
self.deref()
665-
}
666-
}
667-
668-
impl From<LdkBolt12Invoice> for Bolt12Invoice {
669-
fn from(invoice: LdkBolt12Invoice) -> Self {
670-
Bolt12Invoice { inner: invoice }
671-
}
672-
}
673-
674-
/// A wrapper around a [`lightning::offers::static_invoice::StaticInvoice`].
675-
///
676-
/// A `StaticInvoice` is used for async payments where the recipient may be offline.
677-
///
678-
/// Unlike [`Bolt12Invoice`], a `StaticInvoice` does not support proof of payment
679-
/// because the payment hash is not derived from a preimage known only to the recipient.
680-
#[derive(Debug, Clone, PartialEq, Eq)]
681-
pub struct StaticInvoice {
682-
pub(crate) inner: LdkStaticInvoice,
683-
}
684-
685-
impl StaticInvoice {
686-
/// Returns the [`OfferId`] of the underlying [`Offer`] this invoice corresponds to.
687-
///
688-
/// [`Offer`]: lightning::offers::offer::Offer
689-
/// [`OfferId`]: lightning::offers::offer::OfferId
690-
pub fn offer_id(&self) -> lightning::offers::offer::OfferId {
691-
self.inner.offer_id()
692-
}
693-
694-
/// Whether the offer this invoice corresponds to has expired.
695-
pub fn is_offer_expired(&self) -> bool {
696-
self.inner.is_offer_expired()
697-
}
698-
699-
/// Writes `self` out to a `Vec<u8>`.
700-
pub fn encode(&self) -> Vec<u8> {
701-
self.inner.encode()
702-
}
703-
}
704-
705-
impl Deref for StaticInvoice {
706-
type Target = LdkStaticInvoice;
707-
fn deref(&self) -> &Self::Target {
708-
&self.inner
709-
}
710-
}
711-
712-
impl AsRef<LdkStaticInvoice> for StaticInvoice {
713-
fn as_ref(&self) -> &LdkStaticInvoice {
714-
self.deref()
715-
}
716-
}
717-
718-
impl From<LdkStaticInvoice> for StaticInvoice {
719-
fn from(invoice: LdkStaticInvoice) -> Self {
720-
StaticInvoice { inner: invoice }
721-
}
722-
}
723-
724630
/// Represents a BOLT12 invoice that was paid.
725631
///
726632
/// This is used in [`Event::PaymentSuccessful`] to provide proof of payment for BOLT12 payments.
@@ -729,19 +635,19 @@ mod invoice_types {
729635
#[derive(Debug, Clone, PartialEq, Eq)]
730636
pub enum PaidBolt12Invoice {
731637
/// A standard BOLT12 invoice.
732-
Bolt12Invoice(Arc<Bolt12Invoice>),
638+
Bolt12Invoice(Arc<LdkBolt12Invoice>),
733639
/// A static invoice for async payments.
734-
StaticInvoice(Arc<StaticInvoice>),
640+
StaticInvoice(Arc<LdkStaticInvoice>),
735641
}
736642

737643
impl From<LdkPaidBolt12Invoice> for PaidBolt12Invoice {
738644
fn from(ldk_invoice: LdkPaidBolt12Invoice) -> Self {
739645
match ldk_invoice {
740646
LdkPaidBolt12Invoice::Bolt12Invoice(invoice) => {
741-
PaidBolt12Invoice::Bolt12Invoice(Arc::new(Bolt12Invoice { inner: invoice }))
647+
PaidBolt12Invoice::Bolt12Invoice(Arc::new(invoice))
742648
},
743649
LdkPaidBolt12Invoice::StaticInvoice(invoice) => {
744-
PaidBolt12Invoice::StaticInvoice(Arc::new(StaticInvoice { inner: invoice }))
650+
PaidBolt12Invoice::StaticInvoice(Arc::new(invoice))
745651
},
746652
}
747653
}
@@ -752,11 +658,11 @@ mod invoice_types {
752658
match self {
753659
PaidBolt12Invoice::Bolt12Invoice(invoice) => {
754660
0u8.write(writer)?;
755-
invoice.inner.encode().write(writer)?;
661+
invoice.encode().write(writer)?;
756662
},
757663
PaidBolt12Invoice::StaticInvoice(invoice) => {
758664
1u8.write(writer)?;
759-
invoice.inner.encode().write(writer)?;
665+
invoice.encode().write(writer)?;
760666
},
761667
}
762668
Ok(())
@@ -771,12 +677,12 @@ mod invoice_types {
771677
0 => {
772678
let invoice =
773679
LdkBolt12Invoice::try_from(bytes).map_err(|_| DecodeError::InvalidValue)?;
774-
Ok(PaidBolt12Invoice::Bolt12Invoice(Arc::new(Bolt12Invoice { inner: invoice })))
680+
Ok(PaidBolt12Invoice::Bolt12Invoice(Arc::new(invoice)))
775681
},
776682
1 => {
777683
let invoice =
778684
LdkStaticInvoice::try_from(bytes).map_err(|_| DecodeError::InvalidValue)?;
779-
Ok(PaidBolt12Invoice::StaticInvoice(Arc::new(StaticInvoice { inner: invoice })))
685+
Ok(PaidBolt12Invoice::StaticInvoice(Arc::new(invoice)))
780686
},
781687
_ => Err(DecodeError::InvalidValue),
782688
}

0 commit comments

Comments
 (0)