Skip to content

Commit 32ce6bc

Browse files
types: convert non-uniffi PaidBolt12Invoice to enum
This patch updates the non-uniffi version of PaidBolt12Invoice to use the same enum structure as the uniffi version, ensuring consistency across the codebase. Problem: The non-uniffi implementation still used the old struct-based approach with a kind field and optional invoice fields, while the uniffi version was updated to use a proper enum. This inconsistency would cause confusion and potential bugs. Solution: Update the non-uniffi PaidBolt12Invoice to be a proper enum with Bolt12Invoice and StaticInvoice variants, matching the uniffi version. Also update the doc comment in event.rs to reference the new enum variant path. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 86f8905 commit 32ce6bc

File tree

2 files changed

+19
-48
lines changed

2 files changed

+19
-48
lines changed

src/event.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ pub enum Event {
8484
///
8585
/// Will be `None` for non-BOLT12 payments.
8686
///
87-
/// Note that static invoices (indicated by [`crate::payment::PaidBolt12InvoiceKind::StaticInvoice`],
88-
/// used for async payments) do not support proof of payment as the payment hash is not
89-
/// derived from a preimage known only to the recipient.
87+
/// Note that static invoices (indicated by [`PaidBolt12Invoice::StaticInvoice`], used for
88+
/// async payments) do not support proof of payment as the payment hash is not derived
89+
/// from a preimage known only to the recipient.
9090
bolt12_invoice: Option<PaidBolt12Invoice>,
9191
},
9292
/// A sent payment has failed.

src/types.rs

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -721,63 +721,42 @@ mod invoice_types {
721721
}
722722
}
723723

724-
/// The kind of [`PaidBolt12Invoice`].
725-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
726-
pub enum PaidBolt12InvoiceKind {
727-
/// A standard BOLT12 invoice.
728-
Bolt12Invoice,
729-
/// A static invoice for async payments.
730-
StaticInvoice,
731-
}
732-
733724
/// Represents a BOLT12 invoice that was paid.
734725
///
735726
/// This is used in [`Event::PaymentSuccessful`] to provide proof of payment for BOLT12 payments.
736727
///
737728
/// [`Event::PaymentSuccessful`]: crate::Event::PaymentSuccessful
738729
#[derive(Debug, Clone, PartialEq, Eq)]
739-
pub struct PaidBolt12Invoice {
740-
/// The kind of invoice that was paid.
741-
pub kind: PaidBolt12InvoiceKind,
742-
/// The paid BOLT12 invoice, if this is a regular BOLT12 invoice.
743-
pub bolt12_invoice: Option<Arc<Bolt12Invoice>>,
744-
/// The paid static invoice, if this is a static invoice (async payment).
745-
pub static_invoice: Option<Arc<StaticInvoice>>,
730+
pub enum PaidBolt12Invoice {
731+
/// A standard BOLT12 invoice.
732+
Bolt12Invoice(Arc<Bolt12Invoice>),
733+
/// A static invoice for async payments.
734+
StaticInvoice(Arc<StaticInvoice>),
746735
}
747736

748737
impl From<LdkPaidBolt12Invoice> for PaidBolt12Invoice {
749738
fn from(ldk_invoice: LdkPaidBolt12Invoice) -> Self {
750739
match ldk_invoice {
751-
LdkPaidBolt12Invoice::Bolt12Invoice(invoice) => PaidBolt12Invoice {
752-
kind: PaidBolt12InvoiceKind::Bolt12Invoice,
753-
bolt12_invoice: Some(Arc::new(Bolt12Invoice { inner: invoice })),
754-
static_invoice: None,
740+
LdkPaidBolt12Invoice::Bolt12Invoice(invoice) => {
741+
PaidBolt12Invoice::Bolt12Invoice(Arc::new(Bolt12Invoice { inner: invoice }))
755742
},
756-
LdkPaidBolt12Invoice::StaticInvoice(invoice) => PaidBolt12Invoice {
757-
kind: PaidBolt12InvoiceKind::StaticInvoice,
758-
bolt12_invoice: None,
759-
static_invoice: Some(Arc::new(StaticInvoice { inner: invoice })),
743+
LdkPaidBolt12Invoice::StaticInvoice(invoice) => {
744+
PaidBolt12Invoice::StaticInvoice(Arc::new(StaticInvoice { inner: invoice }))
760745
},
761746
}
762747
}
763748
}
764749

765750
impl Writeable for PaidBolt12Invoice {
766751
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), lightning::io::Error> {
767-
match self.kind {
768-
PaidBolt12InvoiceKind::Bolt12Invoice => {
752+
match self {
753+
PaidBolt12Invoice::Bolt12Invoice(invoice) => {
769754
0u8.write(writer)?;
770-
if let Some(invoice) = &self.bolt12_invoice {
771-
let bytes = invoice.inner.encode();
772-
bytes.write(writer)?;
773-
}
755+
invoice.inner.encode().write(writer)?;
774756
},
775-
PaidBolt12InvoiceKind::StaticInvoice => {
757+
PaidBolt12Invoice::StaticInvoice(invoice) => {
776758
1u8.write(writer)?;
777-
if let Some(invoice) = &self.static_invoice {
778-
let bytes = invoice.inner.encode();
779-
bytes.write(writer)?;
780-
}
759+
invoice.inner.encode().write(writer)?;
781760
},
782761
}
783762
Ok(())
@@ -792,20 +771,12 @@ mod invoice_types {
792771
0 => {
793772
let invoice =
794773
LdkBolt12Invoice::try_from(bytes).map_err(|_| DecodeError::InvalidValue)?;
795-
Ok(PaidBolt12Invoice {
796-
kind: PaidBolt12InvoiceKind::Bolt12Invoice,
797-
bolt12_invoice: Some(Arc::new(Bolt12Invoice { inner: invoice })),
798-
static_invoice: None,
799-
})
774+
Ok(PaidBolt12Invoice::Bolt12Invoice(Arc::new(Bolt12Invoice { inner: invoice })))
800775
},
801776
1 => {
802777
let invoice =
803778
LdkStaticInvoice::try_from(bytes).map_err(|_| DecodeError::InvalidValue)?;
804-
Ok(PaidBolt12Invoice {
805-
kind: PaidBolt12InvoiceKind::StaticInvoice,
806-
bolt12_invoice: None,
807-
static_invoice: Some(Arc::new(StaticInvoice { inner: invoice })),
808-
})
779+
Ok(PaidBolt12Invoice::StaticInvoice(Arc::new(StaticInvoice { inner: invoice })))
809780
},
810781
_ => Err(DecodeError::InvalidValue),
811782
}

0 commit comments

Comments
 (0)