+/// 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.
+#[derive(Clone, Debug)]
+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
+ payment_preimage: Option<PaymentPreimage>,
+ /// 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: PaymentSecret,
+ /// 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(PaymentPreimage),
+}
+
+#[derive(Clone, Debug)]
+pub enum ClosureDescriptor {
+ ForceClosed,
+ UserInitiated,
+ CounterpartyInitiated,
+ CooperativeClosure,
+ UnknownOnchainCommitment,
+ ProcessingError,
+ DisconnectedPeer,
+}
+
+impl Writeable for ClosureDescriptor {
+ fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
+ match self {
+ ClosureDescriptor::ForceClosed => 0u8.write(writer)?,
+ ClosureDescriptor::UserInitiated => 1u8.write(writer)?,
+ ClosureDescriptor::CounterpartyInitiated => 2u8.write(writer)?,
+ ClosureDescriptor::CooperativeClosure => 3u8.write(writer)?,
+ ClosureDescriptor::UnknownOnchainCommitment => 4u8.write(writer)?,
+ ClosureDescriptor::ProcessingError => 5u8.write(writer)?,
+ ClosureDescriptor::DisconnectedPeer => 6u8.write(writer)?,
+ }
+ Ok(())
+ }
+}
+
+impl Readable for ClosureDescriptor {
+ fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
+ Ok(match <u8 as Readable>::read(reader)? {
+ 0 => ClosureDescriptor::ForceClosed,
+ 1 => ClosureDescriptor::UserInitiated,
+ 2 => ClosureDescriptor::CounterpartyInitiated,
+ 3 => ClosureDescriptor::CooperativeClosure,
+ 4 => ClosureDescriptor::UnknownOnchainCommitment,
+ 5 => ClosureDescriptor::ProcessingError,
+ 6 => ClosureDescriptor::DisconnectedPeer,
+ _ => return Err(DecodeError::InvalidValue),
+ })
+ }
+}
+