Skip to content

Commit a773001

Browse files
committed
Add optional lifetime to tlv_stream macro
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.
1 parent bbdd873 commit a773001

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

lightning/src/offers/invoice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ impl TryFrom<Vec<u8>> for Bolt12Invoice {
12371237
/// Valid type range for invoice TLV records.
12381238
pub(super) const INVOICE_TYPES: core::ops::Range<u64> = 160..240;
12391239

1240-
tlv_stream!(InvoiceTlvStream, InvoiceTlvStreamRef, INVOICE_TYPES, {
1240+
tlv_stream!(InvoiceTlvStream, InvoiceTlvStreamRef<'a>, INVOICE_TYPES, {
12411241
(160, paths: (Vec<BlindedPath>, WithoutLength, Iterable<'a, BlindedPathIter<'a>, BlindedPath>)),
12421242
(162, blindedpay: (Vec<BlindedPayInfo>, WithoutLength, Iterable<'a, BlindedPayInfoIter<'a>, BlindedPayInfo>)),
12431243
(164, created_at: (u64, HighZeroBytesDroppedBigSize)),

lightning/src/offers/invoice_request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ pub(super) const INVOICE_REQUEST_PAYER_ID_TYPE: u64 = 88;
10611061

10621062
// This TLV stream is used for both InvoiceRequest and Refund, but not all TLV records are valid for
10631063
// InvoiceRequest as noted below.
1064-
tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef, INVOICE_REQUEST_TYPES, {
1064+
tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef<'a>, INVOICE_REQUEST_TYPES, {
10651065
(80, chain: ChainHash),
10661066
(82, amount: (u64, HighZeroBytesDroppedBigSize)),
10671067
(84, features: (InvoiceRequestFeatures, WithoutLength)),

lightning/src/offers/merkle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::prelude::*;
2121
/// Valid type range for signature TLV records.
2222
const SIGNATURE_TYPES: core::ops::RangeInclusive<u64> = 240..=1000;
2323

24-
tlv_stream!(SignatureTlvStream, SignatureTlvStreamRef, SIGNATURE_TYPES, {
24+
tlv_stream!(SignatureTlvStream, SignatureTlvStreamRef<'a>, SIGNATURE_TYPES, {
2525
(240, signature: Signature),
2626
});
2727

lightning/src/offers/offer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ const OFFER_METADATA_TYPE: u64 = 4;
10771077
/// TLV record type for [`Offer::issuer_signing_pubkey`].
10781078
const OFFER_ISSUER_ID_TYPE: u64 = 22;
10791079

1080-
tlv_stream!(OfferTlvStream, OfferTlvStreamRef, OFFER_TYPES, {
1080+
tlv_stream!(OfferTlvStream, OfferTlvStreamRef<'a>, OFFER_TYPES, {
10811081
(2, chains: (Vec<ChainHash>, WithoutLength)),
10821082
(OFFER_METADATA_TYPE, metadata: (Vec<u8>, WithoutLength)),
10831083
(6, currency: CurrencyCode),

lightning/src/offers/payer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ pub(super) struct PayerContents(pub Metadata);
3030
/// [`Refund::payer_metadata`]: crate::offers::refund::Refund::payer_metadata
3131
pub(super) const PAYER_METADATA_TYPE: u64 = 0;
3232

33-
tlv_stream!(PayerTlvStream, PayerTlvStreamRef, 0..1, {
33+
tlv_stream!(PayerTlvStream, PayerTlvStreamRef<'a>, 0..1, {
3434
(PAYER_METADATA_TYPE, metadata: (Vec<u8>, WithoutLength)),
3535
});

lightning/src/util/ser_macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ macro_rules! impl_writeable_tlv_based {
952952
/// [`Readable`]: crate::util::ser::Readable
953953
/// [`Writeable`]: crate::util::ser::Writeable
954954
macro_rules! tlv_stream {
955-
($name:ident, $nameref:ident, $range:expr, {
955+
($name:ident, $nameref:ident $(<$lifetime:lifetime>)?, $range:expr, {
956956
$(($type:expr, $field:ident : $fieldty:tt)),* $(,)*
957957
}) => {
958958
#[derive(Debug)]
@@ -964,13 +964,13 @@ macro_rules! tlv_stream {
964964

965965
#[cfg_attr(test, derive(PartialEq))]
966966
#[derive(Debug)]
967-
pub(crate) struct $nameref<'a> {
967+
pub(crate) struct $nameref<$($lifetime)*> {
968968
$(
969969
pub(super) $field: Option<tlv_record_ref_type!($fieldty)>,
970970
)*
971971
}
972972

973-
impl<'a> $crate::util::ser::Writeable for $nameref<'a> {
973+
impl<$($lifetime)*> $crate::util::ser::Writeable for $nameref<$($lifetime)*> {
974974
fn write<W: $crate::util::ser::Writer>(&self, writer: &mut W) -> Result<(), $crate::io::Error> {
975975
encode_tlv_stream!(writer, {
976976
$(($type, self.$field, (option, encoding: $fieldty))),*

0 commit comments

Comments
 (0)