]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add optional lifetime to tlv_stream macro
authorJeffrey Czyz <jkczyz@gmail.com>
Fri, 2 Aug 2024 16:54:42 +0000 (11:54 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Tue, 29 Oct 2024 23:31:43 +0000 (18:31 -0500)
Using the tlv_stream macro without a type needing a reference results in
a compilation error because of an unused lifetime parameter. To avoid
this, add an optional lifetime parameter to the macro. This allows for
experimental TLVs, which will be empty initially, and TLVs of entirely
primitive types.

lightning/src/offers/invoice.rs
lightning/src/offers/invoice_request.rs
lightning/src/offers/merkle.rs
lightning/src/offers/offer.rs
lightning/src/offers/payer.rs
lightning/src/util/ser_macros.rs

index 6cb37ab5339a8901c52eb81d7346022f546b3c2a..8fd9ab980fa95e4d64388e2ce40ff01ea01fff61 100644 (file)
@@ -1237,7 +1237,7 @@ impl TryFrom<Vec<u8>> for Bolt12Invoice {
 /// Valid type range for invoice TLV records.
 pub(super) const INVOICE_TYPES: core::ops::Range<u64> = 160..240;
 
-tlv_stream!(InvoiceTlvStream, InvoiceTlvStreamRef, INVOICE_TYPES, {
+tlv_stream!(InvoiceTlvStream, InvoiceTlvStreamRef<'a>, INVOICE_TYPES, {
        (160, paths: (Vec<BlindedPath>, WithoutLength, Iterable<'a, BlindedPathIter<'a>, BlindedPath>)),
        (162, blindedpay: (Vec<BlindedPayInfo>, WithoutLength, Iterable<'a, BlindedPayInfoIter<'a>, BlindedPayInfo>)),
        (164, created_at: (u64, HighZeroBytesDroppedBigSize)),
index e33ccb61606dd61489c98035058ff6ab7ee7abbc..4d5c37bbaa993d0419f884d5a7d5aed0e22bdf9c 100644 (file)
@@ -1061,7 +1061,7 @@ pub(super) const INVOICE_REQUEST_PAYER_ID_TYPE: u64 = 88;
 
 // This TLV stream is used for both InvoiceRequest and Refund, but not all TLV records are valid for
 // InvoiceRequest as noted below.
-tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef, INVOICE_REQUEST_TYPES, {
+tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef<'a>, INVOICE_REQUEST_TYPES, {
        (80, chain: ChainHash),
        (82, amount: (u64, HighZeroBytesDroppedBigSize)),
        (84, features: (InvoiceRequestFeatures, WithoutLength)),
index e2fed2e800b367a76943c819b26af5ebf6a67290..15d6aababde5bba0adb9badac86a9a567cf26dc9 100644 (file)
@@ -21,7 +21,7 @@ use crate::prelude::*;
 /// Valid type range for signature TLV records.
 const SIGNATURE_TYPES: core::ops::RangeInclusive<u64> = 240..=1000;
 
-tlv_stream!(SignatureTlvStream, SignatureTlvStreamRef, SIGNATURE_TYPES, {
+tlv_stream!(SignatureTlvStream, SignatureTlvStreamRef<'a>, SIGNATURE_TYPES, {
        (240, signature: Signature),
 });
 
index 546d42b88487afde98ed5e40a6d447865fc58046..4caa3757a349df51f667e1a5831e724142e8031f 100644 (file)
@@ -1077,7 +1077,7 @@ const OFFER_METADATA_TYPE: u64 = 4;
 /// TLV record type for [`Offer::issuer_signing_pubkey`].
 const OFFER_ISSUER_ID_TYPE: u64 = 22;
 
-tlv_stream!(OfferTlvStream, OfferTlvStreamRef, OFFER_TYPES, {
+tlv_stream!(OfferTlvStream, OfferTlvStreamRef<'a>, OFFER_TYPES, {
        (2, chains: (Vec<ChainHash>, WithoutLength)),
        (OFFER_METADATA_TYPE, metadata: (Vec<u8>, WithoutLength)),
        (6, currency: CurrencyCode),
index 0ec5721dc3846e8a0bf4d013abe8885bbaa4696b..696eac240448aab6602cc16a427c4d4f0d996674 100644 (file)
@@ -30,6 +30,6 @@ pub(super) struct PayerContents(pub Metadata);
 /// [`Refund::payer_metadata`]: crate::offers::refund::Refund::payer_metadata
 pub(super) const PAYER_METADATA_TYPE: u64 = 0;
 
-tlv_stream!(PayerTlvStream, PayerTlvStreamRef, 0..1, {
+tlv_stream!(PayerTlvStream, PayerTlvStreamRef<'a>, 0..1, {
        (PAYER_METADATA_TYPE, metadata: (Vec<u8>, WithoutLength)),
 });
index d4428697b4d5b194a207598f43f7f4fc9293b037..0703aac9e8466b380bea1c4655ba06d6fe6a6762 100644 (file)
@@ -952,7 +952,7 @@ macro_rules! impl_writeable_tlv_based {
 /// [`Readable`]: crate::util::ser::Readable
 /// [`Writeable`]: crate::util::ser::Writeable
 macro_rules! tlv_stream {
-       ($name:ident, $nameref:ident, $range:expr, {
+       ($name:ident, $nameref:ident $(<$lifetime:lifetime>)?, $range:expr, {
                $(($type:expr, $field:ident : $fieldty:tt)),* $(,)*
        }) => {
                #[derive(Debug)]
@@ -964,13 +964,13 @@ macro_rules! tlv_stream {
 
                #[cfg_attr(test, derive(PartialEq))]
                #[derive(Debug)]
-               pub(crate) struct $nameref<'a> {
+               pub(crate) struct $nameref<$($lifetime)*> {
                        $(
                                pub(super) $field: Option<tlv_record_ref_type!($fieldty)>,
                        )*
                }
 
-               impl<'a> $crate::util::ser::Writeable for $nameref<'a> {
+               impl<$($lifetime)*> $crate::util::ser::Writeable for $nameref<$($lifetime)*> {
                        fn write<W: $crate::util::ser::Writer>(&self, writer: &mut W) -> Result<(), $crate::io::Error> {
                                encode_tlv_stream!(writer, {
                                        $(($type, self.$field, (option, encoding: $fieldty))),*