-/// Some information provided on receipt of payment depends on whether the payment received is a
-/// spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
-#[must_use]
-#[derive(Clone)]
-#[repr(C)]
-pub enum PaymentPurpose {
- /// Information for receiving a payment that we generated an invoice for.
- InvoicePayment {
- /// The preimage to the payment_hash, if the payment hash (and secret) were fetched via
- /// [`ChannelManager::create_inbound_payment`]. If provided, this can be handed directly to
- /// [`ChannelManager::claim_funds`].
- ///
- /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
- /// [`ChannelManager::claim_funds`]: crate::ln::channelmanager::ChannelManager::claim_funds
- ///
- /// Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
- payment_preimage: crate::c_types::ThirtyTwoBytes,
- /// The \"payment secret\". This authenticates the sender to the recipient, preventing a
- /// number of deanonymization attacks during the routing process.
- /// It is provided here for your reference, however its accuracy is enforced directly by
- /// [`ChannelManager`] using the values you previously provided to
- /// [`ChannelManager::create_inbound_payment`] or
- /// [`ChannelManager::create_inbound_payment_for_hash`].
- ///
- /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
- /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
- /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
- payment_secret: crate::c_types::ThirtyTwoBytes,
- /// This is the `user_payment_id` which was provided to
- /// [`ChannelManager::create_inbound_payment_for_hash`] or
- /// [`ChannelManager::create_inbound_payment`]. It has no meaning inside of LDK and is
- /// simply copied here. It may be used to correlate PaymentReceived events with invoice
- /// metadata stored elsewhere.
- ///
- /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
- /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
- user_payment_id: u64,
- },
- /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
- /// (the payee) providing a preimage.
- SpontaneousPayment(crate::c_types::ThirtyTwoBytes),
-}
-use lightning::util::events::PaymentPurpose as nativePaymentPurpose;
-impl PaymentPurpose {
- #[allow(unused)]
- pub(crate) fn to_native(&self) -> nativePaymentPurpose {
- match self {
- PaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, ref user_payment_id, } => {
- let mut payment_preimage_nonref = (*payment_preimage).clone();
- let mut local_payment_preimage_nonref = if payment_preimage_nonref.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage_nonref.data) }) };
- let mut payment_secret_nonref = (*payment_secret).clone();
- let mut user_payment_id_nonref = (*user_payment_id).clone();
- nativePaymentPurpose::InvoicePayment {
- payment_preimage: local_payment_preimage_nonref,
- payment_secret: ::lightning::ln::PaymentSecret(payment_secret_nonref.data),
- user_payment_id: user_payment_id_nonref,
- }
- },
- PaymentPurpose::SpontaneousPayment (ref a, ) => {
- let mut a_nonref = (*a).clone();
- nativePaymentPurpose::SpontaneousPayment (
- ::lightning::ln::PaymentPreimage(a_nonref.data),
- )
- },
- }
- }
- #[allow(unused)]
- pub(crate) fn into_native(self) -> nativePaymentPurpose {
- match self {
- PaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => {
- let mut local_payment_preimage = if payment_preimage.data == [0; 32] { None } else { Some( { ::lightning::ln::PaymentPreimage(payment_preimage.data) }) };
- nativePaymentPurpose::InvoicePayment {
- payment_preimage: local_payment_preimage,
- payment_secret: ::lightning::ln::PaymentSecret(payment_secret.data),
- user_payment_id: user_payment_id,
- }
- },
- PaymentPurpose::SpontaneousPayment (mut a, ) => {
- nativePaymentPurpose::SpontaneousPayment (
- ::lightning::ln::PaymentPreimage(a.data),
- )
- },
- }
- }
- #[allow(unused)]
- pub(crate) fn from_native(native: &nativePaymentPurpose) -> Self {
- match native {
- nativePaymentPurpose::InvoicePayment {ref payment_preimage, ref payment_secret, ref user_payment_id, } => {
- let mut payment_preimage_nonref = (*payment_preimage).clone();
- let mut local_payment_preimage_nonref = if payment_preimage_nonref.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_preimage_nonref.unwrap()).0 } } };
- let mut payment_secret_nonref = (*payment_secret).clone();
- let mut user_payment_id_nonref = (*user_payment_id).clone();
- PaymentPurpose::InvoicePayment {
- payment_preimage: local_payment_preimage_nonref,
- payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret_nonref.0 },
- user_payment_id: user_payment_id_nonref,
- }
- },
- nativePaymentPurpose::SpontaneousPayment (ref a, ) => {
- let mut a_nonref = (*a).clone();
- PaymentPurpose::SpontaneousPayment (
- crate::c_types::ThirtyTwoBytes { data: a_nonref.0 },
- )
- },
- }
- }
- #[allow(unused)]
- pub(crate) fn native_into(native: nativePaymentPurpose) -> Self {
- match native {
- nativePaymentPurpose::InvoicePayment {mut payment_preimage, mut payment_secret, mut user_payment_id, } => {
- let mut local_payment_preimage = if payment_preimage.is_none() { crate::c_types::ThirtyTwoBytes::null() } else { { crate::c_types::ThirtyTwoBytes { data: (payment_preimage.unwrap()).0 } } };
- PaymentPurpose::InvoicePayment {
- payment_preimage: local_payment_preimage,
- payment_secret: crate::c_types::ThirtyTwoBytes { data: payment_secret.0 },
- user_payment_id: user_payment_id,
- }
- },
- nativePaymentPurpose::SpontaneousPayment (mut a, ) => {
- PaymentPurpose::SpontaneousPayment (
- crate::c_types::ThirtyTwoBytes { data: a.0 },
- )
- },
- }
- }
-}
-/// Frees any resources used by the PaymentPurpose
-#[no_mangle]
-pub extern "C" fn PaymentPurpose_free(this_ptr: PaymentPurpose) { }
-/// Creates a copy of the PaymentPurpose
-#[no_mangle]
-pub extern "C" fn PaymentPurpose_clone(orig: &PaymentPurpose) -> PaymentPurpose {
- orig.clone()
-}
-#[no_mangle]
-/// Utility method to constructs a new InvoicePayment-variant PaymentPurpose
-pub extern "C" fn PaymentPurpose_invoice_payment(payment_preimage: crate::c_types::ThirtyTwoBytes, payment_secret: crate::c_types::ThirtyTwoBytes, user_payment_id: u64) -> PaymentPurpose {
- PaymentPurpose::InvoicePayment {
- payment_preimage,
- payment_secret,
- user_payment_id,
- }
-}
-#[no_mangle]
-/// Utility method to constructs a new SpontaneousPayment-variant PaymentPurpose
-pub extern "C" fn PaymentPurpose_spontaneous_payment(a: crate::c_types::ThirtyTwoBytes) -> PaymentPurpose {
- PaymentPurpose::SpontaneousPayment(a, )
-}