]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Provide users the payment metadata via `Event::PaymentReceived`
authorMatt Corallo <git@bluematt.me>
Tue, 21 Dec 2021 20:38:24 +0000 (20:38 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 26 Jan 2022 19:09:13 +0000 (19:09 +0000)
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_tests.rs
lightning/src/util/events.rs

index 3817fcdb73e2985ba704f503cd491a943285bc85..841eaa6c3bf1206c04c880ba4008130fd0d2ff4c 100644 (file)
@@ -3260,6 +3260,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
                                                                                                payment_hash,
                                                                                                purpose: events::PaymentPurpose::InvoicePayment {
                                                                                                        payment_preimage: $payment_preimage,
+                                                                                                       payment_metadata: $payment_data.payment_metadata,
                                                                                                        payment_secret: $payment_data.payment_secret,
                                                                                                },
                                                                                                amt: total_value,
index b896e0dbe8fd5388f045d8e1bfdf020bb791bdf8..cdca9a8ce9fb32b9ede10a303ba083772fbe48f7 100644 (file)
@@ -8295,10 +8295,11 @@ fn test_secret_timeout() {
        expect_pending_htlcs_forwardable!(nodes[1]);
        let events = nodes[1].node.get_and_clear_pending_events();
        assert_eq!(events.len(), 1);
-       match events[0] {
-               Event::PaymentReceived { purpose: PaymentPurpose::InvoicePayment { payment_preimage, payment_secret }, .. } => {
+       match &events[0] {
+               Event::PaymentReceived { purpose: PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, payment_metadata }, .. } => {
                        assert!(payment_preimage.is_none());
-                       assert_eq!(payment_secret, our_payment_secret);
+                       assert!(payment_metadata.is_none());
+                       assert_eq!(*payment_secret, our_payment_secret);
                        // We don't actually have the payment preimage with which to claim this payment!
                },
                _ => panic!("Unexpected event"),
index a4a733c8e503eff05212d6570ada728a4cb95c1e..e2c8625310064716c52d23c296853fa68d428bdd 100644 (file)
@@ -60,6 +60,8 @@ pub enum PaymentPurpose {
                /// [`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,
+               ///XXX
+               payment_metadata: Option<Vec<u8>>,
        },
        /// Because this is a spontaneous payment, the payer generated their own preimage rather than us
        /// (the payee) providing a preimage.
@@ -417,10 +419,12 @@ impl Writeable for Event {
                                1u8.write(writer)?;
                                let mut payment_secret = None;
                                let payment_preimage;
+                               let mut payment_metadata = None;
                                match &purpose {
-                                       PaymentPurpose::InvoicePayment { payment_preimage: preimage, payment_secret: secret } => {
+                                       PaymentPurpose::InvoicePayment { payment_preimage: preimage, payment_secret: secret, payment_metadata: metadata } => {
                                                payment_secret = Some(secret);
                                                payment_preimage = *preimage;
+                                               payment_metadata = metadata.as_ref();
                                        },
                                        PaymentPurpose::SpontaneousPayment(preimage) => {
                                                payment_preimage = Some(*preimage);
@@ -428,6 +432,7 @@ impl Writeable for Event {
                                }
                                write_tlv_fields!(writer, {
                                        (0, payment_hash, required),
+                                       (1, payment_metadata, option),
                                        (2, payment_secret, option),
                                        (4, amt, required),
                                        (6, 0u64, required), // user_payment_id required for compatibility with 0.0.103 and earlier
@@ -533,10 +538,12 @@ impl MaybeReadable for Event {
                                        let mut payment_hash = PaymentHash([0; 32]);
                                        let mut payment_preimage = None;
                                        let mut payment_secret = None;
+                                       let mut payment_metadata = None;
                                        let mut amt = 0;
                                        let mut _user_payment_id = None::<u64>; // For compatibility with 0.0.103 and earlier
                                        read_tlv_fields!(reader, {
                                                (0, payment_hash, required),
+                                               (1, payment_metadata, option),
                                                (2, payment_secret, option),
                                                (4, amt, required),
                                                (6, _user_payment_id, option),
@@ -545,8 +552,10 @@ impl MaybeReadable for Event {
                                        let purpose = match payment_secret {
                                                Some(secret) => PaymentPurpose::InvoicePayment {
                                                        payment_preimage,
+                                                       payment_metadata,
                                                        payment_secret: secret
                                                },
+                                               None if payment_metadata.is_some() => return Err(msgs::DecodeError::InvalidValue),
                                                None if payment_preimage.is_some() => PaymentPurpose::SpontaneousPayment(payment_preimage.unwrap()),
                                                None => return Err(msgs::DecodeError::InvalidValue),
                                        };