mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-13 14:52:21 +01:00
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.
This commit is contained in:
parent
bbdd8738a8
commit
a77300129c
6 changed files with 8 additions and 8 deletions
|
@ -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)),
|
||||
|
|
|
@ -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)),
|
||||
|
|
|
@ -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),
|
||||
});
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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)),
|
||||
});
|
||||
|
|
|
@ -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))),*
|
||||
|
|
Loading…
Add table
Reference in a new issue