From: Matt Corallo Date: Tue, 25 Jun 2024 14:26:25 +0000 (+0000) Subject: Implement `Readable` for `Bolt12Invoice` X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=refs%2Fheads%2F2024-06-readable-invoices;p=rust-lightning 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. --- 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>)),