X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fblinded_path%2Fpayment.rs;h=dfe89e0ebc6c34e6579fa1cea0ca79f4dc0b7672;hb=b8d4ac1371bf0db3b28339d4e12fadf02f6add3d;hp=ad7b229b53fa1c830d042d24a892360666bf5b65;hpb=09ce1b5d161b1369e47dd25ada95fcbdf6ce7139;p=rust-lightning diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index ad7b229b..dfe89e0e 100644 --- a/lightning/src/blinded_path/payment.rs +++ b/lightning/src/blinded_path/payment.rs @@ -7,11 +7,12 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey}; use crate::blinded_path::BlindedHop; use crate::blinded_path::utils; use crate::io; -use crate::ln::PaymentSecret; +use crate::ln::types::PaymentSecret; use crate::ln::channelmanager::CounterpartyForwardingInfo; use crate::ln::features::BlindedHopFeatures; use crate::ln::msgs::DecodeError; use crate::offers::invoice::BlindedPayInfo; +use crate::offers::invoice_request::InvoiceRequestFields; use crate::offers::offer::OfferId; use crate::util::ser::{HighZeroBytesDroppedBigSize, Readable, Writeable, Writer}; @@ -121,6 +122,12 @@ pub enum PaymentContext { Bolt12Refund(Bolt12RefundContext), } +// Used when writing PaymentContext in Event::PaymentClaimable to avoid cloning. +pub(crate) enum PaymentContextRef<'a> { + Bolt12Offer(&'a Bolt12OfferContext), + Bolt12Refund(&'a Bolt12RefundContext), +} + /// An unknown payment context. #[derive(Clone, Debug, Eq, PartialEq)] pub struct UnknownPaymentContext(()); @@ -134,6 +141,12 @@ pub struct Bolt12OfferContext { /// /// [`Offer`]: crate::offers::offer::Offer pub offer_id: OfferId, + + /// Fields from an [`InvoiceRequest`] sent for a [`Bolt12Invoice`]. + /// + /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest + /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice + pub invoice_request: InvoiceRequestFields, } /// The context of a payment made for an invoice sent for a BOLT 12 [`Refund`]. @@ -372,6 +385,23 @@ impl_writeable_tlv_based_enum!(PaymentContext, (2, Bolt12Refund), ); +impl<'a> Writeable for PaymentContextRef<'a> { + fn write(&self, w: &mut W) -> Result<(), io::Error> { + match self { + PaymentContextRef::Bolt12Offer(context) => { + 1u8.write(w)?; + context.write(w)?; + }, + PaymentContextRef::Bolt12Refund(context) => { + 2u8.write(w)?; + context.write(w)?; + }, + } + + Ok(()) + } +} + impl Writeable for UnknownPaymentContext { fn write(&self, _w: &mut W) -> Result<(), io::Error> { Ok(()) @@ -386,6 +416,7 @@ impl Readable for UnknownPaymentContext { impl_writeable_tlv_based!(Bolt12OfferContext, { (0, offer_id, required), + (2, invoice_request, required), }); impl_writeable_tlv_based!(Bolt12RefundContext, {}); @@ -394,7 +425,7 @@ impl_writeable_tlv_based!(Bolt12RefundContext, {}); mod tests { use bitcoin::secp256k1::PublicKey; use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, ReceiveTlvs, PaymentConstraints, PaymentContext, PaymentRelay}; - use crate::ln::PaymentSecret; + use crate::ln::types::PaymentSecret; use crate::ln::features::BlindedHopFeatures; use crate::ln::functional_test_utils::TEST_FINAL_CLTV;