Skip to content

Commit 8c1472d

Browse files
committed
Add non-legacy blinded Trampoline payloads.
1 parent 41e36e4 commit 8c1472d

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

lightning/src/ln/msgs.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,7 @@ mod fuzzy_internal_msgs {
18301830
}
18311831
}
18321832

1833-
pub(crate) enum OutboundTrampolinePayload {
1833+
pub(crate) enum OutboundTrampolinePayload<'a> {
18341834
#[allow(unused)]
18351835
Forward {
18361836
/// The value, in msat, of the payment after this hop's fee is deducted.
@@ -1851,6 +1851,21 @@ mod fuzzy_internal_msgs {
18511851
/// If applicable, features of the BOLT12 invoice being paid.
18521852
invoice_features: Option<Bolt12InvoiceFeatures>,
18531853
},
1854+
#[allow(unused)]
1855+
BlindedForward {
1856+
encrypted_tlvs: &'a Vec<u8>,
1857+
intro_node_blinding_point: Option<PublicKey>,
1858+
},
1859+
#[allow(unused)]
1860+
BlindedReceive {
1861+
sender_intended_htlc_amt_msat: u64,
1862+
total_msat: u64,
1863+
cltv_expiry_height: u32,
1864+
encrypted_tlvs: &'a Vec<u8>,
1865+
intro_node_blinding_point: Option<PublicKey>, // Set if the introduction node of the blinded path is the final node
1866+
keysend_preimage: Option<PaymentPreimage>,
1867+
custom_tlvs: &'a Vec<(u64, Vec<u8>)>,
1868+
}
18541869
}
18551870

18561871
pub struct DecodedOnionErrorPacket {
@@ -2766,7 +2781,7 @@ impl<'a> Writeable for OutboundOnionPayload<'a> {
27662781
}
27672782
}
27682783

2769-
impl Writeable for OutboundTrampolinePayload {
2784+
impl<'a> Writeable for OutboundTrampolinePayload<'a> {
27702785
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
27712786
match self {
27722787
Self::Forward { amt_to_forward, outgoing_cltv_value, outgoing_node_id } => {
@@ -2789,6 +2804,24 @@ impl Writeable for OutboundTrampolinePayload {
27892804
(21, invoice_features.as_ref().map(|m| WithoutLength(m)), option)
27902805
}, custom_tlvs.iter());
27912806
},
2807+
Self::BlindedForward { encrypted_tlvs, intro_node_blinding_point} => {
2808+
_encode_varint_length_prefixed_tlv!(w, {
2809+
(10, **encrypted_tlvs, required_vec),
2810+
(12, intro_node_blinding_point, option)
2811+
});
2812+
},
2813+
Self::BlindedReceive { sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, encrypted_tlvs, intro_node_blinding_point, keysend_preimage, custom_tlvs } => {
2814+
let keysend_tlv = keysend_preimage.map(|preimage| (5482373484, preimage.encode()));
2815+
let mut custom_tlvs: Vec<&(u64, Vec<u8>)> = custom_tlvs.iter().chain(keysend_tlv.iter()).collect();
2816+
custom_tlvs.sort_unstable_by_key(|(typ, _)| *typ);
2817+
_encode_varint_length_prefixed_tlv!(w, {
2818+
(2, HighZeroBytesDroppedBigSize(*sender_intended_htlc_amt_msat), required),
2819+
(4, HighZeroBytesDroppedBigSize(*cltv_expiry_height), required),
2820+
(10, **encrypted_tlvs, required_vec),
2821+
(12, intro_node_blinding_point, option),
2822+
(18, HighZeroBytesDroppedBigSize(*total_msat), required)
2823+
}, custom_tlvs.iter());
2824+
}
27922825
}
27932826
Ok(())
27942827
}

0 commit comments

Comments
 (0)