From 0c157442b452325dd6997b2de78e24d60c541dd2 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 25 Jun 2024 14:26:25 +0000 Subject: [PATCH] Implement `Readable` for `Bolt12Invoice` In c13b6d814bfb5dd95f9e40f8ff07dd45c47a387e and fc14495ac6a9dbe7dc9a6bd43c4395b599592db1 we implemented `Readable` for `Refund` and `Offer`s, but didn't do so for `Bolt12Invoice`. Because `Bolt12Invoice`s are not serializable to strings, we generally expect users to read and write them as byte arrays, and currently expose this via `TryFrom>`. This is fine, but there's no reason to not implement `Readable` as well, and it saves having to implement `TryFrom` in bindings. --- lightning/src/offers/invoice.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 3f96e703b..c8d94e26e 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -1160,6 +1160,13 @@ impl TryFrom> for Bolt12Invoice { } } +impl Readable for Bolt12Invoice { + fn read(reader: &mut R) -> Result { + let bytes: WithoutLength> = Readable::read(reader)?; + Self::try_from(bytes.0).map_err(|_| DecodeError::InvalidValue) + } +} + tlv_stream!(InvoiceTlvStream, InvoiceTlvStreamRef, 160..240, { (160, paths: (Vec, WithoutLength, Iterable<'a, BlindedPathIter<'a>, BlindedPath>)), (162, blindedpay: (Vec, WithoutLength, Iterable<'a, BlindedPayInfoIter<'a>, BlindedPayInfo>)), -- 2.39.5