Skip to content

Commit 3ce4a12

Browse files
committed
WIP: Iterators in InvoiceTlvStreamRef
1 parent 6550759 commit 3ce4a12

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

lightning/src/offers/invoice.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::offers::parse::{ParseError, ParsedMessage, SemanticError};
3030
use crate::offers::payer::{PayerTlvStream, PayerTlvStreamRef};
3131
use crate::offers::refund::{Refund, RefundContents};
3232
use crate::onion_message::BlindedPath;
33-
use crate::util::ser::{HighZeroBytesDroppedBigSize, SeekReadable, WithoutLength, Writeable, Writer};
33+
use crate::util::ser::{HighZeroBytesDroppedBigSize, Iterable, SeekReadable, WithoutLength, Writeable, Writer};
3434

3535
use crate::prelude::*;
3636

@@ -432,7 +432,7 @@ impl InvoiceFields {
432432
};
433433

434434
InvoiceTlvStreamRef {
435-
paths: Some(&self.paths),
435+
paths: Some(Iterable(self.paths.iter())),
436436
blindedpay: Some(&self.payinfo),
437437
created_at: Some(self.created_at.as_secs()),
438438
relative_expiry: self.relative_expiry.map(|duration| duration.as_secs() as u32),
@@ -461,7 +461,7 @@ impl TryFrom<Vec<u8>> for Invoice {
461461
}
462462

463463
tlv_stream!(InvoiceTlvStream, InvoiceTlvStreamRef, 160..240, {
464-
(160, paths: (Vec<BlindedPath>, WithoutLength)),
464+
(160, paths: (Vec<BlindedPath>, Iterable<'a, core::slice::Iter<'a, BlindedPath>, BlindedPath>)),
465465
(162, blindedpay: (Vec<BlindedPayInfo>, WithoutLength)),
466466
(164, created_at: (u64, HighZeroBytesDroppedBigSize)),
467467
(166, relative_expiry: (u32, HighZeroBytesDroppedBigSize)),

lightning/src/util/ser.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,18 @@ impl<'a, T: Writeable> Writeable for WithoutLength<&'a Vec<T>> {
558558
}
559559
}
560560

561+
pub(crate) struct Iterable<'a, I: Iterator<Item = &'a T> + Clone, T>(pub I);
562+
563+
impl<'a, I: Iterator<Item = &'a T> + Clone, T: Writeable> Writeable for Iterable<'a, I, T> {
564+
#[inline]
565+
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
566+
for ref v in self.0.clone() {
567+
v.write(writer)?;
568+
}
569+
Ok(())
570+
}
571+
}
572+
561573
impl<T: MaybeReadable> Readable for WithoutLength<Vec<T>> {
562574
#[inline]
563575
fn read<R: Read>(mut reader: &mut R) -> Result<Self, DecodeError> {

lightning/src/util/ser_macros.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ macro_rules! tlv_record_ref_type {
559559
((u16, $wrapper: ident)) => { u16 };
560560
((u32, $wrapper: ident)) => { u32 };
561561
((u64, $wrapper: ident)) => { u64 };
562+
(($type:ty, Iterable<$lifetime:lifetime, $itertype:ty, $valuetype:ty>)) => { Iterable<$lifetime, $itertype, $valuetype> };
562563
(($type:ty, $wrapper:ident)) => { &'a $type };
563564
($type:ty) => { &'a $type };
564565
}

0 commit comments

Comments
 (0)