|
17 | 17 | use crate::chain::keysinterface::SpendableOutputDescriptor;
|
18 | 18 | #[cfg(anchors)]
|
19 | 19 | use crate::ln::chan_utils::HTLCOutputInCommitment;
|
20 |
| -use crate::ln::channelmanager::PaymentId; |
| 20 | +use crate::ln::channelmanager::{InterceptId, PaymentId}; |
21 | 21 | use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
|
22 | 22 | use crate::ln::features::ChannelTypeFeatures;
|
23 | 23 | use crate::ln::msgs;
|
@@ -566,6 +566,20 @@ pub enum Event {
|
566 | 566 | /// now + 5*time_forwardable).
|
567 | 567 | time_forwardable: Duration,
|
568 | 568 | },
|
| 569 | + /// Used to indicate that we've received a forwardable payment that should be intercepted. |
| 570 | + PaymentIntercepted { |
| 571 | + /// The scid that indicated this payment should be intercepted |
| 572 | + short_channel_id: u64, |
| 573 | + /// The payment hash used for this payment |
| 574 | + payment_hash: PaymentHash, |
| 575 | + /// How many msats are to be received on the inbound edge of this payment |
| 576 | + inbound_amount_msat: u64, |
| 577 | + /// How many msats the payer intended to route to the next node. Depending on the reason you are |
| 578 | + /// intercepting this payment, you might take a fee by forwarding less than this amount |
| 579 | + expected_outbound_amount_msat: u64, |
| 580 | + /// A id to help LDK identify which payment is being forwarded or failed |
| 581 | + intercept_id: InterceptId |
| 582 | + }, |
569 | 583 | /// Used to indicate that an output which you should know how to spend was confirmed on chain
|
570 | 584 | /// and is now spendable.
|
571 | 585 | /// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
|
@@ -896,6 +910,16 @@ impl Writeable for Event {
|
896 | 910 | (6, channel_type, required),
|
897 | 911 | });
|
898 | 912 | },
|
| 913 | + &Event::PaymentIntercepted { short_channel_id, payment_hash, inbound_amount_msat: inbound_amount_msats, expected_outbound_amount_msat: expected_outbound_amount_msats, intercept_id } => { |
| 914 | + 31u8.write(writer)?; |
| 915 | + write_tlv_fields!(writer, { |
| 916 | + (0, short_channel_id, required), |
| 917 | + (2, payment_hash, required), |
| 918 | + (4, inbound_amount_msats, required), |
| 919 | + (6, expected_outbound_amount_msats, required), |
| 920 | + (8, intercept_id, required) |
| 921 | + }); |
| 922 | + } |
899 | 923 | // Note that, going forward, all new events must only write data inside of
|
900 | 924 | // `write_tlv_fields`. Versions 0.0.101+ will ignore odd-numbered events that write
|
901 | 925 | // data via `write_tlv_fields`.
|
@@ -1199,6 +1223,27 @@ impl MaybeReadable for Event {
|
1199 | 1223 | };
|
1200 | 1224 | f()
|
1201 | 1225 | },
|
| 1226 | + 31u8 => { |
| 1227 | + let mut payment_hash = PaymentHash([0; 32]); |
| 1228 | + let mut intercept_id = InterceptId([0; 32]); |
| 1229 | + let mut short_channel_id = 0; |
| 1230 | + let mut inbound_amount_msats = 0; |
| 1231 | + let mut expected_outbound_amount_msats = 0; |
| 1232 | + read_tlv_fields!(reader, { |
| 1233 | + (0, short_channel_id, required), |
| 1234 | + (2, payment_hash, required), |
| 1235 | + (4, inbound_amount_msats, required), |
| 1236 | + (6, expected_outbound_amount_msats, required), |
| 1237 | + (8, intercept_id, required) |
| 1238 | + }); |
| 1239 | + Ok(Some(Event::PaymentIntercepted { |
| 1240 | + payment_hash, |
| 1241 | + short_channel_id, |
| 1242 | + inbound_amount_msat: inbound_amount_msats, |
| 1243 | + expected_outbound_amount_msat: expected_outbound_amount_msats, |
| 1244 | + intercept_id, |
| 1245 | + })) |
| 1246 | + }, |
1202 | 1247 | // Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
|
1203 | 1248 | // Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
|
1204 | 1249 | // reads.
|
|
0 commit comments