let events_3 = nodes[1].node.get_and_clear_pending_events();
assert_eq!(events_3.len(), 1);
match events_3[0] {
- Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => {
+ Event::PaymentReceived { ref payment_hash, ref payment_preimage, ref payment_secret, amt, user_payment_id: _ } => {
assert_eq!(payment_hash_1, *payment_hash);
+ assert!(payment_preimage.is_none());
assert_eq!(payment_secret_1, *payment_secret);
assert_eq!(amt, 1000000);
},
let events_5 = nodes[1].node.get_and_clear_pending_events();
assert_eq!(events_5.len(), 1);
match events_5[0] {
- Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => {
+ Event::PaymentReceived { ref payment_hash, ref payment_preimage, ref payment_secret, amt, user_payment_id: _ } => {
assert_eq!(payment_hash_2, *payment_hash);
+ assert!(payment_preimage.is_none());
assert_eq!(payment_secret_2, *payment_secret);
assert_eq!(amt, 1000000);
},
let events = nodes[1].node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
match events[0] {
- Event::PaymentReceived { payment_hash, payment_secret, amt, user_payment_id: _ } => {
+ Event::PaymentReceived { payment_hash, payment_preimage, payment_secret, amt, user_payment_id: _ } => {
assert_eq!(payment_hash, our_payment_hash);
+ assert!(payment_preimage.is_none());
assert_eq!(our_payment_secret, payment_secret);
assert_eq!(amt, 1000000);
},
} else if total_value == payment_data.total_msat {
new_events.push(events::Event::PaymentReceived {
payment_hash,
+ payment_preimage: inbound_payment.get().payment_preimage,
payment_secret: payment_data.payment_secret,
amt: total_value,
user_payment_id: inbound_payment.get().user_payment_id,
/// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
/// [`PaymentHash`] and [`PaymentPreimage`] for you, returning the first and storing the second.
///
+ /// The [`PaymentPreimage`] will ultimately be returned to you in the [`PaymentReceived`], which
+ /// will have the [`PaymentReceived::payment_preimage`] field filled in. That should then be
+ /// passed directly to [`claim_funds`].
+ ///
/// See [`create_inbound_payment_for_hash`] for detailed documentation on behavior and requirements.
///
+ /// [`claim_funds`]: Self::claim_funds
+ /// [`PaymentReceived`]: events::Event::PaymentReceived
+ /// [`PaymentReceived::payment_preimage`]: events::Event::PaymentReceived::payment_preimage
/// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
pub fn create_inbound_payment(&self, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32, user_payment_id: u64) -> (PaymentHash, PaymentSecret) {
let payment_preimage = PaymentPreimage(self.keys_manager.get_secure_random_bytes());
let events = $node.node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
match events[0] {
- Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => {
+ Event::PaymentReceived { ref payment_hash, ref payment_preimage, ref payment_secret, amt, user_payment_id: _ } => {
assert_eq!($expected_payment_hash, *payment_hash);
+ assert!(payment_preimage.is_none());
assert_eq!($expected_payment_secret, *payment_secret);
assert_eq!($expected_recv_value, amt);
},
if payment_received_expected {
assert_eq!(events_2.len(), 1);
match events_2[0] {
- Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => {
+ Event::PaymentReceived { ref payment_hash, ref payment_preimage, ref payment_secret, amt, user_payment_id: _ } => {
assert_eq!(our_payment_hash, *payment_hash);
+ assert!(payment_preimage.is_none());
assert_eq!(our_payment_secret, *payment_secret);
assert_eq!(amt, recv_value);
},
let events = nodes[2].node.get_and_clear_pending_events();
assert_eq!(events.len(), 2);
match events[0] {
- Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => {
+ Event::PaymentReceived { ref payment_hash, ref payment_preimage, ref payment_secret, amt, user_payment_id: _ } => {
assert_eq!(our_payment_hash_21, *payment_hash);
+ assert!(payment_preimage.is_none());
assert_eq!(our_payment_secret_21, *payment_secret);
assert_eq!(recv_value_21, amt);
},
_ => panic!("Unexpected event"),
}
match events[1] {
- Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => {
+ Event::PaymentReceived { ref payment_hash, ref payment_preimage, ref payment_secret, amt, user_payment_id: _ } => {
assert_eq!(our_payment_hash_22, *payment_hash);
+ assert!(payment_preimage.is_none());
assert_eq!(our_payment_secret_22, *payment_secret);
assert_eq!(recv_value_22, amt);
},
let events_2 = nodes[1].node.get_and_clear_pending_events();
assert_eq!(events_2.len(), 1);
match events_2[0] {
- Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => {
+ Event::PaymentReceived { ref payment_hash, ref payment_preimage, ref payment_secret, amt, user_payment_id: _ } => {
assert_eq!(payment_hash_1, *payment_hash);
+ assert!(payment_preimage.is_none());
assert_eq!(payment_secret_1, *payment_secret);
assert_eq!(amt, 1000000);
},
let events_5 = nodes[1].node.get_and_clear_pending_events();
assert_eq!(events_5.len(), 1);
match events_5[0] {
- Event::PaymentReceived { ref payment_hash, ref payment_secret, amt: _, user_payment_id: _ } => {
+ Event::PaymentReceived { ref payment_hash, ref payment_preimage, ref payment_secret, amt: _, user_payment_id: _ } => {
assert_eq!(payment_hash_2, *payment_hash);
+ assert!(payment_preimage.is_none());
assert_eq!(payment_secret_2, *payment_secret);
},
_ => panic!("Unexpected event"),
PaymentReceived {
/// The hash for which the preimage should be handed to the ChannelManager.
payment_hash: PaymentHash,
+ /// 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
// We never write out FundingGenerationReady events as, upon disconnection, peers
// drop any channels which have not yet exchanged funding_signed.
},
- &Event::PaymentReceived { ref payment_hash, ref payment_secret, ref amt, ref user_payment_id } => {
+ &Event::PaymentReceived { ref payment_hash, ref payment_preimage, ref payment_secret, ref amt, ref user_payment_id } => {
1u8.write(writer)?;
payment_hash.write(writer)?;
+ payment_preimage.write(writer)?;
payment_secret.write(writer)?;
amt.write(writer)?;
user_payment_id.write(writer)?;
0u8 => Ok(None),
1u8 => Ok(Some(Event::PaymentReceived {
payment_hash: Readable::read(reader)?,
+ payment_preimage: Readable::read(reader)?,
payment_secret: Readable::read(reader)?,
amt: Readable::read(reader)?,
user_payment_id: Readable::read(reader)?,