From bfdfb9da2762fdc71bc88c889c34d9e70ae27c36 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Tue, 21 May 2024 14:28:56 -0500 Subject: [PATCH] Implement Readable for Bolt12Invoice A future InvoiceReceived event will include a Bolt12Invoice. Since Event implements Readable, so must Bolt12Invoice. --- lightning/src/offers/invoice.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 5482e6f83..0d5d2caaa 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -124,7 +124,7 @@ use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError, ParsedMessage} use crate::offers::payer::{PAYER_METADATA_TYPE, PayerTlvStream, PayerTlvStreamRef}; use crate::offers::refund::{IV_BYTES as REFUND_IV_BYTES, Refund, RefundContents}; use crate::offers::signer; -use crate::util::ser::{HighZeroBytesDroppedBigSize, Iterable, SeekReadable, WithoutLength, Writeable, Writer}; +use crate::util::ser::{HighZeroBytesDroppedBigSize, Iterable, Readable, SeekReadable, WithoutLength, Writeable, Writer}; use crate::util::string::PrintableString; #[allow(unused_imports)] @@ -1205,6 +1205,13 @@ impl Writeable 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) + } +} + impl Writeable for InvoiceContents { fn write(&self, writer: &mut W) -> Result<(), io::Error> { self.as_tlv_stream().write(writer) -- 2.39.5